Hi.
I need to convert this BBC BASIC lines in SuperBASIC....
LET E=10
LET TIME=50
PRINT "Line:"+STR$(E)+" X "+STR$(TIME)
I would like to obtain this output="Line:10 X 50"
HELP!
String + Numbers .... help!
Re: String + Numbers .... help!
That's actually pretty simple in SuperBASIC:genetika wrote:Hi.
I need to convert this BBC BASIC lines in SuperBASIC....
LET E=10
LET TIME=50
PRINT "Line:"+STR$(E)+" X "+STR$(TIME)
I would like to obtain this output="Line:10 X 50"
HELP!
Code: Select all
PRINT "Line:" & E & " X " & TIME
Code: Select all
a$ = "10" : PRINT 1 + a$
ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
Re: String + Numbers .... help!
Actually, it is not so simple :
Let's try :
A = 60000000
PRINT#2,A
The QL will answer (on device #2) :
6E7
If you want him to print
60000000
you have to code this little procedure :
and tell the QL :
IP(2,8,A)
(2 is the number of the device on which you want the output, and 8 is the number of characters you want to print)
Coercion etc. is "nice", but it lets the QL do what he wants, not what you want.
POLKa
Let's try :
A = 60000000
PRINT#2,A
The QL will answer (on device #2) :
6E7
If you want him to print
60000000
you have to code this little procedure :
Code: Select all
1 DEFine PROCedure IP(device,precision,value)
2 f$=""
3 FOR i = 1 to precision
4 f$ = f$ & "#"
5 END FOR i
6 PRINT_USING#device,f$,value
7 END DEFine IP
IP(2,8,A)
(2 is the number of the device on which you want the output, and 8 is the number of characters you want to print)
Coercion etc. is "nice", but it lets the QL do what he wants, not what you want.
POLKa
Last edited by polka on Thu Apr 23, 2020 7:09 am, edited 1 time in total.
May the FORTH be with you !
POLKa
POLKa
Re: String + Numbers .... help!
Right - If you want to have control of the format, you can't use automagic coercion.
But I'm pretty sure the BBC Basic version above would have reverted to exponential notation as well - with such big numbers (The example doesn't seem to use numbers in that range)
Tobias
But I'm pretty sure the BBC Basic version above would have reverted to exponential notation as well - with such big numbers (The example doesn't seem to use numbers in that range)
Tobias
ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
Re: String + Numbers .... help!
I stumbled on this problem recently, as I was trying to code a simple model for an epidemy propagating in a population of 60000000. This number was too large for using QL integers (limited to 32767), and when using floats, the QL would not format the output to my will.
Of course, I should have programmed it in Forth, that has only integers but up to 32 bits ; but I was lazy
POLKa
Of course, I should have programmed it in Forth, that has only integers but up to 32 bits ; but I was lazy
POLKa
May the FORTH be with you !
POLKa
POLKa
- Giorgio Garabello
- Gold Card
- Posts: 277
- Joined: Tue Jun 30, 2015 8:39 am
- Location: Turin, Italy
- Contact:
Re: String + Numbers .... help!
Try this: https://superbasic-manual.readthedocs.i ... ht=fdec%24polka wrote:Actually, it is not so simple :
Let's try :
A = 60000000
PRINT#2,A
The QL will answer (on device #2) :
6E7
If you want him to print
60000000
you have to code this little procedure :
and tell the QL :Code: Select all
1 DEFine PROCedure IP(device,precision,value) 2 f$="" 3 FOR i = 1 to precision 4 f$ = f$ & "#" 5 END FOR i 6 PRINT_USING#device,f$,value 7 END DEFine IP
IP(2,8,A)
(2 is the number of the device on which you want the output, and 8 is the number of characters you want to print)
Coercion etc. is "nice", but it lets the QL do what he wants, not what you want.
POLKa
Quantum Technology
http://www.hunggartorino.it/ql/language/en/
http://www.hunggartorino.it/ql/language/en/