-
Str function in VB
Hi,
I'm a beginner in VB. I tried to change an integer to string using str as below
Dim z As Integer
Dim s As String
z = 100
s = Str(z)
Combo2.AddItem (s)
when 100 is converted to string there is a space added in the start of the string.
it is " 100" instead of 100. Please let me know if there are any other functions for changing integer 100 to "100"
Regards,
Carol.
-
Re: Str function in VB
-
Re: Str function in VB
I believe this is the correct syntax:
Dim z As Integer
Dim s As String
z = 100
s = CStr(z)
-
Re: Str function in VB
Right.
The str() function takes in account that there might be a negative number, preceded by a '-'. Str() precedes positive numbers with a blank and will thus result in equal length strings to positive and negative numbers. (Str(-100) has the same length as str(100))