Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: generate 4 - digits pin of same characters or digits
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular kelly mort's Avatar
    Join Date
    Apr 2017
    Location
    Suhum, Ghana, West Africa
    Posts
    1,507
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default generate 4 - digits pin of same characters or digits

    I want a way to generate any of these numbers at a time:
    1234
    0000
    1111
    2222
    3333
    4444
    5555
    6666
    7777
    8888
    9999

    I have this line below here which can check for the availability of those pins . I have been staring at it for a while now hoping to find a way around it but no success yet.
    I need tech support.

    Code:
    Select Case MyInput
            Case String (4, Left(MyInput, 1)), "1234"
             MsgBox "Found"
            Case Else
              MsgBox "Not Found"
    End Select
    I have been able to use an array with Rand Between function to get it like this

    Code:
    GetPin = MyArray(Application. RandBetween(LBound(MyArray), UBound(MyArray)))
    But instead of hard coding the list of possible pins into the array, I am looking for a way to pick or generate one of such pins.

    I just don't want them appear in plain text in my code.

    Thanks in advance
    There Is Always A Better Way

  2. #2
    Board Regular
    Join Date
    Mar 2016
    Posts
    220
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    2 Thread(s)

    Default Re: generate 4 - digits pin of same characters or digits

    Here is a function that returns one of those pins randomly with only "1234" hard-coded. Is this anything like what you are looking for?

    Code:
        GetPin = ReturnPin
    
    
    Function ReturnPin() As String
        Dim i As Integer
        Randomize
        i = Rnd * 10
        Select Case i
            Case 10
                 ReturnPin= "1234"
            Case Else
                 ReturnPin= i & i & i & i
        End Select
    End Function
    I assume that in your code, GetPin is somehow related to MyInput.

  3. #3
    Board Regular kelly mort's Avatar
    Join Date
    Apr 2017
    Location
    Suhum, Ghana, West Africa
    Posts
    1,507
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: generate 4 - digits pin of same characters or digits

    Quote Originally Posted by shknbk2 View Post
    Here is a function that returns one of those pins randomly with only "1234" hard-coded. Is this anything like what you are looking for?

    Code:
        GetPin = ReturnPin
    
    
    Function ReturnPin() As String
        Dim i As Integer
        Randomize
        i = Rnd * 10
        Select Case i
            Case 10
                 ReturnPin= "1234"
            Case Else
                 ReturnPin= i & i & i & i
        End Select
    End Function
    I assume that in your code, GetPin is somehow related to MyInput.
    Sure it is exactly like what I am looking for.

    And simpler than I ever imagined.

    Thanks for it
    There Is Always A Better Way

  4. #4
    Board Regular kelly mort's Avatar
    Join Date
    Apr 2017
    Location
    Suhum, Ghana, West Africa
    Posts
    1,507
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: generate 4 - digits pin of same characters or digits

    @shknbk2,

    Is there a way to add to the above code the numbers in the form:
    0123
    "1234"
    2345
    3456
    Etc?

    So that the hard coded 1234 part becomes the class of the numbers above?

    If anyone else has a knowledge about this please help me out.

    Regards
    There Is Always A Better Way

  5. #5
    Board Regular
    Join Date
    Mar 2016
    Posts
    220
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    2 Thread(s)

    Default Re: generate 4 - digits pin of same characters or digits

    Sure, this goes from 0123 to 6789.

    Code:
    Function ReturnPin() As String
        Dim i As Integer
        Randomize
        i = Rnd * 6
        ReturnPin= i & i + 1 & i + 2 & i + 3
     End Function

  6. #6
    Board Regular kelly mort's Avatar
    Join Date
    Apr 2017
    Location
    Suhum, Ghana, West Africa
    Posts
    1,507
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: generate 4 - digits pin of same characters or digits

    Quote Originally Posted by shknbk2 View Post
    Sure, this goes from 0123 to 6789.

    Code:
    Function ReturnPin() As String
        Dim i As Integer
        Randomize
        i = Rnd * 6
        ReturnPin= i & i + 1 & i + 2 & i + 3
     End Function
    Cool . I did something like this but could not replace the 10. Thanks for the fix.

    Is it possible to merge both of the codes you have supplied?

    I am thinking of making the "case 10" part in the first code take the latest code you have provided but I don't know what to add or what to remove
    There Is Always A Better Way

  7. #7
    Board Regular
    Join Date
    Mar 2016
    Posts
    220
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    2 Thread(s)

    Default Re: generate 4 - digits pin of same characters or digits

    Sure.

    Code:
    Function ReturnPin() As String
        Dim i As Integer
        Randomize
        i = Rnd * 10
        Select Case i
            Case 10
                i = Rnd * 6
                ReturnPin = i & i + 1 & i + 2 & i + 3
            Case Else
                ReturnPin = i & i & i & i
        End Select
    End Function

  8. #8
    Board Regular kelly mort's Avatar
    Join Date
    Apr 2017
    Location
    Suhum, Ghana, West Africa
    Posts
    1,507
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: generate 4 - digits pin of same characters or digits

    Quote Originally Posted by shknbk2 View Post
    Sure.

    Code:
    Function ReturnPin() As String
        Dim i As Integer
        Randomize
        i = Rnd * 10
        Select Case i
            Case 10
                i = Rnd * 6
                ReturnPin = i & i + 1 & i + 2 & i + 3
            Case Else
                ReturnPin = i & i & i & i
        End Select
    End Function
    Great!!!!

    I do have a bit of syntax issues.

    Have a wonderful time
    There Is Always A Better Way

  9. #9
    Board Regular kelly mort's Avatar
    Join Date
    Apr 2017
    Location
    Suhum, Ghana, West Africa
    Posts
    1,507
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: generate 4 - digits pin of same characters or digits

    Quote Originally Posted by shknbk2 View Post
    Sure.

    Code:
    Function ReturnPin() As String
        Dim i As Integer
        Randomize
        i = Rnd * 10
        Select Case i
            Case 10
                i = Rnd * 6
                ReturnPin = i & i + 1 & i + 2 & i + 3
            Case Else
                ReturnPin = i & i & i & i
        End Select
    End Function
    Hi

    One last thing:

    How do I get numbers like

    0011
    0022
    .......
    1100
    1122
    1133
    ........
    2200
    2211
    2233
    ........

    Added to the code we have so far?

    I can do say
    Case 0
    ReturnPin = i & i & i + 1 & i + 1

    Etc but how to update the above code with it is the headache now
    There Is Always A Better Way

  10. #10
    Board Regular
    Join Date
    Mar 2016
    Posts
    220
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    2 Thread(s)

    Default Re: generate 4 - digits pin of same characters or digits

    How about something like this?

    Code:
    Function ReturnPin() As String
        Dim i As Integer, i2 As Integer
        Randomize
        i = Rnd * 10
        i2 = Rnd * 9
        Select Case i
            Case 10
                i = Rnd * 6
                ReturnPin = i & i + 1 & i + 2 & i + 3
            Case Else
                ReturnPin = i & i & i2 & i2
        End Select
    End Function

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •