Results 1 to 12 of 12

Thread: [RESOLVED] Random number generator - select concatentation method

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2010
    Posts
    30

    Resolved [RESOLVED] Random number generator - select concatentation method

    Hi there,

    I need to implement a random number generator into my program to choose a concatenation method at random to concatenate the user's input. I obviously do not want the same method to be generated every time the program is run. my code is as follows:

    Code:
    Dim whole_user_answer As String
    Private Sub Command1_Click()
    create_string whole_user_answer
    End Sub
    Private Sub create_string(ByRef whole_user_answer)
    whole_user_answer = user_answer_4 & user_answer_3 & user_answer_2 & user_answer_1
    MsgBox whole_user_answer
    End Sub
    
    Private Sub Form_Load()
    'This sets the interval for for the specified Timer(Print_Heading) equal to 63ms
    Print_Message.Interval = 63
    'This enables the specified Timer(Print_Heading)
    Print_Message.Enabled = True
    End Sub
    
    Private Sub Option1_Click()
    MsgBox "Are you sure you wish to generate 2 passwords?"
    
    End Sub
    
    Private Sub Option2_Click()
    MsgBox "Are you sure you wish to generate 3 passwords?"
    End Sub
    
    Private Sub Option3_Click()
    MsgBox "Are you sure you wish to generate 4 passwords?"
    End Sub
    
    Private Sub Option4_Click()
    MsgBox "Are you sure you want to generate passwords that are long in length?"
    End Sub
    
    Private Sub Option5_Click()
    MsgBox "Are you sure you want to generate passwords that are medium length?"
    End Sub
    
    Private Sub Option6_Click()
    MsgBox "Are you sure you want to generate passwords that are short in length?"
    End Sub
    
    Private Sub Print_Message_Timer()
    'This declares the text which shall be displayed one character after another:
    title_text_string = "Please select how many passwords you wish to generate:"
    
    Static Ptr As Long
    
    If Ptr < Len(title_text_string) Then
        Ptr = Ptr + 1
        lbl_intro.Caption = Left$(title_text_string, Ptr)
        
    Else
    
        Ptr = 0
        'This disables the specified Timer(Print_Heading)
        Print_Message.Enabled = False
        
    'This ends the IF statement
    End If
    
    End Sub
    
    Private Sub create_short_passwords(ByVal whole_user_answer)
    Dim concatentation_method_1 As String
    Dim concatentation_method_2 As String
    Dim concatentation_method_3 As String
    Dim concatentation_method_4 As String
    Dim concatentation_method_5 As String
    
    concatentation_method_1 = Left$(whole_user_answer, 3) & Right$(whole_user_answer, 3)
    concatentation_method_2 = Left$(whole_user_answer, 2) & Right$(whole_user_answer, 3)
    concatentation_method_3 = Left$(whole_user_answer, 3) & Right$(whole_user_answer, 2)
    concatentation_method_4 = Left$(whole_user_answer, 2) & Right$(whole_user_answer, 2)
    concatentation_method_5 = Left$(whole_user_answer, 1) & Right$(whole_user_answer, 3)
    End Sub
    
    Private Sub create_medium_passwords(ByVal whole_user_answer)
    Dim concatentation_method_1 As String
    Dim concatentation_method_2 As String
    Dim concatentation_method_3 As String
    Dim concatentation_method_4 As String
    Dim concatentation_method_5 As String
    
    concatentation_method_1 = Left$(whole_user_answer, 4) & Right$(whole_user_answer, 4)
    concatentation_method_2 = Left$(whole_user_answer, 3) & Right$(whole_user_answer, 4)
    concatentation_method_3 = Left$(whole_user_answer, 4) & Right$(whole_user_answer, 3)
    concatentation_method_4 = Left$(whole_user_answer, 2) & Right$(whole_user_answer, 5)
    concatentation_method_5 = Left$(whole_user_answer, 5) & Right$(whole_user_answer, 3)
    End Sub
    Private Sub create_long_passwords(ByVal whole_user_answer)
    Dim concatentation_method_1 As String
    Dim concatentation_method_2 As String
    Dim concatentation_method_3 As String
    Dim concatentation_method_4 As String
    Dim concatentation_method_5 As String
    
    concatentation_method_1 = Left$(whole_user_answer, 5) & Right$(whole_user_answer, 4)
    concatentation_method_2 = Left$(whole_user_answer, 4) & Right$(whole_user_answer, 5)
    concatentation_method_3 = Left$(whole_user_answer, 5) & Right$(whole_user_answer, 5)
    concatentation_method_4 = Left$(whole_user_answer, 6) & Right$(whole_user_answer, 5)
    concatentation_method_5 = Left$(whole_user_answer, 5) & Right$(whole_user_answer, 6)
    End Sub
    Many thanks,

  2. #2
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Random number generator - select concatentation method

    My question is what is your question?
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2010
    Posts
    30

    Re: Random number generator - select concatentation method

    Quote Originally Posted by MarMan View Post
    My question is what is your question?
    My question is how do implement this random number generator to generate a concatenation method at random?

    Many thanks,

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Random number generator - select concatentation method

    Thread moved from the 'CodeBank VB6' forum (which is for you to post working code examples, not questions) to the 'VB6 and earlier' forum

  5. #5
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Random number generator - select concatentation method

    Interrogate the random number and call the appropriate function.
    Code:
    Select Case Int(rnd(1)* NumberOfFunctions ) + 1
        Case 1
            CallMethod1
        Case 2
            CallMethod2
        ect.
    End Select
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Dec 2010
    Posts
    30

    Re: Random number generator - select concatentation method

    Quote Originally Posted by MarMan View Post
    Interrogate the random number and call the appropriate function.
    Code:
    Select Case Int(rnd(1)* NumberOfFunctions ) + 1
        Case 1
            CallMethod1
        Case 2
            CallMethod2
        ect.
    End Select

    Hi there, thanks for you reply, I am now getting a sub or function not defiended error :s. My code is as follows:

    Code:
    Private Sub create_user_answer(ByRef whole_user_answer)
    whole_user_answer = user_answer_4 & user_answer_3 & user_answer_2 & user_answer_1
    End Sub
    
    Private Sub Form_Load()
    'This sets the interval for for the specified Timer(Print_Heading) equal to 63ms
    Print_Message.Interval = 63
    'This enables the specified Timer(Print_Heading)
    Print_Message.Enabled = True
    End Sub
    
    Private Sub Option1_Click()
    MsgBox "Are you sure you wish to generate 2 passwords?"
    
    End Sub
    
    Private Sub Option2_Click()
    MsgBox "Are you sure you wish to generate 3 passwords?"
    End Sub
    
    Private Sub Option3_Click()
    MsgBox "Are you sure you wish to generate 4 passwords?"
    End Sub
    
    Private Sub Option4_Click()
    MsgBox "Are you sure you want to generate passwords that are long in length?"
    End Sub
    
    Private Sub Option5_Click()
    MsgBox "Are you sure you want to generate passwords that are medium length?"
    End Sub
    
    Private Sub Option6_Click()
    create_short_passwords whole_user_answer
    MsgBox "Are you sure you want to generate passwords that are short in length?"
    End Sub
    
    Private Sub Print_Message_Timer()
    'This declares the text which shall be displayed one character after another:
    title_text_string = "Please select how many passwords you wish to generate:"
    
    Static Ptr As Long
    
    If Ptr < Len(title_text_string) Then
        Ptr = Ptr + 1
        lbl_intro.Caption = Left$(title_text_string, Ptr)
        
    Else
    
        Ptr = 0
        'This disables the specified Timer(Print_Heading)
        Print_Message.Enabled = False
        
    'This ends the IF statement
    End If
    
    End Sub
    
    Private Sub create_short_passwords(ByVal whole_user_answer)
    
    Select Case Int(Rnd(1) * 5) + 1
        Case 1
            Call concatentation_method_1
        Case 2
            Call concatentation_method_2
        Case 3
            Call concatentation_method_3
        Case4
            Call concatentation_method_4
        Case5
            Call concatentation_method_5
    End Select
    
    Dim concatentation_method_1 As String
    Dim concatentation_method_2 As String
    Dim concatentation_method_3 As String
    Dim concatentation_method_4 As String
    Dim concatentation_method_5 As String
    
    concatentation_method_1 = Left$(whole_user_answer, 3) & Right$(whole_user_answer, 3)
    concatentation_method_2 = Left$(whole_user_answer, 2) & Right$(whole_user_answer, 3)
    concatentation_method_3 = Left$(whole_user_answer, 3) & Right$(whole_user_answer, 2)
    concatentation_method_4 = Left$(whole_user_answer, 2) & Right$(whole_user_answer, 2)
    concatentation_method_5 = Left$(whole_user_answer, 1) & Right$(whole_user_answer, 3)
    
    MsgBox selectcase
    End Sub
    
    'I have only implemented it into Private Sub create_short_passwords
    Many thanks,

  7. #7
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Random number generator - select concatentation method

    You call a Sub named "concatentation_method_1" which doesn't exist, instead you declared "concatentation_method_1" as String!
    At last you try to display "Select Case", which can't show you anything since its a function.
    What do you try to do with a selected "concatention_method_?"?
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Dec 2010
    Posts
    30

    Re: Random number generator - select concatentation method

    Quote Originally Posted by opus View Post
    You call a Sub named "concatentation_method_1" which doesn't exist, instead you declared "concatentation_method_1" as String!
    At last you try to display "Select Case", which can't show you anything since its a function.
    What do you try to do with a selected "concatention_method_?"?

    Ok, thanks.

    There may be some ambiguity in my question. I do not want each concatentation method to be a different sub. I want each password sub to have the ability to randomise the concatentation methods within that password sub as not all concatentation methods are the same for creating short, medium, and long passwords.
    Is there anyway of randomising the concatentation methods within each password sub so that not the same concatentation methods are chosen each time each individual procedure is activated?

    Code:
    Private Sub Command1_Click()
    create_user_answer whole_user_answer
    End Sub
    
    Private Sub create_user_answer (ByRef whole_user_answer)
    whole_user_answer = user_answer_4 & user_answer_3 & user_answer_2 & user_answer_1
    MsgBox whole_user_answer
    End Sub
    
    Private Sub Option4_Click()
    create_long_passwords whole_user_answer
    MsgBox "Are you sure you want to generate passwords that are long in length?"
    End Sub
    
    Private Sub Option5_Click()
    create_medium_passwords whole_user_answer
    MsgBox "Are you sure you want to generate passwords that are medium length?"
    End Sub
    
    Private Sub Option6_Click()
    create_short_passwords whole_user_answer
    MsgBox "Are you sure you want to generate passwords that are short in length?"
    
    End Sub
    
    
    Private Sub create_short_passwords(ByVal whole_user_answer)
    'I want the concatentaion methods in this sub to be randomised
    Dim concatentation_method_1 As String
    Dim concatentation_method_2 As String
    Dim concatentation_method_3 As String
    Dim concatentation_method_4 As String
    Dim concatentation_method_5 As String
    
    concatentation_method_1 = Left$(whole_user_answer, 3) & Right$(whole_user_answer, 3)
    concatentation_method_2 = Left$(whole_user_answer, 2) & Right$(whole_user_answer, 3)
    concatentation_method_3 = Left$(whole_user_answer, 3) & Right$(whole_user_answer, 2)
    concatentation_method_4 = Left$(whole_user_answer, 2) & Right$(whole_user_answer, 2)
    concatentation_method_5 = Left$(whole_user_answer, 1) & Right$(whole_user_answer, 3)
    
    MsgBox selectcase
    End Sub
    
    Private Sub create_medium_passwords(ByVal whole_user_answer)
    'I want the concatentaion methods in this sub to be randomised
    Dim concatentation_method_1 As String
    Dim concatentation_method_2 As String
    Dim concatentation_method_3 As String
    Dim concatentation_method_4 As String
    Dim concatentation_method_5 As String
    
    concatentation_method_1 = Left$(whole_user_answer, 4) & Right$(whole_user_answer, 4)
    concatentation_method_2 = Left$(whole_user_answer, 3) & Right$(whole_user_answer, 4)
    concatentation_method_3 = Left$(whole_user_answer, 4) & Right$(whole_user_answer, 3)
    concatentation_method_4 = Left$(whole_user_answer, 2) & Right$(whole_user_answer, 5)
    concatentation_method_5 = Left$(whole_user_answer, 5) & Right$(whole_user_answer, 3)
    End Sub
    
    Private Sub create_long_passwords(ByVal whole_user_answer)
    'I want the concatentaion methods in this sub to be randomised
    Dim concatentation_method_1 As String
    Dim concatentation_method_2 As String
    Dim concatentation_method_3 As String
    Dim concatentation_method_4 As String
    Dim concatentation_method_5 As String
    
    concatentation_method_1 = Left$(whole_user_answer, 5) & Right$(whole_user_answer, 4)
    concatentation_method_2 = Left$(whole_user_answer, 4) & Right$(whole_user_answer, 5)
    concatentation_method_3 = Left$(whole_user_answer, 5) & Right$(whole_user_answer, 5)
    concatentation_method_4 = Left$(whole_user_answer, 6) & Right$(whole_user_answer, 5)
    concatentation_method_5 = Left$(whole_user_answer, 5) & Right$(whole_user_answer, 6)
    End Sub
    'note how each concatentation method is different in each create_password sub(short,medium, long)
    Many thanks,
    Bainy

  9. #9
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Random number generator - select concatentation method

    Yes there is. Use the SELECT CASE statement.
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  10. #10
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Random number generator - select concatentation method

    Try this:
    Code:
    Private Sub create_short_passwords(ByVal whole_user_answer)
    Dim NewPassword As String
    Select Case Int(Rnd(1) * 5) + 1
        Case 1
            NewPassword =  Left$(whole_user_answer, 3) & Right$(whole_user_answer, 3)
        Case 2
            NewPassWord = Left$(whole_user_answer, 2) & Right$(whole_user_answer, 3)
        Case 3
           NewPassWord = Left$(whole_user_answer, 3) & Right$(whole_user_answer, 2)
        Case4
            NewPassWord = Left$(whole_user_answer, 2) & Right$(whole_user_answer, 3)
        Case5
           NewPassWord = Left$(whole_user_answer, 1) & Right$(whole_user_answer, 2)
    End Select
    
    MsgBox NewPassWord
    End Sub
    Note: You could easily put all password-creators in oner sub.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Dec 2010
    Posts
    30

    Re: Random number generator - select concatentation method

    Quote Originally Posted by opus View Post
    Try this:
    Code:
    Private Sub create_short_passwords(ByVal whole_user_answer)
    Dim NewPassword As String
    Select Case Int(Rnd(1) * 5) + 1
        Case 1
            NewPassword =  Left$(whole_user_answer, 3) & Right$(whole_user_answer, 3)
        Case 2
            NewPassWord = Left$(whole_user_answer, 2) & Right$(whole_user_answer, 3)
        Case 3
           NewPassWord = Left$(whole_user_answer, 3) & Right$(whole_user_answer, 2)
        Case4
            NewPassWord = Left$(whole_user_answer, 2) & Right$(whole_user_answer, 3)
        Case5
           NewPassWord = Left$(whole_user_answer, 1) & Right$(whole_user_answer, 2)
    End Select
    
    MsgBox NewPassWord
    End Sub
    Note: You could easily put all password-creators in oner sub.

    Got it. All working fine now . Thank you very much And i probably will put all the password generators in the one sub, but thats something I can do myself. Many thanks,
    bainy

  12. #12
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Thumbs up Re: Random number generator - select concatentation method

    Quote Originally Posted by bainy View Post
    ... but thats something I can do myself. Many thanks,
    bainy
    That is something we do like to read in here!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

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