Sample Visual Basic .Net Programs

Instructions
00001000_labelsTextboxesButtons
0000100_ages
00002000_hello
00003000_helloWorldAgain
00004000_changePropertiesAtRuntime
00004500_casting-unfinished
00005000_perimeterAndArea
00007000_numberAttributes
00008000_monthDays
00009000_ages
00009005_countingClicks
00009010_clickCount-times-if
00010000_ages-nestedIf
00010100_ifElseifElse
00010105_ticTacToe
00010200_nestedIfElseifProblem
00011000_addUpDigitsInNumber
00012000_manyBoxes
00013000_factorial-ByVal
00013500_factorial-ByRef
00014000_factorial-ByValByRef
00015000_factorial-function
00100000_maxMinEtc
00101000_drawing
00102000_drawing-arrayOfArrays
00103000_points
00104000_canvasPointLine
01000000_asciiChart

Instructions

The following are sample VB.Net programs. Each program is included with the full folder for the project in a single zip file. To run the programs or edit them you must do the following:

  1. Download the zip file by clicking on the filename
  2. You MUST unzip the file in order to run the program or modify the code
    (If you don't unzip the file then you will be able to open the .sln file - see next step - but it will not work correctly).
  3. To start editing the program in Visual Basic, double click on the file with the ".sln" extension.
    NOTE: when you double click on the .sln file you may get a dialog box similar to the following. Since windows doesn't know who created the program Windows assumes that it might have been a hacker and the program might contain a virus. This is NOT an issue for these programs so Click on the OK button to continue.
  4. Once you are in Visual Basic you can use the "Solution Explorer" to view the individual files in the project. If you don't see the Solution Explorer, choose the following menu choice: "view | Solution Explorer"
  5. Most programs have a single Form1.vb file. Double click on the Form1.vb file in the Solution Explorer window to see the main form for the application.
 TopicsFilesDescription / Screen Shots
100001000_labelsTextboxesButtons
  
20000100_ages
  
300002000_hello
  • MessageBox.Show
  • setting properties of a Button (e.g. color)

Program displays a message when user clicks a button.


400003000_helloWorldAgain
  
500004000_changePropertiesAtRuntime
  
600004500_casting-unfinished
  
700005000_perimeterAndArea
  
800007000_numberAttributes
  • two ifs (not nested, without Else)
  • Mod

Asks user for a number. Message boxes describe if the number is positive, negative or even.


900008000_monthDays
  
1000009000_ages
  
1100009005_countingClicks
  • global variables
  • concatenation in a MsgBox
  • addition expression inside a MsgBox

Program has 4 buttons:

  • Button1 - shows how many times user clicked Button1
  • Button2 - shows how many times user clicked Button2
  • "Total Clicks" - shows how many times user clicked both Button1 and Button2. Also shows a total number of clicks.
  • "Reset Counts" - Sets all the counts back to zero

1200009010_clickCount-times-if
  • val
  • global variables
  • if

Program displays a message such as "0 times 2 is 0" When user clicks a button the display is updated for the next number in the two times table (e.g. "1 times 2 is 2") If the user clicks more than 3 times then after every click a message box appears that says "You sure click a lot ..."


1300010000_ages-nestedIf
  
1400010100_ifElseifElse
  
1500010105_ticTacToe
  
1600010200_nestedIfElseifProblem
  • if
  • if with else
  • if with elseif
  • if with elseif and else
  • nested if

Example program to demonstrate how nested If/Elseif/Else statements work.

User enters a number and program displays different message boxes based on the value of the number.


1700011000_addUpDigitsInNumber
  
1800012000_manyBoxes
  
1900013000_factorial-ByVal
  
2000013500_factorial-ByRef
  
2100014000_factorial-ByValByRef
  
2200015000_factorial-function
  
2300100000_maxMinEtc
  
2400101000_drawing
  
2500102000_drawing-arrayOfArrays
  
2600103000_points
  
2700104000_canvasPointLine
  
2801000000_asciiChart