VB Math

slydir

Newcomer
Joined
Sep 16, 2003
Messages
5
I have a question on how to return precision values when doing math functions in vb.
Is there anyway to make vb return a value of 00000001 when subtracting 33554432 from 33554433? I always get a return of just 1.
The way the database is designed to track data is by an 8 digit varchar even if they are all 0's. (Oh yeah this gets converted from integer to varchar b4 getting inserted into the db)
This app is not the only app that accesses the db so I need the two apps to match up. The other app already does this, but no source is available.:(
Thanks in advance for any help
 
This should work:
Visual Basic:
Public Function Get8DigitString(Byval Num as Integer) As String
If Num.ToString().Length < 8 Then
     Return New String("0"c, 8 - Num.ToString().Length) & Num.ToString()
Else
     Return Num.ToString()
End If
End Function
I might have heard of another method using a native .Net function but I don't remember.
 
You rock! That was quick and painless. Better than my hacked if...else statements. Thanks for the help.
 
Wouldn't this be simplier?:

Visual Basic:
Public Function Get8DigitString(ByVal Num As Integer) As String
     Get8DigitString = Format(Num,"00000000")
End Function
 
Back
Top