Visual Basic 6 Tutorials
6 Replies / 1226 Views-
October 6th '05 #1HellbreatherGuest
Visual Basic 6 Tutorials
Hey Guys,
If any of you have Visual Basic 6 or VBA (Visual Basic for Applications) and want to learn to use it well then please post here if I get like 7 or more people say they want lessons I'll start posting them up.
Hellbreather.
-
October 9th '05 #2HellbreatherGuest
Re: Visual Basic 6 Tutorials
Okay well... Only got 9 views but I will post up the first lesson anyway and see if I get more views/replies this way...
Lesson 1 - Introduction To Visual Basic
Visual Basic is a WYSIWYG interface (What you see is what you get) a simple drag and drop tool.... of course there is programmining involved though..
It's easy to use and get the hang of and the advantage is that you can simply create forms quite easily and see the effects right away and make sure everything is placed exactly where you want it.
Building Your First Program
Okay well I will now show you how to create your first program... This is the general program that you create in every language you learn.
Now theres two ways I can show you to do this, but I'm going to cover them both.
On Form Load-Method 1
- First of all create a "Standard EXE File"
- Now double click on the working space
- And there should be the following lines:
Private Sub Form_Load()
End Sub
Now enter the following code underneath the "Private Sub Form_Load() bit:
Msgbox("Hello World!", VbOKOnly, "Hello")
The finished article should look like this
Using Command Button - Method 2Code:Private Sub Form_Load() Msgbox("Hello World!", VbOKOnly, "Hello") End Sub
Do the same for Method 1 except dont click on the working space this time find the "Command Button" button and put one on the working space.
Now double-click on the command button and you should see this bit of code:
Now type in the same Msgbox code so now your code should be:Code:Private Sub Command1_Click() End Sub
Code BreakDownCode:Private Sub Command1_Click() Msgbox("Hello World!", VbOKOnly, "Hello") End Sub
Private Sub and End Sub
These bits translated would simply be "Start Program When....." and "End Program"
MsgBox
Now, this part of the code needs to be broken down into several parts:
- Msgbox - Tells the program to display a message box on the screen
- "Hello World!" - Tells the program what text to display in the message box
- VbOKOnly - Tells the program what type of message box to display
- "Hello" - Tells the program what the title of the message box is#
Exercise Set 1
Now that you have made that program work try doing the following to the Msgbox Code:
- Make it display different text
- Experiment with all the different types of message boxes (referring to VbOKOnly)
- Change the title of the message boxes (Referring to Hello)
-
August 3rd '06 #3
Re: Visual Basic 6 Tutorials
Hey man, I have a 6 disc tutorial of Visual Basic .Net 2003. I'll rip them and send them to you.
-
October 12th '06 #4
Re: Visual Basic 6 Tutorials
That's cool but I got VB 2005 now lol.
So Im back to help

