Liberty BASIC Community Forum
« How to get data in a textbox? »

Welcome Guest. Please Login or Register.
Feb 18th, 2018, 3:42pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: How to get data in a textbox?  (Read 102 times)
PeterLouw
New Member
Image


member is offline

Avatar




PM


Posts: 9
xx How to get data in a textbox?
« Thread started on: Feb 5th, 2018, 3:14pm »

Good day! I am new here. I'm in my late 60s and have been playing around with LB and it's a great language. But I can't figure out how to place data, which has been calculated, in a textbox for display. I wrote a small program and GUI to convert temperature from Fahrenheit to Celcius. It works fine when I use a NOTICE to display the result, but when I use a second textbox for the output nothing seems to work. I've tried everything with the !selection? and able and disable commands; I'm doing something wrong and I don't know what it is. I would be so grateful if someone could assist! Here is the relevant code (I know it's a mess!):

Code:
[button1]

print #main.textbox1, "!contents?";
input #main.textbox1, fah$
cel = (val(fah$) - 32) * 5/9
selected$ = str$(cel)

print #main.textbox1, "!disable"
print #main.textbox2, "!enable"
print #main.textbox2, "";
print #main.textbox2, "!setfocus";
print #main.textbox2, "!selection? selected$";
print #main.textbox2, selected$

wait 


Edited by Chris Iverson to add CODE tags, 2018/02/05-04:16 CST
« Last Edit: Feb 5th, 2018, 4:20pm by Chris Iverson » User IP Logged

Chris Iverson
Administrator
ImageImageImageImageImage


member is offline

Avatar

20% Cooler


Homepage PM

Gender: Male
Posts: 2301
xx Re: How to get data in a textbox?
« Reply #1 on: Feb 5th, 2018, 4:18pm »

The !selection? command is only used by texteditors, not textboxes. And it doesn't put data into a texteditor; it retrieves data from it, much like the !contents? command for textboxes.


Just write the variable to the text field, like your last line of code.

Code:
print #main.textbox1, "!contents?";
input #main.textbox1, fah$
cel = (val(fah$) - 32) * 5/9
selected$ = str$(cel)

print #main.textbox2, selected$ 
User IP Logged

"Do you believe in destiny?" - Pyrrha Nikos, RWBY
"With what wish will your Soul Gem shine?" - Kyubey, Puella Magi Madoka Magica
PeterLouw
New Member
Image


member is offline

Avatar




PM


Posts: 9
xx Re: How to get data in a textbox?
« Reply #2 on: Feb 6th, 2018, 02:59am »

Dear Chris, MANY MANY THANKS! lol as easy as that! Somehow I didn't figure that out ...By the way, LB is the best!!! I first came in contact with LB through the Dummies book by Wallace Wang, and I then worked through the Jerry Lee Ford book. At some stage I tried Python, but I found creating a GUI in Python is terribly cumbersome whereas it really is a pleasure in LB. Thanks again for your guidance, it is much appreciated!
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5655
xx Re: How to get data in a textbox?
« Reply #3 on: Feb 6th, 2018, 04:48am »

Peter be cautious about looking at old code and old examples. Some things have changed. The LBPE is a good place to check stuff out. the link is at the top of the forum.

Some of your code is old hat, not wrong but it can be simplified now. First off is the PRINT command itself, it is unnecessary. As soon as you have the concept that PRINT #handle means "tell the control to do..." then drop the PRINT and simply adddress the #handle. You don't need the INPUT command either as it can be done in one statement now.

Code:
[button1]
'we dont need the PRINT, the , or the second INPUT line
'print #main.textbox1, "!contents?"
'input #main.textbox1, fah$
#main.textbox1 "!contents? fah$"
cel = (val(fah$) - 32) * 5/9
selected$ = str$(cel)

'we dont need enable disable setfocus or to print an ""
'anything you send to a textbox overwrites previous content
'print #main.textbox1, "!disable"
'print #main.textbox2, "!enable"
'print #main.textbox2, "";
'print #main.textbox2, "!setfocus";
'also this last line was wiping out yor selected$ by replacing
'with an empty string from the textbox
'print #main.textbox2, "!selection? selected$";
#main.textbox2 selected$
wait

 



So tidied up

Code:
[button1]
#main.textbox1 "!contents? fah$"
cel = (val(fah$) - 32) * 5/9
selected$ = str$(cel)
#main.textbox2 selected$
wait
 


« Last Edit: Feb 6th, 2018, 04:50am by Rod » User IP Logged

tsh73
Board Moderator

member is online

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1745
xx Re: How to get data in a textbox?
« Reply #4 on: Feb 6th, 2018, 05:53am »

I just wanted to say that one better not call variable "selected" if there is nothing actually selected.
But later realised that this variable doesn't needed at all - print to #main.textbox2 will perform conversion to string.
Code:
[button1]
    #main.textbox1 "!contents? fah$"
    cel = (val(fah$) - 32) * 5/9
    #main.textbox2 cel
wait
 
« Last Edit: Feb 6th, 2018, 05:53am by tsh73 » User IP Logged

damned Dog in the Manger
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls