Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

creating strings from numbers

creating strings from numbers

creating strings from numbers

I have been tasked with creating a barcode from numbers.An example element is qty where a qty of 5 should read 005 within the string.
My cunning plan was to add 1000 to the qty, export to csv as string, then reimport, 'somehow' trimming off the leading 1. But I am tying myself in knots here.
Am I pointing the right way? Is there an easier way of converting numbers to strings? Does anybody out there have experience of this kind of thing?

RE: creating strings from numbers

I don't know if this will do exactly what you want, but it might make a good starting point. In this example I'm assuming that you are storing the string representation of the number in a table along with the number. So in the this example I have a table with two columns. One is called "Number" and the other "String."

The script below will go through the table from top to bottom (via Scan) using a tCursor. The number will be converted to a long integer (in case the numbers exceeds 32,767) and then using a for next loop determines how many zeros to place in front of the number. The converted number is then placed in the "String" field without any numerical punctuation.


     tc       tCursor
   scan tc:
       tc."String" = string(LongInt(tc."Number"))
        for i from 1 to (10 - size(tc."String"))
            tc."String" = "0" + tc."String"

I named the table BTest.db. It consists of two fields, "Number" and "String." I open the table, put it in an edit state, and then start a Scan which will execute all the code below "Scan" from the top down.

I then covert the number to long-integer and then string. I then execute a for loop with an upper limit of ten minus the length of the string field. This way I always get the appropriate number of zeros at the beginning of the string such that the total string length is ten characters.

The for loop concludes when that upper limit is reached and the Scan statement moves to the next record.

Hope this helps.

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886

RE: creating strings from numbers

Fill() will also work nicely


    convertedStr string
    len, n number

len = 3
n = [number field]
convertedStr = fill("0", len - n.size()) + string(n))

You will also have to add the appropriate start and termination chracters to the string before converting it to a barcode.


RE: creating strings from numbers

Oops n should have been a longint

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close