Thread: Array Question

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Australia
    Posts
    24
    Rep Power
    0

    Array Question


    I have two string arrays that I intend to access items from randomly
    The major thing I want to do is to access, for example, item 8 from both arrays, put one in a hint box and have the other as a password to be entered and if the password is entered incorrectly, then another set of items is selected and re-entererd, is there a way that I can do this? Any help is appreciated
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    14
    Rep Power
    0
    Originally Posted by Problematic
    I have two string arrays that I intend to access items from randomly
    The major thing I want to do is to access, for example, item 8 from both arrays, put one in a hint box and have the other as a password to be entered and if the password is entered incorrectly, then another set of items is selected and re-entererd, is there a way that I can do this? Any help is appreciated
    You can create the 2 string arrays, fill them with values and use a random number generator to generate an integer value that falls within the bounds of your arrays. Use the integer value to select an array item by index number.

    You can Google "vb.net generate random number" to learn how or find sample code to generate random numbers within a range

    cheers
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Australia
    Posts
    24
    Rep Power
    0
    I already know how to create a random number generator, but using that number to access a string from the array, I have abosulutely no idea how to do that
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    /dev/null
    Posts
    163
    Rep Power
    18
    Originally Posted by Problematic
    I already know how to create a random number generator, but using that number to access a string from the array, I have abosulutely no idea how to do that
    Use the random number generated as the index and fetch the corresponding string from both arrays. Here's a pseudo-code:
    Code:
    rnd = rand() # An integer number in the required range.
    reqStr = strArr[rnd]
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Australia
    Posts
    24
    Rep Power
    0
    Code:
    Int = Rand.Next(0, 8)
            Int2 = Int
            Str2 = Hint(Int2)
            Str = Password(Int)
    I worked it out, now I'm trying to make another statement within a messagebox
    Code:
    MsgBox("Incorrect password, you have  more tries before the program closes and locks you out", MsgBoxStyle.Critical, "WARNING")
    I've been trying to put a number that counts down between "more" and "tries" but can't work out how exactly to do that, e.g 4...3...2...1...0, any help is appreciated

IMN logo majestic logo threadwatch logo seochat tools logo