Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
string and numeric variable questions
#1
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$
Reply
#2
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.
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#3
STR$() Adds spaces to both the left *and* right. The one to the left holds the negative sign if needed.
Reply
#4
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.
*****
Reply
#5
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"
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#6
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$)
Reply
#7
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.'
Reply
#8
Thanks fella's. I appreciate it, and I am sure there will be more questions to follow.
Reply
#9
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 Wink
I'd knock on wood, but my desk is particle board.
Reply
#10
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...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)