"Michael Turner" <fi*****@m-turner.co.uk> wrote in message
news:O5**************@tk2msftngp13.phx.gbl...
i have a string value that contains a number this could look like
03843282922132 now the 0 at the beginning is the important bit
when using substring to get every three charachters it misses off the
first 0
It does no such thing! Follow your own code as it works its magic...
Dim m As String
m = TextBox3.Text
m now contains the String "03843282922132".
Dim x(m.Length) As Integer
NB: Integer *not* String!!
For i As Integer = 0 To m.Length - 1
x(i) = m.Substring(i, 3)
' e.g. x( 0 ) now holds the Integer 38
Debug.WriteLine(x(i))
Next
Each trio of digits is being "Evilly Type Coerced" from a String into
an Integer and, of course, Integers don't have leading zeroes - only
the String /representations/ of them do.
If you /want/ leading zeroes, keep them as Strings; if you want to
have numbers that you /display/ as Strings, do so, as in
For i As Integer = 0 To m.Length - 1
x( i ) = CInt( m.Substring( i, 3 ) )
Debug.WriteLine( x( i ).ToString( "000" ) )
Next
BTW, please, please *please*, put
Option Strict On
at the top of your source file (or set it in the default project settings).
I cannot recommend its use strongly enough.
It /will/ break a lot of your code but, by the time you've fixed them
all, you'll understand type conversion much, /much/ better.
HTH,
Phill W.