Search VB 2010

Thursday, October 18, 2012

Visual Basic 2010 - Button Sound / Music Play

Visual Basic 2010 - Button Sound

Visual Basic 2010 - Play sound on buttons
Visual Basic 2010 - Play sound on buttons

The code is simply goes like this

You can copy and paste in your (Click_Event) or whatever it is you wish (MouseClick - MouseHover - MouseLeave) :


  1. Dim MySound As New System.Media.SoundPlayer()  
  2.  
  3. MySound.SoundLocation = "path to the .Wav file"
  4. MySound.Load()
  5. MySound.Play()
  6. ' OR you can use this :
  7. Sub PlaySystemSound()
  8. My.Computer.Audio.PlaySystemSound(
    System.Media.SystemSounds.Asterisk)
     
  9. End Sub

Background playing 

It lets the application execute other code while the sound plays. The My.Computer.Audio.Play method allows the application to play only one background sound at a time; when the application plays a new background sound, it stops playing the previous background sound. You can also play a sound and wait for it to complete.

For Visual Basic 2010 and in general, when an application plays a looping sound, it should eventually stop the sound. For more information, see How to: Stop Playing Sounds in the Background in Visual Basic 2010.

Example

The My.Computer.Audio.Play method plays a sound. When AudioPlayMode.WaitToComplete is specified, My.Computer.Audio.Play waits until the sound completes before calling code continues.

Check that the file name references a .wav sound file on your system.
  1. Sub PlayBackgroundSoundFile()

    My.Computer.Audio.Play("C:\Waterfall.wav",
    AudioPlayMode.WaitToComplete)

    End Sub
The My.Computer.Audio.Play method plays a sound. When AudioPlayMode.WaitToComplete is specified, My.Computer.Audio.Play waits until the sound completes before calling code continues.
Check that the application resources include a .wav sound file named Waterfall.
  1. Sub PlayBackgroundSoundResource()

    My.Computer.Audio.Play(My.Resources.Waterfall,
    AudioPlayMode.WaitToComplete)

    End Sub


Here are some online Visual Basic lessons and courses :

Thursday, October 11, 2012

Visual Basic Online Course ProgressBar

Visual Basic 2010 ProgressBar Control 

VB2010 Progress bar - Visual Basic Online Course

 Using the ProgressBar control Example :

- Create New Windows Project
- Button1
- ProgressBar1
- Logic : We will generate 4 MessageBoxes by clicking the Button1 Control and everytime a messagebox shows up, a ProgressBar step will be taken.

Progress Bar Class : In .Net Framework4.0

A ProgressBar control consists of a window that is filled, by default from left to right, as an operation progresses. The control has a range and a current position.
ProgressBar overrides the metadata of the Maximum property and sets its default to 100. ProgressBar overrides the metadata of the Focusable property and sets its default to false. For more information, see Dependency Properties Overview.

Customizing the ProgressBar Control

To apply the same property settings to multiple ProgressBar controls, use the Style property. You can modify the default ControlTemplate to give the control a unique appearance. For more information about creating a ControlTemplate, see Customizing the Appearance of an Existing Control by Creating a ControlTemplate. To see the parts and states that are specific to the ProgressBar, see ProgressBar Styles and Templates.
Dependency properties for this control might be set by the control’s default style. If a property is set by a default style, the property might change from its default value when the control appears in the application. The default style is determined by which desktop theme is used when the application is running. For more information, see Default WPF Themes.

NoteNote
Setting a visual property will only have an effect if that property is both present in ProgressBar control's default template and is set by using a TemplateBinding. You can find a list of visual properties in the "Changing the Visual Structure of a Control" section in Customizing the Appearance of an Existing Control by Creating a Control Template.

How to call a Progress Bar from a Module in VB 2010

In addition to our example about Progress Bar, what if we wanted to code the progress bar to call it from another level [Module Level] !

