?
Solved

Textbox number format

Posted on 2004-10-21
6
Medium Priority
?
227 Views
Last Modified: 2010-04-23
How can I get the textbox to show double digit numbers for the numbers 0 thru 9 instead of single digit numbers?


' Build lists of values matching min and max occurrence
        leastOccurring = New SortedList()
        mostOccurring = New SortedList()
        For Each de In frequencies
            intValue = CType(de.Key, Integer)
            valueFrequency = CType(de.Value, Integer)
            If valueFrequency = minOccurrence Then
                leastOccurring.Add(intValue, intValue)
            End If
            If valueFrequency = maxOccurrence Then
                mostOccurring.Add(intValue, intValue)
            End If
        Next

        ' Display the results in textbox
        Dim OccurringValues As String
        For Each intValue In leastOccurring.Values
            If OccurringValues = "" Then
                OccurringValues = intValue.ToString
            Else
                OccurringValues = OccurringValues & " - " & intValue.ToString
            End If
        Next
        TextBox1.Text = (OccurringValues)

        OccurringValues = ""
        For Each intValue In mostOccurring.Values
            If OccurringValues = "" Then
                OccurringValues = intValue.ToString
            Else
                OccurringValues = OccurringValues & " - " & intValue.ToString
            End If
        Next
        TextBox2.Text = (OccurringValues)
    End Sub
0
Comment
Question by:teamdad
  • 2
  • 2
  • 2
6 Comments
 
LVL 15

Accepted Solution

by:
Timbo87 earned 2000 total points
ID: 12375314
Change

intValue.ToString

to

intValue.ToString("00")
0
 
LVL 10

Expert Comment

by:james-ct16
ID: 12375374
hi

there is a string format in the form of {**} that will do it but i end up spending ages looking it up everytime so i usually write meself a quick function to do it. find i can write it quicker than i cna look it up.

regards

james


code example follows
-------------------------

private function doubleDigit( byval val as interger) as string

if val <10 then
   return "0" & cstr(val)
else
   return cstr(val)
end if

end function

private function doubleDigit( byval val as string) as string

if val.length<2 then
  if va.length=0 then
     return "00"
  else
    return "0" & val
  end if
else
  return val
end if
end function
0
 
LVL 10

Expert Comment

by:james-ct16
ID: 12375395
hi
looks like timbo jumped in with a neater anser as i was writing mine

james
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 

Author Comment

by:teamdad
ID: 12375498
Using intValue.ToString("00") only changes the first number in my list of numbers.  It looks something like this: 01 - 2 - 3 - 4 but I need any numbers that are single digits to show as double digits.
0
 
LVL 15

Expert Comment

by:Timbo87
ID: 12375595
Did you replace all occurences? It should change all of them since you're using a for each loop.
0
 

Author Comment

by:teamdad
ID: 12375819
Apparently I need my glasses changed..... I left off one of the ) on one of them.  Works great now.
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…
Get the source code for a fully functional Access application shell with several popular security features that Access VBA application developers desire, but find difficult or impossible to figure out how to code. You get the source code for managi…
Suggested Courses

599 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question