Qbasicnews.com
Appending a number to an Existing number - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html)
+--- Forum: QB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-11.html)
+--- Thread: Appending a number to an Existing number (/thread-707.html)

Pages: 1 2 3


Appending a number to an Existing number - tmooney - 04-26-2003

Hi, I am just learning QBasic. Is there a way to do this?
Let's say I have the number 5378 and I want to append the number 1 to the end 5378 without any spaces. Can this be done.
For Example

Number.......Append.............New Number
5378..............1 .......................53781

By the way these numbers are not strings, they are numeric.
I tried doing PRINT 5378;1 but this results in 5378 1. I do not want a space in between the 8 and the 1.
:roll:


Appending a number to an Existing number - Agamemnus - 04-26-2003

It cannot be done without a string unless you do
PRINT 5378# * 10 + 1

otherwise,
PRINT val(ltrim$(str$(5378))+ltrim$(str$(1)))

str makes the number a string and adds a space in front of it.
ltrim removes the space.
val makes the string a number.


Appending a number to an Existing number - Ninkazu - 04-26-2003

I'd do this:
Code:
number = 5689
num$=LTRIM$(STR$(number))
num$=num$+"1"
number=val(num$)

That should work


mine is faster. - Agamemnus - 04-26-2003

...


I know you'll just love this one... - Glenn - 04-27-2003

A = 5378
B = 1
C = 10^CINT(LOG(B)/LOG(10)+.5001)
NEWNUMBER = A * C + B


Appending a number to an Existing number - tmooney - 04-27-2003

Thanks I'll try your suggestions. I am not in a hurry for it so I'll play with it a while until I'm bald again then I'll come back to beg for help. :rotfl:


Re: I know you'll just love this one... - wizardlife - 04-27-2003

Quote:A = 5378
B = 1
C = 10^CINT(LOG(B)/LOG(10)+.5001)
NEWNUMBER = A * C + B

retard.


Appending a number to an Existing number - tmooney - 04-27-2003

This Code was what I was looking for. Thanks so much. My brain must of been on overload because the answer was so simple.

[PRINT 5378# * 10 + 1]


Re: I know you'll just love this one... - Ninkazu - 04-27-2003

Quote:
Glenn Wrote:A = 5378
B = 1
C = 10^CINT(LOG(B)/LOG(10)+.5001)
NEWNUMBER = A * C + B

retard.

HAHAHAHAH


See? I knew you'd like it! - Glenn - 04-27-2003

Quote:
Glenn Wrote:A = 5378
B = 1
C = 10^CINT(LOG(B)/LOG(10)+.5001)
NEWNUMBER = A * C + B

retard.