Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

integer to string

Status
Not open for further replies.

mingo7707

Programmer
Jun 4, 2002
5
US
how do you take an integer, say no%, and put it in a string variable, say no$, for example.

Thanks a lot,
Steve
 
Use this:

No$ = Str$(No%)

The Str$ function is good for doing this, but it leaves a leading space. You need to nest the Str$ inside the Ltrim$ function. Your resulting code will look like:

No$ = LTrim$(Str$(No%))

There is also a RTrim$ function for removing trailing spaces, but it is not needed for this example.
 
Nyaj2k1 supposed you wanted to have an user readable number, his solution does that.
However if you want to store the number as a string you can use
no$=mki$(no%)

It makes a string of the same size of the integer variable
and simply copies the bits of the variable into it.
There are different functions depending of the tipe of the variable mkl$ for longs, mkS$ for single, mkd$ for doubles Antoni
 
If you use agual's solution, in order to make it usable as a number again, you must convert it back. cvi for int,cvl for longs, cvd for doubles.

no% = cvi(no$)

Using this type of string is commonly used for storing numbers in a random acess file. David Paulson

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top