isnoend2001
asked on
Increase Numbers containing letters.
I have a registration routine
the credit card company that processes purchases needs a list of valid unlocking numbers.
each time a purchase is made the user is given the next unlocking number
I want to give them a list of 100 valid numbers are between 5000 and 9900
a valid entry could be yjk50kg00dky
with the number subtracted from the string it would be 5000
The next valid number would be yjk50kg01dky the nummbers in the string = 5001
the next 5002
the next 5003
all the way to a hundred.
the string would stay the same "yjkkgdky"
every number would be incremeted by 1
How to write this ?
the credit card company that processes purchases needs a list of valid unlocking numbers.
each time a purchase is made the user is given the next unlocking number
I want to give them a list of 100 valid numbers are between 5000 and 9900
a valid entry could be yjk50kg00dky
with the number subtracted from the string it would be 5000
The next valid number would be yjk50kg01dky the nummbers in the string = 5001
the next 5002
the next 5003
all the way to a hundred.
the string would stay the same "yjkkgdky"
every number would be incremeted by 1
How to write this ?
If the letters are always the same you could just do
Dim str1 As String
Dim str2 As String
Dim strNewUnlock As String
str1 = Mid$(LastUnlockNumber, 4, 2)
str2 = Mid$(LastUnlockNumber, 8, 2)
intNum = str1 & str2
intNum = intNum + 1
strNewUnlock = "yjk" & Left$(CStr(intNum), 2) & "kg" & Right$(CStr(intNum), 2) & "dky"
And I guess that it's unlikely to happen but maybe you should add lines 11 to 14.
Dim str1 As String
Dim str2 As String
Dim strNewUnlock As String
str1 = Mid$(LastUnlockNumber, 4, 2)
str2 = Mid$(LastUnlockNumber, 8, 2)
intNum = str1 & str2
intNum = intNum + 1
If intNum > 9900 Then
MsgBox "Too Large"
Exit Sub
End If
strNewUnlock = "yjk" & Left$(CStr(intNum), 2) & "kg" & Right$(CStr(intNum), 2) & "dky"
ASKER
Thanks martinliss.
this is unneeded
If intNum > 9900 Then
MsgBox "Too Large"
Exit Sub
End If
This is just a list of valid numbers to give the credit card company
I plan on just outputing the list to the debug window and pasting the numbers into their online screen.
in looking at your code should it be put into a loop 1-100 ?
this is unneeded
If intNum > 9900 Then
MsgBox "Too Large"
Exit Sub
End If
This is just a list of valid numbers to give the credit card company
I plan on just outputing the list to the debug window and pasting the numbers into their online screen.
in looking at your code should it be put into a loop 1-100 ?
ASKER
what is this variable LastUnlockNumber ?
ASKER
Martin I used your code to write this sub:
yjk50kg02dky
yjk50kg02dky sb yjk50kg03dky
yjk50kg02dky sb yjk50kg04dky
increase to 100
last number(100) sb yjk51kg00dk
Sub OutPutRegistractionNumbers() 'temp to output for online code disburstment
Dim i As Integer
Dim LastUnlockNumber As String
Dim str1 As String
Dim intNum As Long
Dim str2 As String
Dim strNewUnlock As String
LastUnlockNumber = "yjk50kg01dky"
For i = 1 To 100
str1 = Mid$(LastUnlockNumber, 4, 2)
str2 = Mid$(LastUnlockNumber, 8, 2)
intNum = str1 & str2
intNum = intNum + 1
strNewUnlock = "yjk" & Left$(CStr(intNum), 2) & "kg" & Right$(CStr(intNum), 2) & "dky"
Debug.Print strNewUnlock
Next
End Sub
but the debug showed :yjk50kg02dky
yjk50kg02dky sb yjk50kg03dky
yjk50kg02dky sb yjk50kg04dky
increase to 100
last number(100) sb yjk51kg00dk
You can use it as a function. If you run the "test" sub you will get:
Input: yjk50kg01dky output: yjk50kg02dky
Input: yjk50kg55dky output: yjk50kg56dky
Input: yjk50kg99dky output: yjk51kg00dky
Input: yjk50kg01dky output: yjk50kg02dky
Input: yjk50kg55dky output: yjk50kg56dky
Input: yjk50kg99dky output: yjk51kg00dky
Sub test()
OutPutRegistractionNumbers "yjk50kg01dky"
OutPutRegistractionNumbers "yjk50kg55dky"
OutPutRegistractionNumbers "yjk50kg99dky"
End Sub
Public Function OutPutRegistractionNumbers(LastUnlockNumber) As String 'temp to output for online code disburstment
Dim str1 As String
Dim intNum As Long
Dim str2 As String
Dim strNewUnlock As String
str1 = Mid$(LastUnlockNumber, 4, 2)
str2 = Mid$(LastUnlockNumber, 8, 2)
intNum = str1 & str2
intNum = intNum + 1
strNewUnlock = "yjk" & Left$(CStr(intNum), 2) & "kg" & Right$(CStr(intNum), 2) & "dky"
Debug.Print "Input: " & LastUnlockNumber & " output: " & strNewUnlock
End Function
ASKER
I did this
OutPutRegistractionNumbers ("yjk500kg10dky")
got a type mismatch on this line:
intNum = str1 & str2
Am i doing something wrong?
OutPutRegistractionNumbers
got a type mismatch on this line:
intNum = str1 & str2
Am i doing something wrong?
ASKER
I see i did this too high 500
valid numbers 5000 to 99100
sb yjk50kg001dky the number would be 5001
valid numbers 5000 to 99100
sb yjk50kg001dky the number would be 5001
When you said "I want to give them a list of 100 valid numbers are between 5000 and 9900" was that correct or is it 5000 to 99100"?
ASKER
5000 and 9900
ASKER
sb
low number yjk50kg01dky = 5001
to
high number yjk51kg00dky= 5100
low number yjk50kg01dky = 5001
to
high number yjk51kg00dky= 5100
ASKER
I think i have to upload a hundred unlocking codes. When it gets less than 100 an someone makes a purchase I get a warning: "Low available licenses, please upload more
Each time a user buys the software they are given the first number on the list. I think the number is removed from the list so no 2 users get the same number
Each time a user buys the software they are given the first number on the list. I think the number is removed from the list so no 2 users get the same number
OK I'm confused but have I answered your original question? If not please tell me specifically what you need.
ASKER
Thanks martinliss, but i do see how that code outputs 100 numbers. do i put it into a loop or ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect, Thank you
You're welcome.
Open in new window