Well basically i've been learning VB 6.0 (Visual Basic 6.0) for about 2 weeks now and i've come quiet far.
So i've decided to make a tutorial on a simple program that responds to your words(made completely by ME, but i was helped by a few tutorials). It will use a different color the express what it's saying when you say specific words/anything. You can check the code for the words lol.
Well here it goes:
First open up VB 6.0.
Then make a few command buttons depending on how many responses you want to have.
Put their names as cmd"Blah" ("Blah" means put it as whatever you want it to be eg. "cmdName" would be the button to click to enter your name.
Captions can be whatever you want.
----------------------------------------------------------------
Now, for the coding:
----------------------------------------------------------------Private Sub cmdName_Click()
Dim strName As String
strName = InputBox("Enter your name:", "Name")
Select Case strName
Case "Trevor"
frmTest.ForeColor = vbGreen
Print "Hello there, "; strName; "."
Print "How old are you?"
Case Else
frmTest.ForeColor = vbPink
Print "Hello there, "; strName; "."
Print "How old are you?"
End Select
End Sub
Code Explanation:
Makes the InputBox (Box that requires you to type a response in)strName = InputBox("Enter your name:", "Name")
with the title "Name" and the message "Enter your name:"
----------------------------------------------------------------
Also the above code would cause the form to be printed with:Case "Trevor"
frmTest.ForeColor = vbGreen
Print "Hello there, "; strName; "."
Print "How old are you?"
The ;strName; is the "String" or response of the person In this case it's:"Hello there, ";strName; "."
"How old are you?"
Case "Trevor" (meaning if the person answered "Trevor" as their name, it would print "Hello there, Trevor" and "How old are you?" in green.)
----------------------------------------------------------------
This code would print the text:Case Else
frmTest.ForeColor = vbRed
Print "Hello there, "; strName; "."
Print "How old are you?"
"Hello there,"; strName; "."
"How old are you?"
ONLY if the response of the person was something other then "Trevor".
P.S - You may have noticed that i put:
Twice in both of the "Case" codes, this is kind of like insurance so that it will actually print something rather then nothing. (I found that if i didn't add it twice, it would only print those lines if i answered "Trevor" as the response."Hello there,"; strName; "."
"How old are you?"
And as always before the "End Sub" function in the code, put a
"End Case" to end the "Case"
Please note that there will be an error if you don't add the
"End Case" function to the coding.
----------------------------------------------------------------
Ok now we're done with the code for your name.
You can use the same structure for every button.
eg. cmdAge (cmdAge is the name for the button and Age would be the caption) would be:
And so on....Private Sub cmdAge_Click()
Dim strAge As String
strAge = InputBox("Enter your Age:", "Age")
Select Case strName
Case "14"
frmTest.ForeColor = vbWhite
Print "WoW! "; strAge; " Years young!"
Print "What country do you live in"; strName; "?"
Case Else
frmTest.ForeColor = vbBlack
Print "WoW! "; strAge; " Years young!"
Print "What country do you live in"; strName; "?"
End Select
End Sub
----------------------------------------------------------------
Code Explanation:
Makes the InputBox (Box that requires you to type a response in)strAge = InputBox("Enter your Age:", "Age")
with the title "Age" and the message "Enter your Age:"
----------------------------------------------------------------
The above code would cause the form to be printed with:Case "14"
frmTest.ForeColor = vbWhite
Print "WoW! "; strAge; " Years young!"
Print "What country do you live in"; strName; "?"
[QUOTE"]"WoW! "; strAge; " Years young!"
"What country do you live in"; strName; "?"[/quote]
The ;strAge; is the "String" or response of the person In this case it's:
Case "14" (meaning if the person answered "14" as their age, it would print ""WoW! "; strAge; " Years young!" and "What country do you live in"; strName; "?" in White)
----------------------------------------------------------------
This code would print the text (In black as specified):Case Else
frmTest.ForeColor = vbBlack
Print "WoW! "; strAge; " Years young!"
Print "What country do you live in"; strName; "?"
"WoW! "; strAge; " Years young!"
"What country do you live in"; strName; "?"
ONLY if the response of the person was something other then "14".
P.S - You may have noticed that i put:
Twice in both of the "Case" codes, this is kind of like insurance so that it will actually print something rather then nothing. (I found that if i didn't add it twice, it would only print those lines if i answered "14" as the response."WoW! "; strAge; " Years young!"
"What country do you live in"; strName; "?"
And as always before the "End Sub" function in the code, put a
"End Case" to end the "Case"
Please note that there will be an error if you don't add the
"End Case" function to the coding.
----------------------------------------------------------------
So basically just change the str"blah" ("blah" being what you're asking eg. Age, Name, location.) according to what you're asking for each of the command buttons.
eg. strName
strAge
strCountry
And so on..
Also if you wanted to clear the text from the form.... Make a new button with the name "cmdClear" and Caption "Clear text"
Then open up the code for it and use this code:
If you need any further assistance please pm me or feel free to ask on this thread.Private Sub cmdClear_Click()
Cls
End Sub
I've enclosed a sample.
EDIT - I've also added my GUI (My layout of the SmarterChild copy)
EDIT - I've re-attached the samples.
Thanks for the feedback!
Once again this tutorial was made completely by me, Travy92 but i had some help from oOTheNerdOo (The "Select Case" part) and thanks to tcm9669 for the screenshot program!.
Last edited by Jordan; 09-10-2007 at 06:15 AM.
OH! OMG. Admins could you please move this to Visual Basic tutorials section? I accidently posted it in VB prgramming sections.. Sorry!
And could ya please change the title of the thread to "Tutorial - Smarterchild copy" ?
Thanks.
EDIT - Thanks Jordan for moving it and renaming it.
Last edited by travy92; 09-08-2007 at 06:50 PM.
Hey Travy92, nice tutorial! I'll move this to the tutorial section and change the title.
Yes - I must admit it's a nice tutorial I'm going to download and test it.
EDIT:- The Zip/Rar Files are empty!
And Just a Tip, when you are talking about copies of scripts/programs etc.. you say Clone, not copy. So it should be 'Smarterchild Clone' just to let you know.. but it's up to you.
Last edited by TcM; 09-08-2007 at 09:05 AM.
It`dose look sound i will have to take a look at the source to see what it really looks like.
Edit:
you may want to check your code for people entering incorrect data
example how old are you I entered "HG" which are not numbers, if you were to make a textbox you could place this code in the program.
this code would have to be in this subCode:Select Case KeyAscii Case 8 Case 13 Case 48 Case 49 Case 50 Case 51 Case 52 Case 53 Case 54 Case 55 Case 56 Case 57 Case 127 Case Else MsgBox "Alpha Charecters are not permited", vbInformation, "error" KeyAscii = 0 end select
Private Sub Txtinput_KeyPress(KeyAscii As Integer)
presuming you box would be Txtinput
Before someone thinks that I'm stupid i have no education background in programing and i'm sure that there are better ways of doing this out there. but this is the one i found that worked for me.
you could i guess do it using and if statement, like
*this one has not been tested but i think it should work. I hopeCode:If keyascii <> 8 or keyascii <> 13 or keyascii <> 48 or keyascii <> 49 or keyascii <> 50 or_ keyascii <> 51 or keyascii <> 52 or keyascii <> 53 or keyascii <> 54 or keyascii <> 55_ or keyascii <> 56or keyascii <> 57 or keyascii <> 127 then keyascii=0 end if
they would both go in the same sub the 2 method should work at any time but will only let you do 1234567890 enter del and backspace wihich should be ok...
Last edited by compil003; 09-14-2007 at 07:18 AM. Reason: add comments for the author
Oh, yeah ! Thanks for the tip. I'll use it in my next tutorials if i'm making a tut on a similar program!
thanks
Thx for the tutorial ! =)
this helped a whot
This is pretty useful but im having trouble understanding how can i make it so it automaticly talks to my messenger list?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks