Solved

Increase Numbers containing letters.

Posted on 2014-07-25
18
129 Views
Last Modified: 2014-07-25
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 ?
0
Comment
Question by:isnoend2001
  • 10
  • 8
18 Comments
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40220580
    Dim str1 As String
    Dim str2 As String
    Dim str3 As String
    Dim str4 As String
    Dim str5 As String
    Dim intNum As Integer
    Dim strNewUnlock As String
    
    
    str1 = Left$(LastUnlockNumber, 2)
    str2 = Mid$(LastUnlockNumber, 4, 2)
    str3 = Mid$(LastUnlockNumber, 6, 2)
    str4 = Mid$(LastUnlockNumber, 8, 2)
    str5 = Right$(LastUnlockNumber, 2)
    
    intNum = str2 & str4
    intNum = intNum + 1
    
    strNewUnlock = str1 & Left$(CStr(intNum), 2) & str3 & Right$(CStr(intNum), 2) & str5

Open in new window

0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40220584
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"

Open in new window

0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40220589
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"

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:isnoend2001
ID: 40220605
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 ?
0
 

Author Comment

by:isnoend2001
ID: 40220617
what is this variable LastUnlockNumber ?
0
 

Author Comment

by:isnoend2001
ID: 40220649
Martin I used your code to write this sub:

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

Open in new window

but the debug showed :
yjk50kg02dky
yjk50kg02dky sb yjk50kg03dky
yjk50kg02dky sb yjk50kg04dky

increase to 100
last number(100) sb yjk51kg00dk
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40220816
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

Sub test()
OutPutRegistractionNumbers "yjk50kg01dky"
OutPutRegistractionNumbers "yjk50kg55dky"
OutPutRegistractionNumbers "yjk50kg99dky"
End Sub

Open in new window

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

Open in new window

0
 

Author Comment

by:isnoend2001
ID: 40220831
I did this
OutPutRegistractionNumbers ("yjk500kg10dky")
got a type mismatch on this line:
 intNum = str1 & str2
Am i doing something wrong?
0
 

Author Comment

by:isnoend2001
ID: 40220837
I see i did this too high 500
valid numbers 5000 to 99100
sb yjk50kg001dky the number would be 5001
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40220854
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"?
0
 

Author Comment

by:isnoend2001
ID: 40220861
5000 and 9900
0
 

Author Comment

by:isnoend2001
ID: 40220869
sb
 low number yjk50kg01dky = 5001
to
high number yjk51kg00dky= 5100
0
 

Author Comment

by:isnoend2001
ID: 40220871
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
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40220880
OK I'm confused but have I answered your original question? If not please tell me specifically what you need.
0
 

Author Comment

by:isnoend2001
ID: 40220891
Thanks martinliss, but i do see how that code outputs 100 numbers. do i put it into a loop or ?
0
 
LVL 47

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40220943
OK given a starting value, this will print out the next 100.

Sub test()
OutPutRegistractionNumbers "yjk50kg01dky"

End Sub

Open in new window

Public Sub OutPutRegistractionNumbers(strStartingValue)
Dim i As Integer
 Dim str1 As String
 Dim intNum As Long
    Dim str2 As String
    Dim strNewUnlock As String
    Dim lngIndex As Long
    
    str1 = Mid$(strStartingValue, 4, 2)
    str2 = Mid$(strStartingValue, 8, 2)
    
    intNum = str1 & str2
    
    For lngIndex = 1 To 100
        intNum = intNum + 1
        Debug.Print "yjk" & Left$(CStr(intNum), 2) & "kg" & Right$(CStr(intNum), 2) & "dky"
    Next
    
End Sub

Open in new window

0
 

Author Closing Comment

by:isnoend2001
ID: 40220951
Perfect, Thank you
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40220960
You're welcome.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
vb6 connector to SQL Server 2 41
Copy a row 12 68
vb6 connector to mongodb 2 138
VBA - Excel, Hide/unhide range of rows on sheet with listbox selection 9 95
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question