PDA

View Full Version : Showing (canvas_print) the value of a string



MattW
05-02-2013, 12:52
Hi,

Just a quick question. I'm trying to display on screen the contents of a string.
In QBasic it would be written:

A$="hello"
B$="goodbye"
print A$+" "+B$

(shows "hello goodbye")

I imagine the following would be the TB method, but it's not working probably as I've written it incorrectly:

a as string
b as string
c="hello"
d="goodbye"
canvas_print c
canvas_print c+" "+d (???)


I'm still trying to remember that a variable is defined as numeric or string via DECLARING IT FIRST. i.e. 'a' can be a string or numeric. In QBasic the dollar$ defines a "string".

Also, I'm not sure if maybe I could get this information during program execution? Again, sorry to keep refering to QB, but you could do CNTRL-BREAK to stop program execution, then F6 for the "immediate" section and do "print a$" and the results would be shown. Then F5 to continue program execution. I've read up that this can be done in TB?

Thanks for your help!

Matt

ErosOlmi
05-02-2013, 19:56
Hi Matt,

Canvas is a GUI control present in UI module not so easy to master at first.
But looking at your QB code it seems you just need to print in Console Window so I start from there.
Here a few line of letting you start:

Uses "console"

'---Different ways to define the same variable. The second is more easy
'Dim A as string = "hello"
'String A = "hello"


String A = "hello"
String B = "goodbye"



'---Different ways to concatenate string
PrintL A + " " + B
PrintL A & " " & B
PrintL A . " " . B
PrintL Greetings(a, b)


WaitKey


'---If some code is exexute more tha once, it is much better to create a function
'---and write it only once
Function Greetings(ByVal s1 As String, ByVal s2 As String) As String
Function = s1 & " " & s2
End Function




Regarding control during execution, remember that thinBasic has a debugger (maybe not absolutely bug free but quite usable)
So you can follow your program step by step by executing it in debug mode (F8 key)

Ciao
Eros