I've not been in touch here for a while. I hope you are well.
I still like your Simple Windows API library, although I've been using Vanya's library more recently. I still use your library for developing GUI tasks, since it is so easy to use. I used to use Liberty Basic to do this but I had a little falling out with them on their forum. They didn't like me to mention LB Booster (Liberty Basic on steroids!) on the forum and banned me. First time I've been banned for anything!
Anyway, I had been developing a routine for LB to enter numeric data into an editbox (textbox as LB calls it) and have produced the code which is on the LBB (not LB website). Seeing as I'm looking more at FreeBasic now, I've developed the code for FreeBasic using your Simple Windows API GUI library.
There are many routines for restricting numeric entry into an editbox, but I wanted something that would error check as you entered the characters and would also display entries of ".123" as "0.123" and "-.123" as "-0.123". The routine would also have to ensure entry of only one "-" and this would be at the beginning of the number. The routine would also have to ensure that only one "." could be entered and it must allow editing.
I think I've accomplished this in the code below and, if you are happy with it, you may wish to include it as an example in your library:
Code: Select all
' NUMERIC INPUT IN A TEXTBOX
' This does a check for 0-9 and - or . and prevents entry of all other
' characters. It ensures that "-" can only be placed at the start of
' the number entry. It also ensures that only one "." or "-" can be
' It also ensures that if .123 is entered it displays 0.123 and if
' -.123 is entered -0.123 is displayed.
' Code by RNBW.
Dim As HWND Window_Main, Button_Ok, Edit_1
Dim As MSG msg
dim As String txt, oldtxt
Dim As Integer pos0
Function num(ByVal txt As String) As String
'Function to check that character input is 0-9, - or .
Dim As String num1
Dim As Integer i, a, t
For i = 1 To Len(txt)
a = Asc(Mid(txt,i,1))
if a = 46 then t = t + 1
if (a = 46) and (t > 1) then a = 0 'only DOT after FIRST is cleared
if a = 45 and i>1 then a = 0 'so really almost anything do, not just 8
if a = 46 and i = 1 then num1 = "0" + num1
If a = 45 Or a = 46 or a > 47 and a < 58 then num1 = num1 + Chr(a)
if a = 45 and mid(txt,2,1) = "." then num1 = "-0" + num1
'Create a window with an Editbox and a button:
Window_Main = Window_New (100, 100, 400, 400, "Numeric Entry Filter!")
Var Label_txt = Label_New (10, 10, 150, 20, "Enter numbers:",, Window_Main)
Edit_1 = EditBox_New (150, 10, 100, 20, "",, Window_Main)
Button_Ok = Button_New (160, 300, 60, 20, "Ok",, Window_Main)
'Set timer to 300 miliseconds:
SetTimer(Window_Main, 0, 300, 0 )
Select Case msg.message
'Check contents of the edit box every 300 millisecinds
txt = EditBox_GetText(Edit_1) 'get text from edit box
oldtxt = txt 'make text the oldtext
txt = num(txt) 'gets new text from function num(txt) which does the checking
If oldtxt <> txt Then
EditBox_SetText(Edit_1, txt) 'if old text is not the same as the new text then use new text
pos0 = Len(txt) 'position of character is the length of the current text
SendMessage(Edit_1, EM_SETSEL, pos0, pos0)
If msg.hwnd = Button_Ok Then Print EditBox_GetText(Edit_1) 'print text to console
Loop Until Window_Event_Close(Window_Main, msg)
I hope this is useful to anyone who needs this solution.