Results 1 to 4 of 4

Thread: [RESOLVED] [2005] What happened to string() in vb.net?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    30

    Resolved [RESOLVED] [2005] What happened to string() in vb.net?

    Here I am trying to take an input number value by a user and add X number of preceeding 0's to it to make it have a total of 9 digits.

    They input "37" then I want: 000000037
    They input "4050" then I want: 000004050

    (They will never enter more than 4 digits, sort of besides the point)

    I recall using the old string() function in vb6 where I would whip up something like:

    new_string$ = string(9 - len(uservalue), "0") & uservalue

    (man, those were the days!)

    How can I do the equivalent in vb.net without ugly if statements or recursive code? It seems the string() function is gone, right?

    Thank you guys as always!

    -Josh

  2. #2
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2005] What happened to string() in vb.net?

    Try this
    VB Code:
    1. Dim ss As String
    2.         ss = Format(4512, "000000000")

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    30

    Re: [2005] What happened to string() in vb.net?

    Great!

    I use the format function all the time and dummy me never even thought of or realized that! Kudos to you and thank you for your time!

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [RESOLVED] [2005] What happened to string() in vb.net?

    VB Code:
    1. Dim MyNumber As Integer = 4050
    2.         MessageBox.Show(MyNumber.ToString.PadLeft(9, "0"))

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width