-
November 20th '06 #5
Re: Visual Basic 6 Tutorials
Hey dude I'm doing more difficult stuff in my college. It would be nice if you could help and give more tips to how to make this program contain a for loop.
The code:
Option Explicit
Dim mconv(0 To 11) As Single
Dim mnum(0 To 11) As Single
'Here I've created variables and made them into array's. An array representing boxes 0-11.
'I've placed the codes under Option Explicit to allow them to become global.
Dim mhigh As Single
Dim mlow As Single
Dim mrange As Single
'Created a number of variables here.
Private Sub cmdrange_Click()
txtrange.Text = txthc.Text - txtlc.Text
'A calculation to work out the range. Whatever figure is placed in textbox txtlc will be subtracted from textbox txthc and the results will be placed in textbox txtrange.
End Sub
Private Sub cmdrange1_Click()
txtrange1.Text = txthc1.Text - txtlc1.Text
End Sub
Private Sub txt1_lostfocus(index As Integer)
Dim cancel As Boolean
'Created the variable and the reason I selected Boolean is because the data I will be inputting is either true or false.
If txt1(index) = "" Then
cancel = True
'If the textbox txt1 is empty then the cancel variable will be activated.
Else
mconv(index) = txt1(index).Text
'Here I've placed all the txt1 boxes under the array mconv.
mconv(index) = (txt1(index) - 32) * 5 / 9
'Now the mconv variable will be active on the boxes representing the name txt1 and so will the calculation.
txt2(index).Text = mconv(index)
'I've now also placed the boxes representing the name txt2 within the variable mconv.
txt2(index).Text = Format(mconv(index), "##.#")
'This code allowed me to format my figures into one decimal place.
If txt1(index).Text > 15 Then
txt2(index).BackColor = vbRed
'If the textbox txt1 has a number under 15 placed within it then it will not change colour. But if it's higher than 15 then the background colour will change into red.
End If
End If
'The program [if] here has been ended.
Call highlow(index)
'After the steps above, the procedure highlow will be called.
End Sub
'This is the procedure I had created to work out the ranges.
Private Sub highlow(index)
If index = 0 Then
mhigh = mconv(index)
mlow = mconv(index)
End If
'If the index is equal to zero then the variable array mconv will be active in the variable mhigh and mlow.
If mconv(index) >= mhigh Then
mhigh = mconv(index)
txthc1.Text = mhigh
End If
'If mconv is greater or equal to mhigh then mconv will be placed in mhigh. The variable mhigh is now active in textbox txthc1.
If mconv(index) <= mlow Then
mlow = mconv(index)
txtlc1.Text = mlow
End If
'If the array mconv is less or equal to mlow then mconv will be placed in mlow. The variable mlow is now active in textbox txtlc1.
End Sub
Private Sub highlow1(index)
If index = 0 Then
mhigh = mconv(index)
mlow = mconv(index)
End If
If mconv(index) >= mhigh Then
mhigh = mconv(index)
txthc.Text = mhigh
End If
If mconv(index) <= mlow Then
mlow = mconv(index)
txtlc.Text = mlow
End If
End Sub
Private Sub txtf_LostFocus(index As Integer)
Dim cancel1 As Boolean
If txtf(index) = "" Then
cancel1 = True
Else
mconv(index) = txtf(index).Text
mconv(index) = (txtf(index) - 32) * 5 / 9
txtc(index).Text = mconv(index)
If txtf(index).Text > 15 Then
txtc(index).BackColor = vbGreen
End If
End If
Call highlow1(index)
End Sub
-
May 19th '07 #6
Re: Visual Basic 6 Tutorials
Loops in VB .Net (Example)
Code:Module Module1 Sub Main() Dim d As Integer For d = 0 To 2 System.Console.WriteLine("In the For Loop"); Next d End Sub End Module
-
May 19th '07 #7
Re: Visual Basic 6 Tutorials
Aye.
"For, Next" loops are "determinstic", as in ya know how exactly how many times ya need it to loop. If ya don't know exactly how many times and want it to loop forever until something changes or something stops it then use a non-deterministic loop such as a "Do, While", or "Do, Until" loop. (I do my coding in VB.NET so if any of it looks a bit funky compared to VB6 or whatever then thats probably why)
"Do While" loop:
"Do, Until" loop:Code:'Variable Declarations Dim Variable1 As Integer Dim Variable2 As Integer 'Variable Initialisation. Variable1 = 0 Variable2 = 5 'Loop Process. Do While Variable1 < Variable2 Variable1 = Variable1 +1 Loop
The difference between these loops is that the "Do, While" loop will continue to loop while ever the condition stated is true, if the condition changes, this will end the loop.Code:'Variable Declarations. Dim Variable1 As Integer Dim Variable2 As Integer 'Variable Initialisation. Variable1 = 0 Variable2 = 5 'Loop Process. Do Until Variable1 = Variable2 Variable1 = Variable1 +1 Loop
The "Do, Until" loop will continue to run the code in the loop and then stop when the condition stated is true. So one loops untill the stated condition changes, and the other loops until it is met, hence the "while" and "until" in the loop names.
You can sometimes get the same effect by using one of the other loops and just change the condition around a lil but its good practice to use the correct loop for the correct task, and to do that you have to think about first what you already know, what you need you loop to do, and then what will "catch" it end end the loop.
Once you've thought about this you can then choose your loop, "For, Next" loops have a numerical catch and run a set number of times, while the "Do, Until" and "Do, While" loops have a condition catch, such as loop until the condition changes, or whilever it is true. Some examples of loop choices are below:
"Will I need the loop to run a set number of times, and do I know how many times?"
If yes then your choice of loop should be the "For, Next" one shown in Jordon's example.
"Do I need the loop to run while a condition is true and then stop when or if it changes?"
The choice of loop for this should be the "Do, While" loop.
"I need my loop to keep running until something stops it."
For this, the "Do, Until" loop should be used.
Also Jordon may I ask what languages do you normally do ya programs in, or what are ya used to/like the best? As for the mo I've only really programmed in VB.NET and VBA, theyre quite similar of course but I was wondering what sorta language is mainly used for professional programs and so on, or if it depends on different factors.
I'd assume C++ and Java are used quite a lot but I have no idea if VB.NET is still any use. The tutors are trying to teach us the concepts mostly though so we'll be able to apply em to other languages and so on.Last edited by Bob! : May 21st '07 at 04:09 AM

--Bob!--
Similar Threads
-
Basic Instinct 2
By manutd 4 ever in forum MediaReplies: 3Last Post: April 12th '06, 10:06 PM


Reply With Quote



Bookmarks