Create Visual Basic 2010 Windows Form Application
Place a Progressbar (Progressbar1) control on the Form (Form1
Add new Module (Module1)

Code :

Now, run your application and click on any part of the Form1, you will notice that the ProgressBar is working.

Monday, August 13, 2012

Receive Emails in VB 2010

Day : Aug,12,2012
Send & Receive E-mails from E-mail server using VB .net
Hello,
I was always thinking if i could send and receive e-mails using .Net technology, i was shocked to know that .Net 4 has no POP3 class so one could receive e-mails just like in Microsoft Outlook, regardless that Outlook uses POP3, IMAP and SMTP to both send and receive e-mails from e-mail servers.
I was able to finish the send E-mail part successfully, though i've not finished the attachment and the Html parts, but the receiving e-mails part still out there somewhere i did not do it, though i managed to connect to pop3 servers and receive the +OK response successfully.

I'm using an old laptop (WinXpSp3 Home Edition) with VS2010 along with all the .Net kits installed. I've search the internet for pop3-vb.net resources and i could not land on something that works 100% with the receive E-mails part although i ran into some C# codes that helped me to take the first step which is the Response from the server (Gmail.com).
Another thing to tell you, is Gmail.com have 2-Step Verification method that if enabled, enables you to protect you Google account and provide you with a password to work with applications like this one (E-mail Client). If you dealt with Outlook before you should already knew that; you use your Application password to login to your Gmail.com account associated with your Google account, here is a link that explains all of the 2-Step Verification method, if you don't have a Gmail.com or not working through 2-Step Verification method then you must ignore this.
Also you have to know all about incoming and outgoing Ports, Server and of course User Name and Password, and remember to always use the full e-mail address (your_username@emailserver.com) not just your username, here is some info about E-mail server settings:
Hotmail Settings
Incoming Server(pop3.live.com) port(995) Secure Connection (SSL) is a must
Outgoing Server(smtp.live.com) port(587) Secure Connection (TLS) is a must
Note that Hotmail.com have both free and paid accounts, but both supports E-mail clients. So you should go inside your E-mail settings to enable POP3 and forwarding option to be able to work with E-mail clients.
Yahoo Settings
Incoming Server(pop.mail.yahoo.com) port(995) Secure Connection (SSL) is not a must if you're using the free mail.
Outgoing Server(smtp.mail.yahoo.com) port(465) Secure Connection (TLS) is a must
Note that Yahoo.com have both free and paid accounts, but both supports E-mail clients. So you should go inside your E-mail settings to enable POP3 and forwarding option to be able to work with E-mail clients.
Gmail Settings
Incoming Server(pop.gmail.com) port(995) Secure Connection (SSL) is a must
Outgoing Server(smtp.gmail.com) port(587) Secure Connection (TLS) is a must
Finally, i would really like to suggest using Outlook as a practise first, try to establish a connection with your mail server and send some e-mail and receive some, just to make sure your mail server is sat up correctly.

The Send E-mail Part

Imports System.Net.Mail 'The Mail Class we use to send e-mails
Public Class SendFrm 'The form name : SendFrm 
Dim SmtpSvr As New Net.Mail.SmtpClient()
Dim E_mail As New Net.Mail.MailMessage()
Dim UsrNm, Pwd, Srve As String
Dim Int_port As Integer
Private Sub SendFrm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
UsrNm = ("Your_UserName@gmail.com") 'I'm using Gmail.com 
Pwd = ("Your_Password") 'My 2-Step Verification Password (Link) coz i enable this method, if not then your regular Password. 
Srve = ("pop.gmail.com")
Intport = 587
End Sub
Private Sub Label11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label11.Click
'I'm using Label11 to send : Name (Send) 
SmtpSvr.UseDefaultCredentials = False
SmtpSvr.Credentials = New Net.NetworkCredential(UsrNmt.ToString, Pwd.ToString)
SmtpSvr.Port = Intport
SmtpSvr.Host = Srve.ToString
E_mail = New MailMessage()
E_mail.From = New MailAddress(UsrNm.ToString, "Whatever_You_Desire", System.Text.Encoding.UTF8)
E_mail.IsBodyHtml = False 'Still Working on it. 
E_mail.Body = ("Hello, This is my first E-mail though My Client")
SmtpSvr.EnableSsl = True
E_mail.To.Add(TxtFrnd.Text.ToString) 'TextBox Name : TxtFrnd 
E_mail.Subject = (TxtSub.Text.ToString) 'TextBox Name : TxtSubCursor = Cursors.WaitCursor
SmtpSvr.Send(E_mail)
MsgBox("mail sent")
Cursor = Cursors.Default
End Sub
So easy, huh ?!
The Receive E-mail Part
This is another VB Project.
Imports System.IO
Imports System.Net.Sockets
Imports System.Text
Imports System.Net.Security
Class Form1
Dim Read_Stream As StreamReader
Dim POP3 As New TcpClient
Dim PopHost As String = "pop.gmail.com"
Dim UserName As String = "MyGmail@gmail.com"
Dim Password As String = "My2stepVerficationPass"
Dim Server_Response As String
Dim response As StreamWriter

Private Sub CmdDownload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdDownload.Click

Cursor = Cursors.WaitCursor
POP3.Connect(PopHost, 995)
TextBox1.AppendText(Cons("STAT ")) 'TextBox Name : TextBox1 to receive response from server using (STAT) command,
'Note : In the bottom there is a table with all POP commands and responses.I'm using Cons Function to send commands to POP server.
Cursor = Cursors.Default
End Sub

Function Cons(ByVal server_Command As String)
Dim m_buffer() As Byte = System.Text.Encoding.ASCII.GetBytes(server_Command)
Dim m_sslStream = New SslStream(POP3.GetStream(), False)
m_sslStream.AuthenticateAsClient(PopHost)
Dim bytes As Int64 = m_sslStream.Read(m_buffer, 0, m_buffer.Length)
Return (Encoding.ASCII.GetString(m_buffer, 0, bytes))
End Function

Of course this is not it, i'm still working on errors i receive .... keep up!

Update (1) Aug,15,2012 - I was able to successfully get response from Gmail (pop.gmail.com) server and pass my Username and password.
POP Commands
CommandResponsesExamples
USER name+OK name is welcome here
-ERR never heard of name
USER David
+OK Please enter a password
PASS string+OK maildrop locked and ready
-ERR invalid password
-ERR unable to lock maildrop
PASS test
+OK valid logon
QUIT+OK+OK Server closing connection
STAT+OK nn mmSTAT
+OK 2 320
LIST [msg]+OK scan listing follows
-ERR no such message
LIST
+OK 2 messages (320 octets)
1 120
2 200
...

LIST 2

+OK 2 200
RETR msg+OK message follows
-ERR no such message
RETR 1
+OK 120 octets
< the POP3 server sends the entire message here >
DELE msg+OK message deleted
-ERR no such message
DELE 2
+OK message deleted
NOOP+OK no transactionNOOP
+OK
LAST+OK nnLAST
+OK 2
RSET+OKRSET
+OK maildrop has 2 messages (320 octets)
Additional Commands
TOP msg nn+OK top of msg
-ERR
TOP 1 10
+OK
< first 10 lines of the header >
RPOP user+OK
-ERR
RPOP david
+OK enter password


Update (1) Aug,15,2012 - I was able to successfully get response from Gmail (pop.gmail.com) server and pass my Username and password.
Update (2) Aug,17,2012 - Retrieving the number of E-mails from POP3 Mail Server .
Update (3) Aug,18,2012 - Get list of E-mails and download them and read them to your application.

Here are some online Visual Basic lessons and courses :

Sunday, July 29, 2012

Visual Basic 2010 Error the application failed to initialize properly 0xc000007b

Visual Basic 2010 Computer Virus

Visual Basic Courses Online

Error :

he application failed to initialize properly 0xc000007b

Cause :

Virus W32.Sality

Symptoms :

When you attempt to start an application (.exe) it generates an error message the application failed to initialize properly 0xc000007b

 Solution :

Any antivirus will do the job.

In my case :

I had VS2010 Professional Edition installed on my X86 machine that runs WinXpSp3 Home Edition along with many other applications (i.e. Office 2003\2007, VS6 SP6) and of course .Net framework 4.0.
 
Every time i develop an application it runs fine until i restart my computer or shut it down and then re-open it again, i receive this annoying error message when i attempt to run the .exe file i just built with VS 2010 "the application failed to initialize properly 0xc000007b"
 
I formatted my C:\ drive and re-installed windows along with VS 2010 and all other software, but that did not solve the problem, i did not realize that my PC is infected with Virus [Win32.Sality] until i used a flash USB memory that acting a little bit weird for instance, it was opening in new window and that my computer is really slowing down so i got a KAV rescue CD and scanned my whole PC and found a lot of WIN32.Sality Virus there and removed it along with a lot of applications, then i re-installed Windows XPSP3 Home Edition again and VS 2010 Pro. and all other applications, and the problem went away for good.

I really worked around the problem for a very long time and it did not work out until i used this method i mentioned, so i thought it would be fine to share with everyone.

Thanx for reading, i hope that was useful .

Wednesday, May 23, 2012

Visual Basic 2010 Working With DataBase Full Project Example

VB 2010 Book
Working With Database Full Project Example

Download VB 2010 Book to work with MS-Access
Download VB 2010 Book to work with MS-Access

Book Link via MediaFire.com

The book is 5 chapters and is explained here, it contains source code of a project example on how to work with Microsoft Access Database from Visual Basic 2010.

    In the book; the photos show how to start your project, how to select your database and how to display it. Here, we'll discuss each photo and explain each code block.

Chapter#1 - Released
VB .Net 2010 Working With DataBase Full Project Example

    Photo (1) : Shows the folder that contains the project, the (My-First-Con.vbproj) is the icon you need to click to open the project.

    Photo (2) : From menu (Data) choose (Add New Data Source), a popup dialog-box will show titled (Choose a Data Source Type) and you select (Database) as long as we are connecting to one, then click next.

    Photo (3) : A popup dialog-box appears titled (Data Source Configuration) and you select (DataSet). The DataSet is the connection type we are trying to establish here, click next. Also in the end you will notice a file (DataSet) was created, let's not rush, ok?!

    Photo (4) : Another dialog-box shows up titles (Choose Your Data Connection), here we'll choose (New Connection) and another dialog-box will show up to choose the connection from it, this new dialog-box titled (Add Connection) has (Change) button and (Browse) button, we will click on (Change) to choose the data source we wish to work with, as for this lesson we're working on (Access) so we will choose access from the next popup window that will show when we click on (Change) which called (Microsoft Access Database File), the other databases are for the other types of databases, now choose (Access) and there will be another button below called (Data Provider) which provides us with the technology we wish to work with, as for here we will work with (.Net Framework Data Provider for Ole DB), then we click next.

Continue reading ....

Chapter#2 - Released
VB .Net 2010 Working With DataBase Full Project Example
Chapter#3 - Released
 VB .Net 2010 Working With DataBase Full Project Example
  •         Adding\Inserting photos into database table
  •         Retrieving\displaying photo from database table
  •         Displaying photos into DataGridView Control
  •         Using PictureBox Drag/Drop Method to display photo
- The example remains (My Phone Book) so we will just resume our previous work.

Here are some online Visual Basic lessons and courses :

Monday, May 14, 2012

VB2010 -Connect your first database

Hello,

This is a new book about using MS-Visual Basic .Net 2010 to connect to database and build complete applications based on database.
The book title’s (“Microsoft Visual Studio 2010 Data-Base Applications”) it comes in PDF format, with many Source codes and photo shots of – How To Do …… ?

Visual Basic Courses - Share