Results 1 to 5 of 5

Thread: [RESOLVED] Barcode Issue?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2012
    Location
    I'm living in VBForum bcz its members deserve respect and appreciation
    Posts
    333

    Resolved [RESOLVED] Barcode Issue?

    Hi everyone. I have a barcode scan thing. Anyway, my question is how can we remove or add the zero's in a barcode. In my case I have barcode read two different way as:
    1- 1234
    2- 001234
    ---> all I need is the "01234"
    Can anyone help me how to omit the zero or add it if when barcode read that way?... please any advice would be appreciated.

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: Barcode Issue?

    Convert the data to a number then use the format() function to output the number in the format you wish, or convert to a number then back to a string and check the length of the new string if less than 5 add the required number of 0s to the left, or check the length of the string from the scan if greater than five drop the first digit(s) to get the required length



    This is assuming that you want a 5 character result which is left padded with 0s. If that is not what you are looking for then explain in more detail

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2012
    Location
    I'm living in VBForum bcz its members deserve respect and appreciation
    Posts
    333

    Re: Barcode Issue?

    convert to a number then back to a string and check the length of the new string if less than 5 add the required number of 0s to the left.
    Yes correct that's what i'm looking for. i use replace but it's omit all zero.

  4. #4
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: Barcode Issue?

    As DM says
    Let's say that the value is 1234 or 001234

    1.-
    Store the value in a string variable, let's say MyStr
    Convert to numeric
    Dim X As Integer
    X = CInt(MyStr)
    Then convert to desired output using Format
    MyStr = Format(X, "00000")

    Or
    2.-
    Store the value in a string variable, let's say MyStr
    Then if length equal to 4 then add one 0
    If Len(MyStr) = 4 Then MyStr = "0" & MyStr
    If the length is equal to 5 then cut first 0
    If Len(MyStr) = 5 Then MyStr = Mid(MyStr,2)
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: [RESOLVED] Barcode Issue?

    Another option that could be done with just one line would be to add 0s at the begining then take the right 5 characters
    Code:
    MyStr=Right$("00000" & BarcodeValue,5)

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