Page 1 of 1

Input/Print

Posted: Mon Mar 24, 2008 10:47 pm
by rolstra
Hi everybody,
I am an absolute beginner - so far. What I did not find out in studying the manual: How can I INPUT numeric data and how can I PRINT numeric data. The INPUT/PRINT statements so far seem to be only for string data. E.g. I want to:

INPUT number1
INPUT number2
x = number1 + number2
PRINT x

How does this work with purebasic?
Thank you,
Roland

Posted: Mon Mar 24, 2008 11:25 pm
by Demivec

Code: Select all

number1 = Val(InputRequester("First Number", "Please make your input:", "")) ;INPUT number1
number2 = Val(InputRequester("Second Number", "Please make your input:", "")) ;INPUT number2
x = number1 + number2
MessageRequester("Sum",Str(x)) ;PRINT x
Here is one method to accomplish what you require using Requesters, one for input one for output. They deal only with strings, so numbers have to be converted both ways.

Another method involves console output (a text only screen). This method is the one you referred to with Input and Print. Use a method similar to the one I demonstrated to do the conversions betwen numbers and text.

Another method involves a GUI (graphic user interface) using gadgets for input and displaying the results.

I hope this helps.

Posted: Tue Mar 25, 2008 12:57 am
by pdwyer
Disclaimer, typed into the browser without checking for spelling or stupid mistakes

Code: Select all


OpenConsole()

    Num1.s = Input()
    Num2.s = Input()
    x.l = Val(Num1) + Val(Num2)

    PrintN(Str(x))
    Input()   ; give you a chance to see the output before the console screen vanishes


CloseConsole()


Posted: Tue Mar 25, 2008 8:38 am
by rolstra
Thank you very much,
that was exactly what I wanted to know.
Roland.

Posted: Tue Mar 25, 2008 9:37 am
by Baldrick
Rolstra,
If you are a complete beginner as you say, I would recommend for you to have a look at a site which has been put up by 1 of the forum users here ( blueznl ) which I think will probably help you a lot.
http://www.xs4all.nl/~bluez/datatalk/purebasic.htm