Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2004
    Location
    South Africa
    Posts
    178

    Unanswered: dropping zeros from a textfield

    I have part numbers like the following
    TFG283201
    000YDH228
    0HDYWB2283
    etc.
    if the part number starts with a zero, I want it dropped.
    if the part number has more than one zero at the beginning, they must be dropped too.
    However if the zero appears between other characters or numbers, then it must stay where it is.
    How would i go about doing this?

  2. #2
    Join Date
    Aug 2003
    Posts
    106
    Dim myPart as String
    Dim myStop as Integer

    myStop = 0
    myPart = PartNumber

    Do
    If LEFT(myPart, 1) = "0" Then
    myPart = RIGHT(myPart, LEN(myPart)-1)
    Else: myStop = 1
    End If
    Loop Until myStop = 1

    'myPart = PartNumber minus any leading zeros!

    Good luck

    sugarflux

  3. #3
    Join Date
    Jan 2004
    Location
    South Africa
    Posts
    178
    Originally posted by sugarflux
    Dim myPart as String
    Dim myStop as Integer

    myStop = 0
    myPart = PartNumber

    Do
    If LEFT(myPart, 1) = "0" Then
    myPart = RIGHT(myPart, LEN(myPart)-1)
    Else: myStop = 1
    End If
    Loop Until myStop = 1

    'myPart = PartNumber minus any leading zeros!

    Good luck

    sugarflux
    excellent
    thank you

  4. #4
    Join Date
    Sep 2002
    Location
    South Wales
    Posts
    580

    Question Out of interest

    What happens if string starts as "0"?

    Does that cause any problems?
    Windows Server 2003-8 / Terminal Services / SQL 2000 / Access 2003 / Office 2003-7 / Exchange 2003-7 / Blackberry Enterprise Server / AutoCAD / Lambert And Butler / Red Bull

  5. #5
    Join Date
    Aug 2003
    Posts
    106
    No problems!

    All this code does is looks at the first letter of the string 'myPart' . If the first letter is a zero, it deletes it (or rather changes the word 'myPart' to every letter except the first letter).

    Hope this helps!
    sugarflux

  6. #6
    Join Date
    Sep 2002
    Location
    South Wales
    Posts
    580

    Talking Hinting

    I wast just hinting that if there was a possibility that the string
    started life as purely "0" (dont know if this is possible), you would end up
    with a zero length string, which may or may not cause problems elsewhere in the application.

    Just out of caution...
    Windows Server 2003-8 / Terminal Services / SQL 2000 / Access 2003 / Office 2003-7 / Exchange 2003-7 / Blackberry Enterprise Server / AutoCAD / Lambert And Butler / Red Bull

  7. #7
    Join Date
    Aug 2003
    Posts
    106
    Yes - too right!

    Sorry - completely missed that one

    So you would need a

    If Len(myPart) > 1 Then
    <All the code i wrote before>
    Else:

    End IF

Posting Permissions

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