MAGIC 8 BALL TUT
Let's begin with what control settings you need.
-Label (1) = Default settings
-TextBox (1) = Default settings
-Command Button (1) = Default Settings
-Standard .EXE
Place your controls on the form in a comfortable sense.
To do that I guess I should tell you what they are going to be used for:
-The label is for the 8-Ball's answer
-The textbox is for the question
-The Command button is to answer the question
Change the names of the controls or other settings to your likings before we start.
---------------------------------------------------------
OK!!! Let's start the programming! This is a very simple application, and is *of course* designed for beginners at VB6. Please do not flame this tutorial, it is only to help out. If you're going to post anything at all, make it a Thanks or constructive comments. Nothing negative and no spam.
CODE TIME.
Ok, here we have the code for your command button, or answer button. This is the only code of the application.
Code:
Private Sub Command1_Click()
Answer = Array("I'm afraid so.", "I really hope not.", "How the hell am I supposed to know?", "That's a hard one. Come back later.", "It could very well be so!")
Randomize
n = Int(5*Rnd)
label1.caption = Answer(n)
End Sub
Let's begin the explanation with the last line of code (forgive me for starting backwards
Code:
Text1.Text = Answer(n)
Now a bit further up we start having the complicated stuff, with all the variables and such.
Code:
Answer = Array("I'm afraid so.", "I really hope not.", "How the hell am I supposed to know?", "That's a hard one. Come back later.", "It could very well be so!")
Randomize
n = Int(5*Rnd)
At the top we have the "Answer =" function. What this is, is an instruction telling the program what the possible answers can be. To shorten it up when we tell label1 to display the answer, we an "abreviation" if you will, to make it shorter to type the second time. It also makes it look less like a mess.
That next part, beginning with the "Randomize". That is well, the randomizing part, to tell the application to randomize the answer.
Now we have probably the most complicated part: The variable.
Each answer in this program corresponds to a number. In this case we have 0,1,2,3,4. Using the variable, we can identify and show one of these answers using number identification for them. The Rnd function helps us choose a number between 0.0 and 1.0 - This is a problem since we don't want decimals, we want full numbers. That's also to ease the process and render it less confusing. Using this, we can have our 5 answers. That's where the "Int" comes in. This useful function rounds off the random number chosen between 0.0 and 4.0 (now it's 4.0 due to the multiplication by 5 of the "Rnd function between the brackets) so it doesn't confuse the program, and the identity of our answers are nice and solid whole numbers. All that is packed in to choose the answer, therefore label1.caption = Answer(n).
Thanks and I hope you enjoyed my tutorial.
Credits
This was made from my knowledge, which has been built up from many sources and many tutorials, so if I listed all of them I could be here for ages...
So thanks so everyone on Sythe, Cruels and Fagex for their help.
WTF SOURCE CODE!?
I don't have a source code for you because I don't think giving the answers to you will help you learn. Read the tut and learn something.
I do have a compiled .exe of this project though, download it here (.rar).

















