|
-
Nov 26th, 2008, 09:55 PM
#1
Thread Starter
PowerPoster
[RESOLVED] Best way to increment numbers containing a string
I am creating invoice, contract numbers etc to an ini file. When opening, increase the number number by 1.
Like PO1000
Inv1000
Chg1000
what would be the easiest way to do this?
The letters will always be on the left part of the string
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Nov 26th, 2008, 09:59 PM
#2
Re: Best way to increment numbers containing a string
What is the expected (agreed) range of numbers top be used?
For example: 0000 to 1000, or 1000 to 9999999
-
Nov 26th, 2008, 10:14 PM
#3
Thread Starter
PowerPoster
Re: Best way to increment numbers containing a string
 Originally Posted by Bruce Fox
What is the expected (agreed) range of numbers top be used?
For example: 0000 to 1000, or 1000 to 9999999
They are going to start at 1,000 and not go past 100,000
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Nov 26th, 2008, 11:21 PM
#4
Thread Starter
PowerPoster
Re: Best way to increment numbers containing a string
Thanks i got it
Private Function OnlyNumbers(ByVal Data As String) As String
Dim I As Integer
For I = 1 To Len(Data)
If InStr("0123456789,", Mid(Data, I, 1)) > 0 Then
OnlyNumbers = OnlyNumbers & Mid(Data, I, 1)
End If
Next
End Function
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Nov 26th, 2008, 11:46 PM
#5
Re: [RESOLVED] Best way to increment numbers containing a string
 Originally Posted by isnoend07
I am creating invoice, contract numbers etc to an ini file. When opening, increase the number number by 1.
Like PO1000
Inv1000
Chg1000
what would be the easiest way to do this?
The letters will always be on the left part of the string
Well, I don't know if this is the best way but it is one way. Create a text file in the VB98 dir and type 1000 in it before saving it. The Invoice number will increment by 1 each time you run this app.
Code:
Option Explicit
Private Sub Form_Load()
Dim lngInvNum As Long
Dim strInvNum As String
Open "MyInvNum.txt" For Input As #1
Input #1, lngInvNum
lngInvNum = lngInvNum + 1
strInvNum = "Invoice " & lngInvNum
Label1.Caption = strInvNum ' Display the Invoice number
Close #1
Open "MyInvNum.txt" For Output As #1
Print #1, lngInvNum ' Store the new number
Close #1
End Sub
Last edited by CDRIVE; Nov 26th, 2008 at 11:49 PM.
Reason: change Integer to Long
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Nov 27th, 2008, 01:07 AM
#6
Re: [RESOLVED] Best way to increment numbers containing a string
I have a suspicion that I misunderstood the question. Sorry!
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Nov 27th, 2008, 01:11 AM
#7
Thread Starter
PowerPoster
Re: [RESOLVED] Best way to increment numbers containing a string
 Originally Posted by CDRIVE
I have a suspicion that I misunderstood the question. Sorry!
No prob, i got it handled, thanks
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Nov 27th, 2008, 02:42 AM
#8
Re: Best way to increment numbers containing a string
 Originally Posted by isnoend07
Thanks i got it
Private Function OnlyNumbers(ByVal Data As String) As String
Dim I As Integer
For I = 1 To Len(Data)
If InStr("0123456789,", Mid(Data, I, 1)) > 0 Then
OnlyNumbers = OnlyNumbers & Mid(Data, I, 1)
End If
Next
End Function
For what it's worth, that is inefficent.
You know that at least the last 6 locations could be numbers, so account for that in the loop so you are not iterating past each and every location.
One way would be to start the loop 6 positions back into the string (as the max will be 6 digits, with 4 being the minimum).
Another way with a short loop (two times) would be to take the last six positions (could all be numbers, OR may contain at max two characters) and loop past those two left locations and check for numericy.
(IsNumeric)
And another, to extract the text and numbers, start the loop from the left until you IsNumeric, then use that position to extract the Right$() (maybe Mid())portion and Left$() to get the textual component << more than likely the faster of the three.
Last edited by Bruce Fox; Nov 27th, 2008 at 02:52 AM.
-
Nov 27th, 2008, 10:59 AM
#9
Thread Starter
PowerPoster
Re: Best way to increment numbers containing a string
 Originally Posted by Bruce Fox
For what it's worth, that is inefficent.
You know that at least the last 6 locations could be numbers, so account for that in the loop so you are not iterating past each and every location.
One way would be to start the loop 6 positions back into the string (as the max will be 6 digits, with 4 being the minimum).
Another way with a short loop (two times) would be to take the last six positions (could all be numbers, OR may contain at max two characters) and loop past those two left locations and check for numericy.
(IsNumeric)
And another, to extract the text and numbers, start the loop from the left until you IsNumeric, then use that position to extract the Right$() (maybe Mid())portion and Left$() to get the textual component << more than likely the faster of the three.
Thanks for your reply. Actually I have found I don't need to do anything to the string as the letters are for display only.
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Nov 27th, 2008, 02:53 PM
#10
Re: [RESOLVED] Best way to increment numbers containing a string
Why don't you simply save a line with just the number and then append that to PO, Inv, Chg as you need?
-
Nov 27th, 2008, 03:44 PM
#11
Re: [RESOLVED] Best way to increment numbers containing a string
NO Loop Option
Actually, if you did have the combination, using InStr() for the first occurance of an integer would do. Using that position (+1) you could extract from there til the end and you would have the Numbers - NO loops required in this case.
Anyway glad it's working the way you need
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|