Programming in VB.Net

This site include tutorials of VB.Net programming

Tuesday, April 13, 2010

Input Field validation (Accept only numbers)

  • In this exercise you will learn one of the methods of validating inputs at field level















  • Add a new form to project. Name it as frmTextboxvalid.
  • Place a Label and  a TextBox. Name the textbox as txtNumbers.
  • Click at "View" and then at "Code" to enter the code window.
  • Click at the combo box on the left side and select txtNumbers.
  • Click at the combo box on the right side and select KeyPress event.
  • Then write the following code.
                    Private Sub txtNumbers_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNumbers.KeyPress


                          If Asc(e.KeyChar) <> 8 Then
                                   If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
                                          e.Handled = True
                                  End If
                          End If


                   End Sub

  • Run the Application.

Sunday, March 14, 2010

Sending EMAIL through VB.Net

  • Now you will learn how to send email using a VB.net program. This can be done in different ways.
  • First two code segments shows how a mail can be Configured and sent using the default mail server using VB code.
  • This program sends emails to a recipient address(s) that you specify. You have to give the mail server (SMTP Server) name or the IP address correctly.
  • If you are planned to send the mail using the button1_click() or button2_click() methods, first make a reference to the System.web.dll file (because the example uses classes in the system.web.mail namespace). project->Add reference...
  • Third code segment [button3_click()] starts the MS OUTLOOK and then user can use that application to send and receive emails.



  • Codings...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim email As New System.Web.Mail.MailMessage
email.To = "ABSReceiver@abc.com"
email.From = "ABcSender@abc.com"
email.Body = "Hi!!!!!! "
email.Subject = "Testing"
email.BodyFormat = Web.Mail.MailFormat.Text
System.Web.Mail.SmtpMail.SmtpServer = "1.1.1.1" 'SMTP Server IP Address
System.Web.Mail.SmtpMail.Send(email)
End Sub


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
System.Web.Mail.SmtpMail.SmtpServer = "1.1.1.1" 'SMTP Server IP Address
System.Web.Mail.SmtpMail.Send("ABSReceiver@abc.com", "ABcSender@abc.com", "Testing", "Hi!!!!!! ")
End Sub


Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim a As Object
a = Shell("c:\Program Files\Outlook Express\msimn.exe", AppWinStyle.NormalFocus)
End Sub

Sunday, March 7, 2010

Use of font dialog box and colour dialog box

  • Create new project and add a form.
  • Drag and Drop two command buttons and a Label to the form.
  • Then drag & drop a FontDialog and a ColorDialog to the form.
  • change the Name property of the buttons & Label as cmdFont, cmdColor and lblShow.
  • Change the Text property of the buttons & Label as Change Font, Change Color and Show

  • Double click on the change font button. write the following two lines.
FontDialog1.ShowDialog()
lblShow.Font = FontDialog1.Font

  • Double click on the change Color button. write the following two lines.
ColorDialog1.ShowDialog()
lblShow.ForeColor = ColorDialog1.Color

  • Run the Application by clicking at > or by pressing F5. Click on button and change fonts and colors.

Tuesday, November 24, 2009

Our first Project " Hello World ! "


  • First Create New Project........

  • Then drag and drop a button from tool box

  • Then click button and change the text property ("Button1") in Property window to Hello.....

  • Now double click on then command window appear



  • Then add following code.....

    MsgBox("Hello World !")

  • Then come to form design and click Run Button


  • Finaly Click Hello button and see result....

Sunday, November 22, 2009

Let's start VB.Net

  • How to open VB.Net
Go to Start menu -> All Progarms -> Microsoft Visual Studio 2005 and select Microsoft Visual Studio 2005 like this..............
vb.net

  • Then you can see following window
Learn VB Then click create project on left side to create new project. If you want open your existing report choose open project..........
  • Click create project

Then you get following Window............


Open vb.netChoose language as Visual Basic and Windows Application and after that give a name for project click OK.....


  • Then You have opened a new project

Now we have to Design and add code to our Project............


Tuesday, September 15, 2009