Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

Bit of a strange question I am having to do a routine to read in and update a serial number,
Read in as a string, send to board in question as a string. However the problem comes when adding 1 to increment it. If I use 1234567890 and use a Val to convert it to a number it works and I can add 1 to it and save it back out 1234567891. However the problem comes if it is 0000000000. This Val translates to 0 (because it is all 0's) if I add one to it, it is 1 with no leading 0's. I asked a similar question in relation to C# many moons ago and got a regex answer. A quick demo of what I am trying to do is below:
VB
Dim line As String = System.IO.File.ReadAllText("SerialNumber.ini.txt")
  TextBox1.Text = line

   Label1.Text = line
   SearchWithinThis = line
   MsgBox(SearchWithinThis)
   FirstCharacter = SearchWithinThis.IndexOf(SearchForThis)
   MsgBox(FirstCharacter)
   LineModded = line.Substring(FirstCharacter + 1, 10)
   LineModded += 1
   MsgBox(LineModded)

I am just afraid of what can go wrong!
Glenn
Posted
Comments
[no name] 10-Apr-14 7:33am    
Have you tried String.PadLeft?
glennPattonWork3 10-Apr-14 7:36am    
No, but am About to....
CHill60 10-Apr-14 7:46am    
Sorry - didn't see your comment before I posted my solution
[no name] 10-Apr-14 7:51am    
Not a problem at all.

VB
Dim s1 As String = "000000000000"
Dim l As Long = Val(s1)
Debug.Print(l.ToString())
Dim s2 As String = (l + 1).ToString().PadLeft(11, "0")
Debug.Print(s2)

gives output
0
00000000001
 
Share this answer
 
Comments
glennPattonWork3 10-Apr-14 7:49am    
No Worries I am working on this problem and another (and thinking about lunch!)
one line.
VB
LineModded = (CInt(line) + 1).ToString("0000000000")
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900