|
-
Feb 17th, 2007, 06:00 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Need Major Help
let me see if i can get this expressed clearly...
i want my progrom to provide responses based on answers typed into a text box...
so far, it works using the "if then" statements... for example... i want my program to do this... when the user types in the text box...
user: hello
program: "hello" or "hi" or "hey"
i only want it to give one of those responses, randomly... it works for the most part except i can't get it to give random answers from a predetermined list... can anyone help...
-
Feb 17th, 2007, 06:19 PM
#2
Re: Need Major Help
You should use the random class.
Are these answers in an array? Or a collection?
I guess its in an array:
VB Code:
Dim arrayOfWords() as String
'...
'...
'...
Dim rnd as New Random
Dim intIndex as Integer = rnd.Next(0, arrayOfWords.GetUpperBound(0)+1)
MessageBox.Show(arrayOfWords(intindex))
-
Feb 17th, 2007, 06:45 PM
#3
Thread Starter
Hyperactive Member
Re: Need Major Help
i want it to show in texbox1, not a message box... how would i do that? where would i insert the words...
not really sure the difference between arrays and collections, but i'll check that out now...
-
Feb 17th, 2007, 06:53 PM
#4
Re: Need Major Help
The randomly picked word is in the arrayOfWords(intIndex) variable and can be used wherever you want.
VB Code:
TextBox1.Text = arrayOfWords(intIndex)
And here is one way to insert the words:
VB Code:
Dim arrayOfWords() as String = {"Hello", "Hi", "Yo!", "Good day"}
Not that you should declare the array of words outside any procedure, in the general declarations.
You should do some reading on MSDN about arrays and collections, but in this case you should be using arrays and not collections.
-
Feb 17th, 2007, 09:07 PM
#5
Thread Starter
Hyperactive Member
Re: Need Major Help
it's telling me that
(intIndex)
is not declared
-
Feb 17th, 2007, 10:25 PM
#6
Re: Need Major Help
It shouldnt give you that if you used all of the code I provided in the first post.
You cant use the intIndex in another procedure than the one it is declared in.
-
Feb 18th, 2007, 12:13 AM
#7
Thread Starter
Hyperactive Member
Re: Need Major Help
got it... thanks... it works perfect...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|