Windows Develop Bookmark and Share   
 index > Windows Forms Designer > displaying zero with single digit int
 

displaying zero with single digit int

HI

I am making a countdown application. Currently it display values like that
10,9,8,7,6 and so on.

But I want to display it like that

10,09,08,07,06 and so on

Regards
Adeel Arshad
Regards,Adeel Arshad
khushi83  Saturday, August 22, 2009 4:29 AM

Posting your code will help but here is a clue. Before displaying the numbers, check if their lenght is less than 2. If the lenght is less than two then add "0" to the number else display as is. Something like this (I did not test the code but it does provide you with the clue/logic to do what you're trying to do):

Dim myValue As String= CStr(myNumber)
'Numbers don't have lenght property so convert to string first

Dim displayValue As String 'This is the count down numbers to display

If myValue.Lenght > 2 Then
displayValue = "0" & myValue
 'Add 0 to the beginning of your number
Else

displayValue = myValue
End If

TextBoxDisplay.Text = displayValue

Only performance counts!
Sylva  Saturday, August 22, 2009 8:29 AM
Hello.

Try the following code it may fullfill ur purpose.
             string TempValue = "";
                for (int i = 10; i >= 1; i--)
                {
                    TempValue += i.ToString("00") + " ";
                }
                this.label1.Text = TempValue;
Good Luck.

Malik M.Shahid  Saturday, August 22, 2009 11:52 AM

Posting your code will help but here is a clue. Before displaying the numbers, check if their lenght is less than 2. If the lenght is less than two then add "0" to the number else display as is. Something like this (I did not test the code but it does provide you with the clue/logic to do what you're trying to do):

Dim myValue As String= CStr(myNumber)
'Numbers don't have lenght property so convert to string first

Dim displayValue As String 'This is the count down numbers to display

If myValue.Lenght > 2 Then
displayValue = "0" & myValue
 'Add 0 to the beginning of your number
Else

displayValue = myValue
End If

TextBoxDisplay.Text = displayValue

Only performance counts!
Sylva  Saturday, August 22, 2009 8:29 AM
Hello.

Try the following code it may fullfill ur purpose.
             string TempValue = "";
                for (int i = 10; i >= 1; i--)
                {
                    TempValue += i.ToString("00") + " ";
                }
                this.label1.Text = TempValue;
Good Luck.

Malik M.Shahid  Saturday, August 22, 2009 11:52 AM

You can use google to search for other answers

Custom Search

More Threads

• Loading a UserControl into a Panel on Form
• Where can I find image resource for 'start', 'pause', 'stop' button
• Help needed for WinForm Application
• Supporting 2003 & 2005 InitializeComponent
• How do I create a custom control that another form using it catches events?
• Controls in MDI form
• VS 2008 forms designer doesn't show controls
• Designer will not open after downloading new VB 2008
• Gah! The designer is filling in my properties for me!!
• Custom Scrolling