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
Printable View
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
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,000Quote:
Originally Posted by Bruce Fox
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
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.Quote:
Originally Posted by isnoend07
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
I have a suspicion that I misunderstood the question. Sorry!
No prob, i got it handled, thanksQuote:
Originally Posted by CDRIVE
For what it's worth, that is inefficent.Quote:
Originally Posted by isnoend07
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.Quote:
Originally Posted by Bruce Fox
Why don't you simply save a line with just the number and then append that to PO, Inv, Chg as you need?
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 :)