Jump to content

Tutorial - Smarterchild copy

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
24 replies to this topic

#1
travy92

travy92

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
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:

[quote]
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 [/quote]----------------------------------------------------------------
[SIZE=2]Code Explanation:[/SIZE]

[quote]strName = InputBox("Enter your name:", "Name")[/quote]Makes the InputBox (Box that requires you to type a response in)
with the title "Name" and the message "Enter your name:"

----------------------------------------------------------------
[quote]Case "Trevor"
frmTest.ForeColor = vbGreen
Print "Hello there, "; strName; "."
Print "How old are you?"[/quote]Also the above code would cause the form to be printed with:

[quote]"Hello there, ";strName; "."
"How old are you?"[/quote]The ;strName; is the "String" or response of the person In this case it's:

Case "Trevor" (meaning if the person answered "Trevor" as their name, it would print "Hello there, Trevor" and "How old are you?" in green.)
----------------------------------------------------------------

[quote]Case Else
frmTest.ForeColor = vbRed
Print "Hello there, "; strName; "."
Print "How old are you?" [/quote]This code would print the text:
"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:
[quote]"Hello there,"; strName; "."
"How old are you?"[/quote]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.

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:

[quote]
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 [/quote]And so on....
----------------------------------------------------------------
[SIZE=2]Code Explanation:[/SIZE]

[quote]strAge = InputBox("Enter your Age:", "Age")[/quote]Makes the InputBox (Box that requires you to type a response in)
with the title "Age" and the message "Enter your Age:"
----------------------------------------------------------------
[quote]Case "14"
frmTest.ForeColor = vbWhite
Print "WoW! "; strAge; " Years young!"
Print "What country do you live in"; strName; "?"[/quote]The above code would cause the form to be printed with:

[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)


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

[quote]Case Else
frmTest.ForeColor = vbBlack
Print "WoW! "; strAge; " Years young!"
Print "What country do you live in"; strName; "?"[/quote]This code would print the text (In black as specified):
"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:
[quote]"WoW! "; strAge; " Years young!"
"What country do you live in"; strName; "?"[/quote]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.

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:

[quote]Private Sub cmdClear_Click()
Cls
End Sub[/quote]If you need any further assistance please pm me or feel free to ask on this thread.

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!.

Attached Files



#2
travy92

travy92

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
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.

#3
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Hey Travy92, nice tutorial! I'll move this to the tutorial section and change the title.

#4
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
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.

#5
compil003

compil003

    Newbie

  • Members
  • Pip
  • 1 posts
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.
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

this code would have to be in this sub

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
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
*this one has not been tested but i think it should work. I hope
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...

#6
travy92

travy92

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
Oh, yeah ! Thanks for the tip. I'll use it in my next tutorials if i'm making a tut on a similar program!
[SIGPIC]C:\Users\Travis\Desktop\Image Converter\Knight1.bmp[/SIGPIC]

#7
coco123

coco123

    Newbie

  • Members
  • Pip
  • 2 posts
thanks

#8
Amoon

Amoon

    Newbie

  • Members
  • Pip
  • 1 posts
Thx for the tutorial ! =)

#9
josh_the_insane_prince

josh_the_insane_prince

    Newbie

  • Members
  • Pip
  • 1 posts
this helped a whot

#10
Goatz

Goatz

    Newbie

  • Members
  • Pip
  • 1 posts
This is pretty useful but im having trouble understanding how can i make it so it automaticly talks to my messenger list?

#11
DJC

DJC

    Newbie

  • Members
  • Pip
  • 1 posts
Thanks for the tutorial!

#12
argjendii

argjendii

    Newbie

  • Members
  • Pip
  • 1 posts
Great tutorial thanks