This isnt really a tutorial more of a few VERY SIMPLE exercises which will help someone learn the basics of Visual Basic. I know that many people dont like Visual Basic and some say its childish but I feel that it helps to have an Idea as so much is written in VB these days.

I havnt ever written a tutorial befor so please dont flame me much (Im very sensitive)

I Apologise in advance for my bad english. I not the best of writters.

-----------------------------------------------------------------------------------------

EXERCISE 1

AIM: Create a simple program with a button which when pressed displays a message on the form and pop up an alert box.

1) Create a folder in the place you wish to save this new VB project, e.g c:\Push Me

2) Start VB6 and select standard exe

3) On the form draw a Command Button by selecting the option off the toolbar on the left hand side of the screen

4) On the form draw a Label by selecting the option off the toolbar on the left hand side of the screen

5) Now you have your form sorted you need to set properties in order for them to do what you want. To set properties select the item you wish to change and then in the bottom right hand corner there should be a window in which the properties are set out.

Set the following properties to your objects

Command Button:

Name = cmdPushMe
Caption = Push Me
FontSize = 14

Label:

Name = lblDisplay
Caption = (leave blank)

Form:

Name = frmFirst


6) Now you have your form and properties sorted you need to add the code for your project. To add coding for the button double click on it. A box should pop up in which you should insert the following code...

Sub cmdPushMe_Click()

lblDisplay.Caption = "ouch"

MsgBox "Not That Hard!"

End Sub

7) Now run your program by clicking the play button in the top toolbar (just like the play button on your VCR)

8) Go to File - Save Project As and save the project to the folder you created in step 1)

--------------------------------------------------------------------

Exercise 2 : Hello Project

Remember : Each New Project Should Be Saved In A New Folder

1) Create a new folder in which to save this project, e.g c:\Hello

2) On a new form, draw one label and three command buttons and set the following properties:



Command Button1:

Name = cmdDisplay
Caption = Display

CommandButton2:

Name = cmdClear
Caption = Clear
Enabled = False

Command Button3:

Name = cmdExit
Caption = Exit

Label:

Name = lblMessage
Caption = (leave Blank)
Font Size = 14

Form:

Name = frmGreetings
Caption = Greetings!


2) There are three events possible here:

- the cmdDisplay button is clicked
- the cmdClear button is clicked
- the cmdExit button is clicked

so you must attach code to each button.

When the Display button is clicked we want to:

Display 'Hello Pat' in the label, lblMessage
Make the clear button enabled (so user can click it)
Make the Display button disabled (so user cant click it)


so, attach this coding to the display button:

Sub cmdDisplay_Click()

lblMessage.Caption = "Hello Pat"
cmdClear.Enabled = True
cmdDisplay.Enabled = False

End Sub


3) Attach similar coding to the clear button, so that the following will happen when it is clicked:

Display nothing in the label, lblMessage
Make the Display button enabled (So user can click it)
Make the clear button disabled (So user cant click it)


Work this out for yourself :-P

HINT: code it between

Sub cmdClear_Click()

End Sub


4) Attach code to the exit button so that the program will end when this button is clicked:

Sub cmdExit_Click()

End

End Sub


5) Run your program and see what it does

6) Use save project as to save the project to the folder you created in step 1

------------------------------------------------------------------

EXERCISE 3 : Simple Maths Project

Create a project with an interface like the attached gif "ex3"

Add the necessary coding to add, subtract and multiply the numbers entered and then to display the result of the calculation in txtResult.

The clear button should clear txtNo1, txtNo2 and txtResult ready for the user to input two new numbers.

The Exit button should end the program ... duh!

Hints For Exercise 3


Labels have a caption property, but text boxes have a Text property

Some simple code attached to the add button could be:

[B]Sub cmdAdd.Click()

txtResult.Text = Val(txtNo1.Text) + Val(txtNo2.Text)

End Sub

Val is needed here because we are using numbers

Remember to do the same steps as in exercise 1 & 2:

- Create a new folder for this project
- Draw the interface
- Set the properties of each control on the interface
- Attach COde to each button onn the interface
- Test the program
- Save the project using save project as