Newbie "Hello World" Tutorial

chris00
09-18-2002, 06:20 PM
The "Hello World" tutorial

HI, I made this tutorial mainly for newbies explaining some of the basic VB things
and hope this tutorial will get you started making your own programs.

This tutorial uses a Form (Form1), Label (LblHello), and a Timer(Timer1)

First we have to make the Form, the form is what you see on the screen

First you have to pick "Standard EXE" in the NEW Project Menu.

Now lets get started:


Click on the Caption Label (Image 1A) button in the menu.
Put it on the Form by clicking and dragging the mouse and sizing it
Making sure the Label is selected look in the Properties Menu (Image 1B)
Change the (Name) to LblHello ,"Lbl" for Label and "Hello" since this is a "Hello World" program
Now lets change the .Caption from "Label1" to "" (blank)
Click in the .Font field and change it to whatever you want.


Click on the Timer button in the menu, looks like a clock (Image 2A)
Put it on the Form by clicking and dragging the mouse (size doesn't matter)
After Selecting the Timer goto to the Properties Menu (Image 1B)
Change the .Interval to 250


The Variable declaration (goes a the top of the code)

A Variable is a Letter(s) (or a Letter and a Number) that represents a number or piece of text (a string)
A String contains text
A Integer can hold numbers from -32768 to 32767


Option Explicit ' makes sure all variables are declared
Dim strWrlString As String ' the String that contains "Hello World"
Dim intA As Integer
Dim intB As Integer
Dim strWrlLetter(11) As String 'the separated letters of WrlString into the srlWrlLetter array
' an array is a collection of variables with the same name that are referenced by an index.
' (11) mean there can be 12 values held in the array (0-11)

The Form Load is the Sub that fires of when the application is first run.
Double-Click the Form to get to this sub
In this Sub we split WrlString up

Private Sub Form_Load()
strWrlString = "Hello World"' Giving strWrlString the value of Hello World
For intA = 1 To Len(strWrlString)' intA = Length of strWrlString (which in this case equals 11)
strWrlLetter(intA) = Left$(strWrlString, intA)' Puts part of strWrlSting in the strWrlLetter array
Next intA sends it back to "For a = ...."
End Sub

The Timer Sub fires at a set interval (in this case 250), Double-Click the Timer (Clock) and you
will see the Timer1_Timer Sub
In this sub we change the labels, making it look like one letter is added at a time.
Private Sub Timer1_Timer()
LblHello.Caption = strWrlLetter(intB)' Caption = first b letters of the strWrlString
Form1.Caption = strWrlLetter(intB)' Caption = first b letters of the strWrlString
intB = intB + 1' adds 1 to intB
If intB = Len(strWrlString) + 1 Then ' checks to see if all of the letters are spelled out
intB = 0' clears the loop so it can restart
End If ' Ends the if statement
LblHello.Refresh' Refreshes the Label
End Sub

I hope this tutorial has been helpful to you, and good luck.

Chris00

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum