Solved

Textbox number format

Posted on 2004-10-21
223 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
Question by:teamdad
    6 Comments
     
    LVL 15

    Accepted Solution

    by:
    Change

    intValue.ToString

    to

    intValue.ToString("00")
    0
     
    LVL 10

    Expert Comment

    by:james-ct16
    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
    hi
    looks like timbo jumped in with a neater anser as i was writing mine

    james
    0
     

    Author Comment

    by:teamdad
    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
    Did you replace all occurences? It should change all of them since you're using a for each loop.
    0
     

    Author Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    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…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    This video Micro Tutorial is the second in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 (http://www.experts-exchange.com/articles/17490/). But the ability to create custom scanning profiles a…

    857 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now