Visual Basic 2005


Add to MY Favorites...

Back to Vicky's Home Page Teaching Home Page Visual Basic 2005 Html For Kids

Common Code for Tools

Load an Image Into a Picture Box

Picturebox1.image = system.drawing.image.fromfile _ ("c:\folder\file.jpg")

Note the underscore.  The underscore is a continuation character.  It says this is not the end of the statement, and that it will continue on the next line.

Prompt for Input

InputName=InputBox("Enter your name please")

Check For a Checked Checkbox

 

Values for checkbox states:

1 = checked

0 = not checked

How you can evaluate the state:

If checkbox1.checkstate = 1 Then

Add Items to a List Box

ListBox1.Items.Add("Cash")

ListBox1.Items.Add("Check")

ListBox1.Items.Add("Credit")

Add Items to a Combo Box

ComboBox1.Items.Add("Cash")

ComboBox1.Items.Add("Check")

ComboBox1.Items.Add("Credit")

Add radio buttons

Use the GroupBox control to encapsulate a set of radio buttons.

Evaluate a list box selection and act on it

         Select Case ListBox1.SelectedIndex

           Case 0

                Payment = "Cash"

           Case 1

                Payment = "Check"

           Case 2

                Payment = "Credit"

        End Select

 

Evaluate a combobox selection and act on it

         Select Case ComboBox1.SelectedIndex

           Case 0

                Payment = "Cash"

           Case 1

                Payment = "Check"

           Case 2

                Payment = "Credit"

        End Select

    

If Then Else

If CheckBox1.CheckState = 1 Then

    PictureBox2.Visible = True

Else

    'If there is no mark, hide the image

    PictureBox2.Visible = False

End If

Note the comment.  It is preceded by a single quote mark.  Use these to make notes in your code so you can understand it later.

Events

Statements to  run when a things happen

     Private Sub Form1_Load(ByVal sender As System.Object)

These statements define the event, in this case Form1 Load.  Statements about what to do when the event occurs will follow.

Typically list boxes are filled when the form loads.

 

Methods

Statements that can do something to a particular kind of object.

The Add method

Used to Add items to a list or combo box

ComboBox1.Items.Add("U.S. Dollars")

 

Process start

Use this to starts a browser or another application from the VB program.

Starts the browers with a url loaded

System.Diagnostics.Process.Start _ ("http://www.microsoft.com/learning/books/")

Starts Word with a document loaded

System.Diagnostics.Process.Start _ ("winword.exe”,c:\myletter.doc")

Loose Notes

Continuation character is the underscore - use this to continue a statement on the next line.

Single quote starts a comment 

 

 


 
Another page developed by
vicky@vickywoodard.com
Copyright © 2006 Vicky K. Woodard
All rights reserved
Last updated: 8/17/2006