| View previous topic :: View next topic |
| Author |
Message |
-Negative- Expert Cheater
Reputation: 0
Joined: 12 Oct 2007 Posts: 142
|
Posted: Fri Jun 13, 2008 7:14 pm Post subject: [vb.net] help\question |
|
|
how to set anything value to - 0001, its fakin doing me 1. how to make something value 0001
IMPORTANT
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Fri Jun 13, 2008 8:16 pm Post subject: |
|
|
You cannot make the value 0001 but you can make the string to display the number 0001
do something like (pseudo C#)
| Code: | if ( num == 0 ) { String s = "0000"; }
else if ( num < 10 ) { String s = "000" + Convert.ToString(num); }
else if ( num < 100 ) { String s = "00" + Convert.ToString(num); }
else if ( num < 1000 ) { String s = "0" + Convert.ToString(num); }
else { String s = Convert.ToString(num); } |
_________________
|
|
| Back to top |
|
 |
-Negative- Expert Cheater
Reputation: 0
Joined: 12 Oct 2007 Posts: 142
|
Posted: Fri Jun 13, 2008 10:14 pm Post subject: |
|
|
| useless =\
|
|
| Back to top |
|
 |
Estx Expert Cheater
Reputation: 0
Joined: 04 Mar 2008 Posts: 172
|
Posted: Sat Jun 14, 2008 1:43 am Post subject: |
|
|
If you want it as a string: Integer.ToString("0000")
E.g.
| Code: | Dim tInt As Integer
tInt.ToString("0000") |
or
| Code: | | (10).ToString("0000") |
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Sat Jun 14, 2008 1:47 am Post subject: |
|
|
You could always do (C#):
| Code: | | string sNumber = iNumber.ToString().PadLeft(4, '0'); |
The first parameter is the total number of chars, and the second parameter is the padding character.
_________________
|
|
| Back to top |
|
 |
Estx Expert Cheater
Reputation: 0
Joined: 04 Mar 2008 Posts: 172
|
Posted: Sat Jun 14, 2008 2:13 am Post subject: |
|
|
| samuri25404 wrote: | You could always do (C#):
| Code: | | string sNumber = iNumber.ToString().PadLeft(4, '0'); |
The first parameter is the total number of chars, and the second parameter is the padding character. |
Never thought of that, unique. Good idea, but probably better just to perform the padding in the format provider string as I suggested. Mind you, it's really just coding preference in that matter. No performance or rendering difference.
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Sat Jun 14, 2008 2:31 am Post subject: |
|
|
Yeah, I learned that early, when my dad showed me some string manipulation stuff (like Trim, Pad, etc.. you can find all that with "myString." and the intellisense will pick it up). I usually don't like to mess around with the formatting, but it's useful with Hexadecimal.
_________________
|
|
| Back to top |
|
 |
|