Still need help with formatting numbers, any1?

Can anyone help pls
Basically what i got is a textbox which max length is 6.
If i enter say 123456 to the textbox and save to file, then its saves 123456 thats no problem.

My Probem:
If i dont enter any numbers then save to file, i want it 2 save 000000, or if i only enter say 123, then i need it to save 000123, or if i enter say 6 then i need the file to save it as 000006

Can anyone help?
Thanx Gary

Comments

  • copy paste this ....

    Function FillZeros(ByVal myNum As String, _
    ByVal WantedLength As Integer) As String
    Dim i, Rest As Integer
    Rest = WantedLength - myNum.Length
    For i = 0 To Rest
    myNum = "0" & myNum
    Next
    Return myNum
    End Function

    call this ... > myString = FillZeros("123", 6)

    myNum is the value you want to change eg 123
    WantedLength is the MaxLength


  • : Can anyone help pls
    : Basically what i got is a textbox which max length is 6.
    : If i enter say 123456 to the textbox and save to file, then its saves 123456 thats no problem.
    :
    : My Probem:
    : If i dont enter any numbers then save to file, i want it 2 save 000000, or if i only enter say 123, then i need it to save 000123, or if i enter say 6 then i need the file to save it as 000006
    :
    : Can anyone help?
    : Thanx Gary
    :
    :

    You can also do it this way as well ...

    [code]
    Dim num As String = "123"

    MessageBox.Show(num.PadLeft(6, "0"c))
    [/code]

    This will display "000123" in a message box

    If you do this ...

    [code]
    Dim num As String = ""

    MessageBox.Show(num.PadLeft(6, "0"c))
    [/code]

    It will display "000000" in a message box

  • thanx i'll give it a go

    : copy paste this ....
    :
    : Function FillZeros(ByVal myNum As String, _
    : ByVal WantedLength As Integer) As String
    : Dim i, Rest As Integer
    : Rest = WantedLength - myNum.Length
    : For i = 0 To Rest
    : myNum = "0" & myNum
    : Next
    : Return myNum
    : End Function
    :
    : call this ... > myString = FillZeros("123", 6)
    :
    : myNum is the value you want to change eg 123
    : WantedLength is the MaxLength
    :
    :
    :

  • : : Can anyone help pls
    : : Basically what i got is a textbox which max length is 6.
    : : If i enter say 123456 to the textbox and save to file, then its saves 123456 thats no problem.
    : :
    : : My Probem:
    : : If i dont enter any numbers then save to file, i want it 2 save 000000, or if i only enter say 123, then i need it to save 000123, or if i enter say 6 then i need the file to save it as 000006
    : :
    : : Can anyone help?
    : : Thanx Gary
    : :
    : :
    :
    : You can also do it this way as well ...
    :
    : [code]
    : Dim num As String = "123"
    :
    : MessageBox.Show(num.PadLeft(6, "0"c))
    : [/code]
    :
    : This will display "000123" in a message box
    :
    : If you do this ...
    :
    : [code]
    : Dim num As String = ""
    :
    : MessageBox.Show(num.PadLeft(6, "0"c))
    : [/code]
    :
    : It will display "000000" in a message box
    :
    : Thanx that was a great help, i can get on with it now
    Dynamo

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories