Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Serial Numbers
#1
Well hello again, I'm here with another bit of code, I was pondering the idea of a way to add serial codes and code checks to my programs, and this is what i came up with to generate a serial number>
Code: (Select All)
Function genCode$
    Dim As Single one, two, three: one = 8: two = 7: three = 4
    Dim code As String
    '1
    Do
        For i = 1 To 5
            x$ = x$ + _Trim$(Str$(Int(Rnd * 10)))
        Next
        If Val(x$) Mod one = 0 Then
            Exit Do
        Else
            x$ = ""
        End If
    Loop
    code = x$
    x$ = ""
    '2
    Do
        For i = 1 To 7
            x$ = x$ + _Trim$(Str$(Int(Rnd * 10)))
        Next
        If Val(x$) Mod two = 0 Then
            Exit Do
        Else
            x$ = ""
        End If
    Loop
    code = code + "-" + x$
    x$ = ""
    '3
    Do
        For i = 1 To 5
            x$ = x$ + _Trim$(Str$(Int(Rnd * 10)))
        Next
        If Val(x$) Mod three = 0 Then
            Exit Do
        Else
            x$ = ""
        End If
    Loop

and this is what checks to see if the code is valid, and then returns a 1 for valid and a 0 for invalid>
Code: (Select All)
Function checkcode (d As String)
    Dim As Single one, two, three: one = 8: two = 7: three = 4
    Dim As String a, b, c

    If InStr(d, "-") = 0 Then
        a = Mid$(d, 1, 5)
        b = Mid$(d, 6, 7)
        c = Mid$(d, 13, 5)
        Print a, b, c
    End If

    a = Left$(d, InStr(d, "-") - 1)
    b = Mid$(d, InStr(d, "-") + 1, 7)
    c = Right$(d, 5)

    If Val(a) Mod one = 0 And Val(b) Mod two = 0 And Val(c) Mod three = 0 Then
        If d = "" Then checkcode = 0: Exit Function
        checkcode = 1
    Else
        checkcode = 0
    End If
End Function


Attached Files
.bm   serial.bm (Size: 1.46 KB / Downloads: 28)
Reply
#2
"C64 Run" Magazine was full of this stuff. Had a program that had to be entered and run first of all. Then when the user entered one of the games or other programs featured in the magazine, after [ENTER] key was pressed it gave out an "unique" number. The user was supposed to make sure that number matched the one for the current line in the printed source code.

LOL I still wanted to know what was that "Connex" which was like Tetris, featured in one issue for the Commodore 128.
Reply




Users browsing this thread: 1 Guest(s)