Results 1 to 7 of 7

Thread: [RESOLVED] Need Major Help

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    Las Vegas, NV
    Posts
    301

    Resolved [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...

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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:
    1. Dim arrayOfWords() as String
    2. '...
    3. '...
    4. '...
    5. Dim rnd as New Random
    6. Dim intIndex as Integer = rnd.Next(0, arrayOfWords.GetUpperBound(0)+1)
    7. MessageBox.Show(arrayOfWords(intindex))
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    Las Vegas, NV
    Posts
    301

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

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Need Major Help

    The randomly picked word is in the arrayOfWords(intIndex) variable and can be used wherever you want.
    VB Code:
    1. TextBox1.Text = arrayOfWords(intIndex)

    And here is one way to insert the words:
    VB Code:
    1. 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.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    Las Vegas, NV
    Posts
    301

    Re: Need Major Help

    it's telling me that

    (intIndex)

    is not declared

  6. #6
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    Las Vegas, NV
    Posts
    301

    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
  •  



Click Here to Expand Forum to Full Width