Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Synergy.ron@gmail.com is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2020
    Location
    washington
    Posts
    50

    disect 6 digit serial....

    I have some vba code that generates a 6 digit random number. 056789 for example. I need to separate each digit and then use the chr(5+65) for example= "F". ultimately i will end with "AFH...etc.



    my problem is that i don't know what function to use to get each separate digit from the 6 digit serial??? what is the best way to do this??

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    8,973
    Not sure I get it. You want to add 65 to the chr value for each digit? Or you want to stick an "F" in between somethings?
    I have no idea where you're getting the H from. 6 + 65 would be G, not H but 5+65 would be F. I think I am close though?
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    Iím telling everyone it's good to eat dried grapes. Itís all about raisin awareness.

  3. #3
    isladogs's Avatar
    isladogs is offline Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    4,806
    Why not use code to generate a 6 character text string in the first place e.g. AFGHIJ...then no need for any conversion routine
    Colin (Mendip Data Systems): Website, email
    Try again. Fail again. Fail better.
    A
    sking for help isn't giving up. Its refusing to give up.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    15,551
    Here's a function to generate randomAlpha characters.
    Code:
    ---------------------------------------------------------------------------------------
    ' Procedure : randomalpha
    ' Author    : mellon
    ' Date      : 12/10/2015
    ' Purpose   : Returns random alpha characters based on your HowManyChars value
    '---------------------------------------------------------------------------------------
    '
    Function randomalpha(HowManyChars As Integer) As String
              Dim a As Long
              Dim Z As Long, i As Long
              Dim str As String
              Dim ralpha As Variant
              Dim Result As String
    10       On Error GoTo randomalpha_Error
    
    20        a = 1
    30        Z = 26
    40        str = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
    50        ralpha = Split(str, " ")
    
    60        For i = 1 To HowManyChars
    70            Result = Result & ralpha(randomNumber(a, Z) - 1)
                  'Debug.Print Result
    80        Next i
    90        randomalpha = Result
    
    100      On Error GoTo 0
    110      Exit Function
    
    randomalpha_Error:
    
    120       MsgBox "In Line " & Erl & "  Error " & Err.Number & " (" & Err.Description & ") in procedure randomalpha  of Module AccessMonster"
    End Function
    Calls this function

    Code:
    '---------------------------------------------------------------------------------------
    ' Procedure : randomNumber
    ' Author    : Jack
    ' Created   : 11/18/2010
    ' Purpose   : To Generate Random numbers between and including a range of numbers.
    'Lo and Hi are the lowest and highest random numbers you wish to generate.
    '
    'The Randomize keyword is critical to getting different results for each Access session.
    '=======================================================================================
    '---------------------------------------------------------------------------------------
    ' Last Modified:
    '
    ' Inputs: N/A
    ' Dependency: N/A
    '------------------------------------------------------------------------------
    '
    Function randomNumber(lo As Long, hi As Long) As Long
    10       On Error GoTo randomNumber_Error
    
    20    Randomize
    30    randomNumber = Int((hi - lo + 1) * Rnd + lo)
    
    40       On Error GoTo 0
    randomNumber_Exit:
    50       Exit Function
    
    randomNumber_Error:
    
    60        MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure randomNumber of Module AccessMonster"
    70        GoTo randomNumber_Exit
               
    End Function


    Test routine:

    Code:
    Sub testRandomAlpha()
     Debug.Print randomalpha(16)
    End Sub
    Result:

    FKCCVOCNTBRATVIC

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    8,973
    I want to close the db I have left hanging so I'll post code for what I thought was being asked for.
    Code:
    Public Function AlterVal(strValue As String) As String
    Dim i As Integer
    
    For i = 1 To Len(strValue)
    AlterVal = AlterVal & Chr(Mid(strValue, i, 1) + 65)
    Next
    MsgBox AlterVal
    End Function
    ?alterval("056789")
    AFGHIJ
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    Iím telling everyone it's good to eat dried grapes. Itís all about raisin awareness.

  6. #6
    Synergy.ron@gmail.com is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2020
    Location
    washington
    Posts
    50
    1) each copy of the app, when1st run creates a uniqe 6 digit number (serial)
    2)The user notifies (registers) the app w/ me by sending me the serial.
    3)I send the user the decode (alpha) code that unlocks the serial .

  7. #7
    wvmitchell is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2020
    Posts
    24
    Code:
    Function RON(myNumber As Double) As String
        Dim x As Long, s As String, t As String
        ' myNumber is a decimal number, like .056789
        myNumber = 1000000 * myNumber
        s = Format(myNumber, "000000")
        For x = 1 To 6
            t = t & Chr(65 + Mid(s, x, 1))
        Next x
        RON = t
    End Function

  8. #8
    isladogs's Avatar
    isladogs is offline Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    4,806
    Quote Originally Posted by Synergy.ron@gmail.com View Post
    1) each copy of the app, when1st run creates a uniqe 6 digit number (serial)
    2)The user notifies (registers) the app w/ me by sending me the serial.
    3)I send the user the decode (alpha) code that unlocks the serial .
    Sorry to sound negative, but if this is intended as a security measure, it will be trivial for anyone to hack.
    Colin (Mendip Data Systems): Website, email
    Try again. Fail again. Fail better.
    A
    sking for help isn't giving up. Its refusing to give up.

  9. #9
    Synergy.ron@gmail.com is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2020
    Location
    washington
    Posts
    50
    yes it is trival to hack. but this is a membership app for an organization that has an average age of about 70. Even a trivial code would stop most hacks......

  10. #10
    isladogs's Avatar
    isladogs is offline Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    4,806
    That may be true but I'm approaching 70 and, as I say, it would be trivial to hack.
    If you are going to apply security, you may as well do so seriously ... or in my opinion anyway, not bother at all
    Colin (Mendip Data Systems): Website, email
    Try again. Fail again. Fail better.
    A
    sking for help isn't giving up. Its refusing to give up.

  11. #11
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    8,973
    Gents, the distinction should be old and knowledgeable in Access versus old and not.
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    Iím telling everyone it's good to eat dried grapes. Itís all about raisin awareness.

  12. #12
    isladogs's Avatar
    isladogs is offline Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    4,806
    Better still....Older and wiser...
    Colin (Mendip Data Systems): Website, email
    Try again. Fail again. Fail better.
    A
    sking for help isn't giving up. Its refusing to give up.

  13. #13
    Synergy.ron@gmail.com is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2020
    Location
    washington
    Posts
    50
    Quote Originally Posted by isladogs View Post
    That may be true but I'm approaching 70 and, as I say, it would be trivial to hack.
    If you are going to apply security, you may as well do so seriously ... or in my opinion anyway, not bother at all
    I am over 70 and am just making sure the program is 'registered'.

  14. #14
    isladogs's Avatar
    isladogs is offline Very idle programmer
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    4,806
    Quote Originally Posted by Synergy.ron@gmail.com View Post
    I am over 70 and am just making sure the program is 'registered'.
    Not sure what 'registered' means but clearly you are older and wiser
    Colin (Mendip Data Systems): Website, email
    Try again. Fail again. Fail better.
    A
    sking for help isn't giving up. Its refusing to give up.

  15. #15
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    8,973
    Three solutions were offered - no comment on whether or not any of them were of any use. Is that a symptom?
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    Iím telling everyone it's good to eat dried grapes. Itís all about raisin awareness.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Count same digit numbers from each row
    By Gulya in forum Access
    Replies: 11
    Last Post: 01-12-2021, 12:17 PM
  2. Filter by 3rd digit
    By normie in forum Queries
    Replies: 10
    Last Post: 05-21-2017, 02:08 PM
  3. Replies: 3
    Last Post: 07-07-2015, 12:29 PM
  4. dates - 2 digit year
    By RCDAwebmaster in forum Queries
    Replies: 5
    Last Post: 05-20-2014, 08:14 AM
  5. Replies: 6
    Last Post: 09-20-2013, 01:58 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums - Senior Forums