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.