Posts: 131
Threads: 32
Joined: Mar 2004
Can you or how can you let a string variable equal a numeric variable and vice versa.
for example
a$=num Where num is inputed
or
num = a$ the numeric of a$
Posts: 2,765
Threads: 138
Joined: Nov 2002
string$ = STR$(num)
num = VAL(string$)
there.
but the STR$ adds a space to the left (or right I forget) os if you want you need to LTRIM$ it.
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Posts: 292
Threads: 31
Joined: Apr 2003
STR$() Adds spaces to both the left *and* right. The one to the left holds the negative sign if needed.
Posts: 1,956
Threads: 65
Joined: Jun 2003
RST, I don't recall the string of a value having a space on the right end. As a matter of fact I just ran a test, and there is definitely no space on the right end.
*****
Posts: 2,765
Threads: 138
Joined: Nov 2002
yup Moneo is correct (((unless by some miraculous event i get killed and a temporal rift opens up that NO DUCT TAPE SHALL CLOSE!)))
Code:
PRINT "a" + STR$(1) + "a"
PRINT "a" + STR$(-1) + "a"
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Posts: 273
Threads: 51
Joined: May 2002
jgr: If you want to get rid of that extra space at the beginning, use LTRIM$(variable$). This function returns the string with any spaces removed starting from the left(RTRIM$ does it from the right). To use it, do this:
variable$ = LTRIM$(variable$)
Posts: 451
Threads: 16
Joined: Feb 2003
Or, you can use FORMAT$ to control how the string is generated from the number.
ie:
Code:
PRINT FORMAT$(12345)
PRINT FORMAT$(12345, "##,###")
Life is like a box of chocolates', hrm, WTF, no it isn't, more like, 'life is like a steaming pile of horse crap.'
Posts: 131
Threads: 32
Joined: Mar 2004
Thanks fella's. I appreciate it, and I am sure there will be more questions to follow.
Posts: 3,279
Threads: 170
Joined: Nov 2003
For QB, I usually just say "screwit" and use something like this:
string$ = LTRIM$(RTRIM$(STR$(num)))
Old habits die hard I suppose...but there was a time when spaces appeared on both sides. Maybe it's not with integers, maybe it's with singles and doubles? Anyone want to confirm?
For VB, we get to use something like this:
string$ = Trim(Str(num))
so much easier
I'd knock on wood, but my desk is particle board.
Posts: 3,343
Threads: 83
Joined: Mar 2003
A space appears when you're converting a positive number to a string, the space is the reserved space for the "-" sign that never appeared.
And you could do this:
Code:
DEF FNtrim(strng$) = LTRIM$(RTRIM$(strng$))
^^ not sure on the syntax of DEF FN but that's the basis of how I'd make a TRIM$ function...