|
-
Jul 16th, 2007, 12:33 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [2005] format question
why I set the format to 0000, but it doesn't work?
here is my code
Code:
Dim loud As Integer
loud = TextBox1.Text
loud = Format(loud, "0000")
console.writeln(loud)
if my textbox1 is 0123, it just show me 123...
-
Jul 16th, 2007, 12:37 PM
#2
Re: [2005] format question
Code:
Dim loud As Integer
If Integer.TryParse(TextBox1.Text, loud) Then
Debug.WriteLine(loud.ToString("0000"))
Else
Debug.WriteLine("Invalid number")
End If
-
Jul 16th, 2007, 12:41 PM
#3
Thread Starter
Hyperactive Member
Re: [2005] format question
so, is that right?
loud = loud.tostring("0000")
-
Jul 16th, 2007, 12:43 PM
#4
Fanatic Member
-
Jul 16th, 2007, 12:52 PM
#5
Re: [2005] format question
 Originally Posted by newpat
so, is that right?
loud = loud.tostring("0000")
stanav gave you the solution you were asking for. Did you give it a shot?
In addition, here is some more on formatting:
http://msdn2.microsoft.com/en-us/lib...sy(VS.80).aspx
-
Jul 16th, 2007, 01:00 PM
#6
Thread Starter
Hyperactive Member
Re: [2005] format question
 Originally Posted by stanav
Code:
Dim loud As Integer
If Integer.TryParse(TextBox1.Text, loud) Then
Debug.WriteLine(loud.ToString("0000"))
Else
Debug.WriteLine("Invalid number")
End If
but how can I save the 0123 to loud?
I tried, although it come out with "0123", I dun know how can I save it to loud.
-
Jul 16th, 2007, 01:05 PM
#7
Re: [2005] format question
Integers do not have leading zeros. Save it to a string variable if you must have the leading zero.
vb.net Code:
' loud
Dim loud As Integer = 123
Dim str As String = loud.ToString("0000")
MessageBox.Show(str)
-
Jul 16th, 2007, 01:13 PM
#8
Re: [2005] format question
 Originally Posted by newpat
so, is that right?
loud = loud.tostring("0000")
No, that's not what I meant....
What you have displayed on screen is just a string representation of the integer value. And you can not format an integer itself but rather its string representation. That's why you have to to convert the integer to string and then format that string.
-
Jul 17th, 2007, 12:32 AM
#9
Thread Starter
Hyperactive Member
Re: [2005] format question
ok then...My integer is to compare with another integer...
However, I have found out another way to do my expection.
Thx for all!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|