VBAndCs / sVB-Small-Visual-Basic

Small Visual Basic (sVB) is an educational programming language, created by Eng. Mohammad Hamdy as an evolved version of Microsoft Small Basic (SB). It is meant to be easier and more powerful at the same time, to introduce programming basics to kids and beginners of any age, provided that they can use the English keyboard on the Windows OS.
Other
222 stars 16 forks source link

Difference between programming key events with GraphicsWindow and a sVB form ... #29

Closed boa2145 closed 1 year ago

boa2145 commented 1 year ago

Hello Mohammad,

I understand to code key events on GraphicsWindow in Small Basic. This works on GraphicsWindow even if there is a focus on the textbox. So, I don't need an extra event handling within the textbox.

GraphicsWindow.KeyDown = OnKeyDown

Sub OnKeyDown ........keyPressed = GraphicsWindow.LastKey ........If keyPressed = "Enter" Then ...........do something ........EndIf EndSub

I also want to use the key event (e.g. Enter) for a texbox, not only a button to evaluate the input of the textbox. But I don't understand how to code the key event with a sVB form. Do I have to use the "name" of the textbox like "GraphicsWindow"? Could you, please, help me?

Regards ... Gregor

boa2145 commented 1 year ago

Good morning Mohammad,

I figured it out in Small Visual Basic: I wanted to check the key events inside a textbox. So, I code the following lines now:

-> InputTextBox (name of my textbox) InputTextBox.OnKeyDown = OnKeyDownSub

Sub OnKeyDownSub ..... If Keyboard.Lastkey = Keys.Enter Then .......... do something like .......... User_Number = InputTextbox.Text .......... CheckUserNumber() ..... EndIf EndSub

Now I am able to check and evaluate the keyboard events within a text box. That was my question to you. I'll leave it here anyway, in case other users are interested.

Last question: Does sVB have something to input only numbers inside a textbox of a form?

Kind regards ... Gregor

VBAndCs commented 1 year ago

@boa2145 You can use the upper lists of the code editor to easily add event handlers: image

Does sVB have something to input only numbers inside a textbox of a form?

See the Numeric TextBox project in the samples folder installed in your documents folder.

boa2145 commented 1 year ago

Thanks for the hint to the example to code a textbox only for numbers. I often read your sVB handbook, but I can also have a look into your examples.

PS: I hope I'm not bothering you with my questions, but you're the only one I can ask. If I can't find the answers to my questions with your manual, I'm at a loss and then have to plow through sVB somehow. I really like sVB and I hope to discover all the possibilities to program with this BASIC dialect with joy. I am mainly interested in programming languages ​​in the education sector such as Python, Small Basic, TigerJython, Scratch and recently Small Visual Basic.

VBAndCs commented 1 year ago

@boa2145 You are welcome. I just started teaching sVB to 10 to 16 years old kids, which eats most of my time, and this also reveals some hidden bugs in the sVB IDE because kids make all kind of unexpected mistakes, so I made three minor releases in a week, and the current version is 2.8.5.9. The sVB reference book contains all about it, and explains important parts of the sample projects in the examples provided for methods and properties, but it is not meant as an educational book, and this is why I may provide some introductory books later. Thanks.

boa2145 commented 1 year ago

Yes, that's right. Children are good testers of programs because they sometimes do very illogical things and it's interesting how the program copes with them. But it is also great for any program if its functions are used often by the users. Then you can quickly notice whether it works the way it was intended. Your sVB handbook is very good like a reference book. I wanted to print it out, but it is too expensive to print 750 pages.

I had been messing with the labels recently and it wasn't working as a switch like I wanted it to. My idea was to use labels to output messages since I didn't find DrawBoundText(). So initially the label had no caption, it was empty and should be invisible. Then the message should be showed 2 seconds and should disappear again, all with Label.Visible = True or False and new label captions. But it didn't work the way I thought it would. So I left it and output the messages with LabelName.Text and overwritten them with a new LabelName.Text after 2 seconds.

VBAndCs commented 1 year ago

@boa2145 If I understand correctly, you can have two labels on top of each other, then hide one and show the other. The label can do many amazing things: • Use the Text property to set the text displayed by the label. • Use the Append… methods to add a formatted text to the label. • Use the AppendLink method to add a hyper link to the label. • Use the Image property to load an image from a file and display it in the label. • Use the Add… methods to add geometric shapes to the label. • The label can has auto width or height or both (just set the width or height to -1), or use the FitContent.. methods. • Use the WordWrap property to allow long text to be displayed over multiple lines.