PDA

View Full Version : simple math.calculator + verify numbers AND characters possible ?



Lionheart008
21-08-2010, 15:32
hello.

I've wanted to make calculations with "numbers" (ok here) and I ask if it's also possible to check after some math. formula like "sin", "Cos", "tan" in same textfield ? It's possible to check after numbers and Strings or single Character at same time ?


CONTROL GET TEXT CB.HNDL, %TXT_TEXTBOX1 TO sTest
x = VERIFY (sTest , "-+,./*^1234567890sincostan")

I've tested this way but without success, how to check the data for feedback these sin,cos,tan functions ?


IF INSTR(sTest, ANY "SINCOSTAN") THEN
a = a + INSTR(sTest, " SIN ")
a = a + INSTR(sTest, " COS ")
a = a + INSTR(sTest, " TAN ")
...
end if


how to look after these three words as math. formula?


str = "SIN() - Sinus","COS() - Cosinus","TAN() - Tangent"

any help, tipp or example for testing would be good. thanks. frank

ErosOlmi
21-08-2010, 16:24
There is no one way but many different ways depending on what you are trying to do.

If you want to have a math evaluator, it is a complex job. Maybe you can have a look at Eval module.
If you want to just check some text, you have plenty of thinBasic functions working on text but they will not tell you if text if correct from a math point of view.

Lionheart008
24-08-2010, 21:54
There is no one way but many different ways depending on what you are trying to do.

hello all. thank you eros for explanations. I see. nevertheless I am going on to build little math. calculator and much more ;)

1) first question: how to send a number to a textbox correct ? my example doesn't work, although I thought it must run. ------> problem solved too! ;)


' Empty GUI script created on 08-24-2010 21:34:13 by (ThinAIR)
'------ fixed version :)

Uses "console", "ui"

'---------------------
%IDOK1 = 1000
%BTN_Test = 101
%LBL_LABEL1 = 102
%LBL_LABEL2 = 103
%TXT_TEXTBOX1 = 104
%TXT_TEXTBOX2 = 105
%TXT_TEXTBOX3 = 106
%result = 107
%Numbers = 108
%Numbers2 = 109
%Numbers3 = 110
%Numbers4 = 111
%LBL_LABEL3 = 112
%Adds = 113
%MINUS = 114
%MULTI = 115
%DIV = 116
%DIV2 = 117
%Clears = 118
%ButtonClose = 120
'---------------------


Function TBMain() As Long
Local hDlg As Long

Dialog New 0, "test-for-5-to-textbox: " + Date$, -1,-1, 280, 180, %WS_CAPTION Or %WS_SYSMENU Or %WS_POPUP Or %WS_MINIMIZEBOX, 0 To hDlg

Control Add Button, hDlg, %ButtonClose, "close", 225, 160, 28, 14
Control Add Button, hDlg, %Numbers, "5", 165, 60, 24, 24
Control Add Textbox, hDlg, %TXT_TEXTBOX1, "", 15, 90, 100, 13

Dialog Show Modal hDlg Call DlgProc

End Function

CallBack Function DlgProc() As Long
Local sTest As String '
Local vTest As String
Local x,l,b,f As Long
Local v As String
Local tTest As String
Local p As String
Local s As String
Local str As String
Local zText As Asciiz * 2
Local zText2 As Asciiz * 4
Local hdlg As Long

Select Case CBMSG
Case %WM_COMMAND
If CBWPARAM = %ButtonClose Then Dialog End CBHNDL

Select Case CBCTL
Case %IDOK
If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
Control Get Text CBHNDL, %TXT_TEXTBOX1 To sTest
Control Get Text CBHNDL, %TXT_TEXTBOX2 To tTest

MsgBox 0,"first Edit: = "+stest, ,"Result"
MsgBox 0,"second Edit: = "+ttest, ,"second Result"
l = Val(stest)
End If

Case %Numbers
zText = "5"
Control Set Text CBHNDL, %TXT_TEXTBOX1, Str$(zText)
MsgBox 0,"shows: number 5"

End Select
End Select

End Function

2) problem zone and bigger one: (sorry, solved!)

x = Verify (sTest ,"-+,./*^01234567890sincostan") '--> doesn't work !
'x = Verify (sTest , "1234567890") '--> only this line with numbers works :)


Case %TXT_TEXTBOX1
'If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
If CBCTLMSG = %EN_UPDATE Then
Control Get Text CBHNDL, %TXT_TEXTBOX1 To sTest

x = Verify (sTest ,"-+,./*^01234567890sincostan") '--> doesn't work !
'x = Verify (sTest , "1234567890") '--> this line works :)

If x > 0 Then
sTest = Remove$(sTest, Mid$(sTest, x, 1))
Control Set Text CBHNDL, %TXT_TEXTBOX1, sTest
Control Send CBHNDL, %TXT_TEXTBOX1, %EM_SETSEL, x-1, x-1
End If

any help on that would be great. thanks.

new edit: example with "verify" works now with


x = Verify (sTest , "1234567890+-*,=!/() sincostan")

success: I have restarted my computer and thinbasic/thinair.exe., that's strange. this example didn't work for me more about an hour. :unguee:

new edit2: problems are fixed :) ! yippieh!

servus, frank
ps: fixed version of "math. calculator demo" you can find in zip file too

Lionheart008
24-08-2010, 22:31
:P problem solved for number 5 with :)

correct:

Control Set Text CBHNDL, %TXT_TEXTBOX1, str$(zText)

instead of wrong way:

Control Send CBHNDL, %TXT_TEXTBOX1, %EM_REPLACESEL, VarPtr(zText),1 '---> doesn't run!

good tipp for all nightcrawlers: don't work and stay alive for programming if you are tired ! ;)

corrected version I send in my last post.

frank

Lionheart008
25-08-2010, 18:14
well, this is first release of my simple math. calculator. You can calculate "add", "minus", do "substract", "divide" (not by zero!) numbers. you can type in "sin", "cos", "tan". for next release I will check how to include running function for these three math. commands, perhaps by "instr" command.

critics to this little tool are very welcome :)


' Empty GUI script created on 08-24-2010 20:37:28 by (ThinAIR)
'--------------- simple math. calculator with callbacks, gui elements by frank brübach

Uses "ui" ', "console"

Begin Const
%IDOK1 = 1000 = %WM_USER + 1
%BTN_Test
%LBL_LABEL1
%LBL_LABEL2
%TXT_TEXTBOX1
%TXT_TEXTBOX2
%TXT_TEXTBOX3
%result
%Numbers
%Numbers2
%Numbers3
%Numbers4
%LBL_LABEL3
%Adds
%MINUS
%MULTI
%DIV
%DIV2
%Clears
%ButtonClose
End Const


Function TBMain() As Long
Local hDlg As Long

Dialog New 0, "Frank's math.Calc Tool 1b_go!: " + Date$, -1,-1, 280, 180, %WS_CAPTION Or %WS_SYSMENU Or %WS_POPUP Or %WS_MINIMIZEBOX, 0 To hDlg

Dialog Set Color hDlg, -1, Rgb(92,192,222)
Dim icony As String
icony = APP_SourcePath + "batmancar1.ico"
Dialog Set Icon hDlg , icony

Control Add Label, hDlg, -1, "..type in numbers and calculate", 5, 10, 130, 10, %SS_CENTER
Control Set Color hDlg, -1, -1, Rgb(146,202,142)
Control Add Label, hDlg, %LBL_LABEL1, " Info: - + , . / * ^ 01234567890, sin, cos, tan allowed", 50, 28, 180, 10
Control Set Color hDlg, %LBL_LABEL1, Rgb(255,100,10),%BLACK
Control Add Button, hDlg, %ButtonClose, "close", 225, 160, 32, 14
Control Add Button, hDlg, %Adds, "+", 56, 140, 16, 16
Control Add Button, hDlg, %MINUS, "-", 8, 140, 16, 16
Control Add Button, hDlg, %MULTI, "*", 23, 140, 16, 16
Control Add Button, hDlg, %DIV, "/", 40, 140, 16, 16
Control Add Button, hDlg, %IDOK, "test (edit)", 55, 60, 40, 16
Control Add Button, hDlg, %Clears, "clear", 95, 60, 40, 16
Control Add Button, hDlg, %result, "result (+)", 12, 60, 44, 16
Control Add Button, hDlg, %Numbers, "5", 165, 60, 18, 18
Control Add Button, hDlg, %Numbers2, "10", 185, 60, 18, 18
Control Add Button, hDlg, %Numbers3, "2", 185, 80, 18, 18
Control Add Button, hDlg, %Numbers4, "8", 165, 80, 18, 18
Control Add Textbox, hDlg, %TXT_TEXTBOX1, "", 15, 90, 100, 14
Control Add Textbox, hDlg, %TXT_TEXTBOX2, "", 75, 120, 120, 16
Control Add Textbox, hDlg, %TXT_TEXTBOX3, "", 75, 140, 120, 16
Control Set Color hDlg, %TXT_TEXTBOX3, -1, Rgb(190, 240, 240)

Dialog Show Modal hDlg Call DlgProc

End Function

CallBack Function DlgProc() As Long
Local sTest As String '
Local vTest As String
Local x,l,b,f As Long
Local v As String
Local tTest As String
Local p As String
Local s As String
Local str As String
Local zText As Asciiz * 2
Local zText2 As Asciiz * 4
Local hdlg As Long

Select Case CBMSG
Case %WM_COMMAND
If CBWPARAM = %ButtonClose Then Dialog End CBHNDL

Select Case CBCTL
Case %IDOK
If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
Control Get Text CBHNDL, %TXT_TEXTBOX1 To sTest
Control Get Text CBHNDL, %TXT_TEXTBOX2 To tTest

MsgBox 0,"first Edit: = "+stest, ,"Result"
MsgBox 0,"second Edit: = "+ttest, ,"second Result"
l = Val(stest)
End If

Case %Clears
If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
Control Set Text CBHNDL, %TXT_TEXTBOX1, sTest
Control Set Text CBHNDL, %TXT_TEXTBOX2, tTest
Control Set Text CBHNDL, %TXT_TEXTBOX3, vTest
Reset sTest
Reset tTest
Reset vTest
Control Set Color CBHNDL, %TXT_TEXTBOX1, -1, Rgb(Rnd(1,100), 240, 100)
End If

Case %TXT_TEXTBOX1
If CBCTLMSG = %EN_UPDATE Then
Control Get Text CBHNDL, %TXT_TEXTBOX1 To sTest
x = Verify (sTest , "1234567890+-*,=!/() sincostan")
If x > 0 Then
sTest = Remove$(sTest, Mid$(sTest, x, 1))
Control Set Text CBHNDL, %TXT_TEXTBOX1, sTest
Control Send CBHNDL, %TXT_TEXTBOX1, %EM_SETSEL, x-1, x-1
End If

End If

Case %TXT_TEXTBOX2
If CBCTLMSG = %EN_UPDATE Then
Control Get Text CBHNDL, %TXT_TEXTBOX2 To tTest
x = Verify (tTest , "1234567890+-*,=!/() sincostan")
If x > 0 Then
tTest = Remove$(tTest, Mid$(tTest, x, 1))
Control Set Text CBHNDL, %TXT_TEXTBOX2, tTest
Control Send CBHNDL, %TXT_TEXTBOX2, %EM_SETSEL, x-1, x-1
End If
End If

Case %result
If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
Control Get Text CBHNDL, %TXT_TEXTBOX1 To sTest
Control Get Text CBHNDL, %TXT_TEXTBOX2 To tTest
Control Get Text CBHNDL, %TXT_TEXTBOX3 To vTest
l = Val(stest)
b = Val(ttest)
f = l + b
Control Set Text CBHNDL, %TXT_TEXTBOX3, Str$(f)
End If

Case %Adds
If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
Control Get Text CBHNDL, %TXT_TEXTBOX1 To sTest
Control Get Text CBHNDL, %TXT_TEXTBOX2 To tTest
Control Get Text CBHNDL, %TXT_TEXTBOX3 To vTest
l = Val(stest)
b = Val(ttest)
f = l + b
Control Set Text CBHNDL, %TXT_TEXTBOX3, Str$(f)

End If

Case %minus
If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
Control Get Text CBHNDL, %TXT_TEXTBOX1 To sTest
Control Get Text CBHNDL, %TXT_TEXTBOX2 To tTest
Control Get Text CBHNDL, %TXT_TEXTBOX3 To vTest
l = Val(stest)
b = Val(ttest)
f = l - b
Control Set Text CBHNDL, %TXT_TEXTBOX3, Str$(f)
End If

Case %multi
If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
Control Get Text CBHNDL, %TXT_TEXTBOX1 To sTest
Control Get Text CBHNDL, %TXT_TEXTBOX2 To tTest
Control Get Text CBHNDL, %TXT_TEXTBOX3 To vTest
Control Set Color CBHNDL, %TXT_TEXTBOX3, -1, Rgb(190, 240, 240)
l = Val(stest)
b = Val(ttest)
f = l * b
Control Set Text CBHNDL, %TXT_TEXTBOX3, Str$(f)
End If

Case %div
If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
Control Get Text CBHNDL, %TXT_TEXTBOX1 To sTest
Control Set Color CBHNDL, %TXT_TEXTBOX1, Rgb(255,0,0), Rgb(0,0,0)
Control Get Text CBHNDL, %TXT_TEXTBOX2 To tTest
Control Get Text CBHNDL, %TXT_TEXTBOX3 To vTest

If Val(vTest) <> 0 Then
l = Val(stest)
b = Val(ttest)
str = Str$(l / b)
Control Set Text CBHNDL, %TXT_TEXTBOX3, str
End If
End If
If tTest = "0" Then
MsgBox 0,"[error] = 0 division", %MB_OK, "error!"
End If
If sTest = "0" Then
MsgBox 0,"[error]= 0 division", %MB_OK, "error!"
End If
If str = "0" Then
MsgBox 0,"[error]= 0 division", %MB_OK, "error!"
End If

Case %Numbers
zText = "5"
Control Set Text CBHNDL, %TXT_TEXTBOX1, Str$(zText)
MsgBox 0,"shows: number 5"

Case %Numbers2
zText2 = "10"
Control Set Text CBHNDL, %TXT_TEXTBOX2, Str$(zText2)
MsgBox 0,"shows: number 10"

Case %Numbers3
zText = "2"
Control Set Text CBHNDL, %TXT_TEXTBOX1, Str$(zText)
MsgBox 0,"shows: number 2"

Case %Numbers4
zText2 = "8"
Control Set Text CBHNDL, %TXT_TEXTBOX2, Str$(zText2)
MsgBox 0, "shows: number 8"

Case %WM_DESTROY
MsgBox 0, "Window is to be destroyed."

End Select
End Select
End Function



thinbasic "math. calculator 1.b" code example and icon you can find in zip folder.

best regards, frank

Michael Hartlef
25-08-2010, 20:04
Nice start Frank.

But I didn't know where to put in the numbers. When I pressed the numbered buttons, messageboxes came up. For what? And I was able to crash the app by pressed on the arithmetic buttons. I guess I did it when I should not. I would rather make it crash save first and work on the user experience than adding new features.

Michael

Lionheart008
25-08-2010, 21:18
hi mike, thanks for testing and having feedback! good to hear that I can improve gui with infos :)

for using math. calc tool: use both white edit fields and type in a) by hand numbers. then push one of four calc button (+ - * / ) and the result will appear directly :)

or b) push one of four number button (to make it easier for beginners) and the numbers should appear after clicking in both editfields, after that you can push add or minus or multiply button to see what's happen (the result will be put in third edit field too).

have made a little update with better infos, I hope this one helps! :) thanks. try and use it again. if you have any problems please send it again. I haven't any problems with calculations under win xp 2.

"math.calculator 1.c"

' Empty GUI script created on 08-24-2010 20:37:28 by (ThinAIR)
'--------------- simple math. calculator with callbacks, gui elements by frank brübach

Uses "ui" ', "console"

Begin Const
%IDOK1 = 1000 = %WM_USER + 1
%BTN_Test
%LBL_LABEL1
%LBL_LABEL2
%LBL_LABEL3
%LBL_LABEL4
%LBL_LABEL5
%TXT_TEXTBOX1
%TXT_TEXTBOX2
%TXT_TEXTBOX3
%result
%Numbers
%Numbers2
%Numbers3
%Numbers4
%Adds
%MINUS
%MULTI
%DIV
%DIV2
%Clears
%ButtonClose
End Const


Function TBMain() As Long
Local hDlg As Long
MsgBox 0, "type in in both white editfields numbers: push 4 calc button + - * / to see results :)", %MB_OK, "math. calculator for testing"
Dialog New 0, "Frank's math.Calc Tool 1c_go!: " + Date$, -1,-1, 290, 180, %WS_CAPTION Or %WS_SYSMENU Or %WS_POPUP Or %WS_MINIMIZEBOX, 0 To hDlg

Dialog Set Color hDlg, -1, Rgb(92,192,222)
Dim icony As String
icony = APP_SourcePath + "batmancar1.ico"
Dialog Set Icon hDlg , icony

Control Add Label, hDlg, -1, "info: type in both white editfields numbers and calculate by math. buttons", 5, 10, 140, 18, %SS_CENTER
Control Set Color hDlg, -1, -1, Rgb(146,202,142)
Control Add Label, hDlg, %LBL_LABEL1, " EditFields: - + , . / ()=*^ 01234567890,sin,cos,tan allowed", 50, 36, 186, 10
Control Set Color hDlg, %LBL_LABEL1, Rgb(255,100,10),%BLACK
Control Add Button, hDlg, %ButtonClose, "close", 235, 160, 42, 14
Control Add Button, hDlg, %Adds, "+", 64, 140, 16, 16
Control Add Button, hDlg, %MINUS, "-", 8, 140, 16, 16
Control Add Button, hDlg, %MULTI, "*", 28, 140, 16, 16
Control Add Button, hDlg, %DIV, "/", 46, 140, 16, 16
Control Add Label, hDlg, %LBL_LABEL2, " minus multy div add ", 8, 126, 70, 10
Control Set Color hDlg, %LBL_LABEL2, Rgb(255,100,10),%BLACK
Control Add Button, hDlg, %IDOK, "test (edit)", 55, 60, 40, 16
Control Add Button, hDlg, %Clears, "clear", 95, 60, 40, 16
Control Add Button, hDlg, %result, "result (+)", 12, 60, 44, 16
Control Add Button, hDlg, %Numbers, "5", 205, 80, 18, 18
Control Add Button, hDlg, %Numbers2, "10", 225, 80, 18, 18
Control Add Label hDlg, %LBL_LABEL4, " push these four numbers only for testing the editfields", 175, 60, 90, 18
Control Set Color hDlg, %LBL_LABEL4, Rgb(255,100,10),%BLACK
Control Add Button, hDlg, %Numbers3, "2", 225, 100, 18, 18
Control Add Button, hDlg, %Numbers4, "8", 205, 100, 18, 18
Control Add Textbox, hDlg, %TXT_TEXTBOX1, "12", 15, 90, 100, 14
Control Add Textbox, hDlg, %TXT_TEXTBOX2, "18", 85, 120, 120, 16
Control Add Textbox, hDlg, %TXT_TEXTBOX3, " = ", 85, 140, 120, 16
Control Add Label hDlg, %LBL_LABEL5, " <= result ", 205, 144, 36, 10
Control Set Color hDlg, %LBL_LABEL5, Rgb(255,100,10),%BLACK
Control Set Color hDlg, %TXT_TEXTBOX3, -1, Rgb(190, 240, 240)

Dialog Show Modal hDlg Call DlgProc

End Function

CallBack Function DlgProc() As Long
Local sTest As String '
Local vTest As String
Local x,l,b,f As Long
Local v As String
Local tTest As String
Local p As String
Local s As String
Local str As String
Local zText As Asciiz * 2
Local zText2 As Asciiz * 4
Local hdlg As Long

Select Case CBMSG
Case %WM_COMMAND
If CBWPARAM = %ButtonClose Then Dialog End CBHNDL

Select Case CBCTL
Case %IDOK
If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
Control Get Text CBHNDL, %TXT_TEXTBOX1 To sTest
Control Get Text CBHNDL, %TXT_TEXTBOX2 To tTest

MsgBox 0,"first Edit: = "+stest, ,"Result"
MsgBox 0,"second Edit: = "+ttest, ,"second Result"
l = Val(stest)
End If

Case %Clears
If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
Control Set Text CBHNDL, %TXT_TEXTBOX1, sTest
Control Set Text CBHNDL, %TXT_TEXTBOX2, tTest
Control Set Text CBHNDL, %TXT_TEXTBOX3, vTest
Reset sTest
Reset tTest
Reset vTest
Control Set Color CBHNDL, %TXT_TEXTBOX1, -1, Rgb(Rnd(1,100), 240, 100)
End If

Case %TXT_TEXTBOX1
'If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
If CBCTLMSG = %EN_UPDATE Then
Control Get Text CBHNDL, %TXT_TEXTBOX1 To sTest
x = Verify (sTest , "1234567890+-*,=!/() sincostan")
If x > 0 Then
sTest = Remove$(sTest, Mid$(sTest, x, 1))
Control Set Text CBHNDL, %TXT_TEXTBOX1, sTest
Control Send CBHNDL, %TXT_TEXTBOX1, %EM_SETSEL, x-1, x-1
End If

End If

Case %TXT_TEXTBOX2
If CBCTLMSG = %EN_UPDATE Then
Control Get Text CBHNDL, %TXT_TEXTBOX2 To tTest
x = Verify (tTest , "1234567890+-*,=!/() sincostan")
If x > 0 Then
tTest = Remove$(tTest, Mid$(tTest, x, 1))
Control Set Text CBHNDL, %TXT_TEXTBOX2, tTest
Control Send CBHNDL, %TXT_TEXTBOX2, %EM_SETSEL, x-1, x-1
End If
End If

Case %result
If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
Control Get Text CBHNDL, %TXT_TEXTBOX1 To sTest
Control Get Text CBHNDL, %TXT_TEXTBOX2 To tTest
Control Get Text CBHNDL, %TXT_TEXTBOX3 To vTest
l = Val(stest)
b = Val(ttest)
f = l + b
Control Set Text CBHNDL, %TXT_TEXTBOX3, Str$(f)
End If

Case %Adds
If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
Control Get Text CBHNDL, %TXT_TEXTBOX1 To sTest
Control Get Text CBHNDL, %TXT_TEXTBOX2 To tTest
Control Get Text CBHNDL, %TXT_TEXTBOX3 To vTest
l = Val(stest)
b = Val(ttest)
f = l + b
Control Set Text CBHNDL, %TXT_TEXTBOX3, Str$(f)

End If

Case %minus
If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
Control Get Text CBHNDL, %TXT_TEXTBOX1 To sTest
Control Get Text CBHNDL, %TXT_TEXTBOX2 To tTest
Control Get Text CBHNDL, %TXT_TEXTBOX3 To vTest
l = Val(stest)
b = Val(ttest)
f = l - b
Control Set Text CBHNDL, %TXT_TEXTBOX3, Str$(f)
End If

Case %multi
If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
Control Get Text CBHNDL, %TXT_TEXTBOX1 To sTest
Control Get Text CBHNDL, %TXT_TEXTBOX2 To tTest
Control Get Text CBHNDL, %TXT_TEXTBOX3 To vTest
Control Set Color CBHNDL, %TXT_TEXTBOX3, -1, Rgb(190, 240, 240)
l = Val(stest)
b = Val(ttest)
f = l * b
Control Set Text CBHNDL, %TXT_TEXTBOX3, Str$(f)
End If

Case %div
If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
Control Get Text CBHNDL, %TXT_TEXTBOX1 To sTest
Control Set Color CBHNDL, %TXT_TEXTBOX1, Rgb(255,0,0), Rgb(0,0,0)
Control Get Text CBHNDL, %TXT_TEXTBOX2 To tTest
Control Get Text CBHNDL, %TXT_TEXTBOX3 To vTest

If Val(vTest) <> 0 Then
l = Val(stest)
b = Val(ttest)
str = Str$(l / b)
Control Set Text CBHNDL, %TXT_TEXTBOX3, str
End If
End If
If tTest = "0" Then
MsgBox 0,"[error] = 0 division", %MB_OK, "error!"
End If
If sTest = "0" Then
MsgBox 0,"[error]= 0 division", %MB_OK, "error!"
End If
If str = "0" Then
MsgBox 0,"[error]= 0 division", %MB_OK, "error!"
End If

Case %Numbers
zText = "5"
Control Set Text CBHNDL, %TXT_TEXTBOX1, Str$(zText)
MsgBox 0,"shows: number 5 in editfield1"

Case %Numbers2
zText2 = "10"
Control Set Text CBHNDL, %TXT_TEXTBOX2, Str$(zText2)
MsgBox 0,"shows: number 10 in editfield2"

Case %Numbers3
zText = "2"
Control Set Text CBHNDL, %TXT_TEXTBOX1, Str$(zText)
MsgBox 0,"shows: number 2 in editfield1"

Case %Numbers4
zText2 = "8"
Control Set Text CBHNDL, %TXT_TEXTBOX2, Str$(zText2)
MsgBox 0, "shows: number 8 in editfield2"

Case %WM_DESTROY
MsgBox 0, "Window is to be destroyed."

End Select
End Select
End Function



would be good to hear more feedback of other users if these calculations are working fine.

best regards, servus, frank

Michael Hartlef
26-08-2010, 20:05
Ok, I tested your script. Now it is more clear where to put something. Still when you delete the second edit field and press division, the scirpt crashes with a divide by zero error.

zlatkoAB
26-08-2010, 21:43
Frank ...
look someties in joske evaluator on coding monkeys and you will
figured how things work on very simle and clever way .
I use them in my latest ABasic testing and works fine.
I know i know( i talk to myself)...
I simply dont have time to translate this to thinBasi but i willl....

Lionheart008
28-08-2010, 00:21
thanks, michael and aurel for tests and good link for math. evaluator :)

here a fixed version for avoiding to divide by empty space in text field. Hope everything is correct now.


Still when you delete the second edit field and press division, the scirpt crashes with a divide by zero error.


' Empty GUI script created on 08-24-2010/08-27-2010 20:37:28 by (ThinAIR)
'--------------- simple math. calculator with callbacks, gui elements by frank brübach

Uses "ui" ', "console"

Begin Const
%IDOK1 = 1000 = %WM_USER + 1
%BTN_Test
%LBL_LABEL1
%LBL_LABEL2
%LBL_LABEL3
%LBL_LABEL4
%LBL_LABEL5
%TXT_TEXTBOX1
%TXT_TEXTBOX2
%TXT_TEXTBOX3
%result
%Numbers
%Numbers2
%Numbers3
%Numbers4
%Adds
%MINUS
%MULTI
%DIV
%DIV2
%Clears
%ButtonClose
End Const


Function TBMain() As Long
Local hDlg As Long
msgbox 0, "type in in both white editfields numbers: push 4 calc button + - * / to see results :)", %MB_OK, "math. calculator for testing"
Dialog New 0, "Frank's math.Calc Tool 1d_go!: " + Date$, -1,-1, 290, 180, %WS_CAPTION Or %WS_SYSMENU Or %WS_POPUP Or %WS_MINIMIZEBOX, 0 To hDlg

Dialog Set Color hDlg, -1, Rgb(92,192,222)
Dim icony As String
icony = APP_SourcePath + "batmancar1.ico"
Dialog Set Icon hDlg , icony

Control Add Label, hDlg, -1, "info: type in both white editfields numbers and calculate by math. buttons", 5, 10, 140, 18, %SS_CENTER
Control Set Color hDlg, -1, -1, Rgb(146,202,142)
Control Add Label, hDlg, %LBL_LABEL1, " EditFields: - + , . / ()=*^ 01234567890,sin,cos,tan allowed", 50, 36, 186, 10
Control Set Color hDlg, %LBL_LABEL1, Rgb(255,100,10),%BLACK
Control Add Button, hDlg, %ButtonClose, "close", 235, 160, 42, 14
Control Add Button, hDlg, %Adds, "+", 64, 140, 16, 16
Control Add Button, hDlg, %MINUS, "-", 8, 140, 16, 16
Control Add Button, hDlg, %MULTI, "*", 28, 140, 16, 16
Control Add Button, hDlg, %DIV, "/", 46, 140, 16, 16
Control Add Label, hDlg, %LBL_LABEL2, " minus multy div add ", 8, 126, 70, 10
Control Set Color hDlg, %LBL_LABEL2, Rgb(255,100,10),%BLACK
Control Add Button, hDlg, %IDOK, "test (edit)", 55, 60, 40, 16
Control Add Button, hDlg, %Clears, "clear", 95, 60, 40, 16
Control Add Button, hDlg, %result, "result (+)", 12, 60, 44, 16
Control Add Button, hDlg, %Numbers, "5", 205, 80, 18, 18
Control Add Button, hDlg, %Numbers2, "10", 225, 80, 18, 18
Control Add Label hDlg, %LBL_LABEL4, " push these four numbers only for testing the editfields", 175, 60, 90, 18
Control Set Color hDlg, %LBL_LABEL4, Rgb(255,100,10),%BLACK
Control Add Button, hDlg, %Numbers3, "2", 225, 100, 18, 18
Control Add Button, hDlg, %Numbers4, "8", 205, 100, 18, 18
Control Add Textbox, hDlg, %TXT_TEXTBOX1, "12", 15, 90, 100, 14
Control Add Textbox, hDlg, %TXT_TEXTBOX2, "18", 85, 120, 120, 16
Control Add Textbox, hDlg, %TXT_TEXTBOX3, " = ", 85, 140, 120, 16
Control Add Label hDlg, %LBL_LABEL5, " <= result ", 205, 144, 36, 10
Control Set Color hDlg, %LBL_LABEL5, Rgb(255,100,10),%BLACK
Control Set Color hDlg, %TXT_TEXTBOX3, -1, Rgb(190, 240, 240)

Dialog Show Modal hDlg Call DlgProc

End Function

CallBack Function DlgProc() As Long
Local sTest As String '
Local vTest As String
Local x,l,b,f As Long
Local v As String
Local tTest As String
Local p As String
Local s As String
Local str As String
Local zText As Asciiz * 2
Local zText2 As Asciiz * 4
Local hdlg As Long

Select Case CBMSG
Case %WM_COMMAND
If CBWPARAM = %ButtonClose Then Dialog End CBHNDL

Select Case CBCTL
Case %IDOK
If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
Control Get Text CBHNDL, %TXT_TEXTBOX1 To sTest
Control Get Text CBHNDL, %TXT_TEXTBOX2 To tTest

MsgBox 0,"first Edit: = "+stest, ,"Result"
MsgBox 0,"second Edit: = "+ttest, ,"second Result"
l = Val(stest)
End If

Case %Clears
If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
Control Set Text CBHNDL, %TXT_TEXTBOX1, sTest
Control Set Text CBHNDL, %TXT_TEXTBOX2, tTest
Control Set Text CBHNDL, %TXT_TEXTBOX3, vTest
Reset sTest
Reset tTest
Reset vTest
Control Set Color CBHNDL, %TXT_TEXTBOX1, -1, Rgb(Rnd(1,100), 240, 100)
End If

Case %TXT_TEXTBOX1
'If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
If CBCTLMSG = %EN_UPDATE Then
Control Get Text CBHNDL, %TXT_TEXTBOX1 To sTest
x = Verify (sTest , "1234567890+-*,=!/() sincostan")
If x > 0 Then
sTest = Remove$(sTest, Mid$(sTest, x, 1))
Control Set Text CBHNDL, %TXT_TEXTBOX1, sTest
Control Send CBHNDL, %TXT_TEXTBOX1, %EM_SETSEL, x-1, x-1
End If

End If

Case %TXT_TEXTBOX2
If CBCTLMSG = %EN_UPDATE Then
Control Get Text CBHNDL, %TXT_TEXTBOX2 To tTest
x = Verify (tTest , "1234567890+-*,=!/() sincostan")
If x > 0 Then
tTest = Remove$(tTest, Mid$(tTest, x, 1))
Control Set Text CBHNDL, %TXT_TEXTBOX2, tTest
Control Send CBHNDL, %TXT_TEXTBOX2, %EM_SETSEL, x-1, x-1
End If
End If

Case %result
If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
Control Get Text CBHNDL, %TXT_TEXTBOX1 To sTest
Control Get Text CBHNDL, %TXT_TEXTBOX2 To tTest
Control Get Text CBHNDL, %TXT_TEXTBOX3 To vTest
l = Val(stest)
b = Val(ttest)
f = l + b
Control Set Text CBHNDL, %TXT_TEXTBOX3, Str$(f)
End If

Case %Adds
If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
Control Get Text CBHNDL, %TXT_TEXTBOX1 To sTest
Control Get Text CBHNDL, %TXT_TEXTBOX2 To tTest
Control Get Text CBHNDL, %TXT_TEXTBOX3 To vTest
l = Val(stest)
b = Val(ttest)
f = l + b
Control Set Text CBHNDL, %TXT_TEXTBOX3, Str$(f)

End If

Case %minus
If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
Control Get Text CBHNDL, %TXT_TEXTBOX1 To sTest
Control Get Text CBHNDL, %TXT_TEXTBOX2 To tTest
Control Get Text CBHNDL, %TXT_TEXTBOX3 To vTest
l = Val(stest)
b = Val(ttest)
f = l - b
Control Set Text CBHNDL, %TXT_TEXTBOX3, Str$(f)
End If

Case %multi
If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
Control Get Text CBHNDL, %TXT_TEXTBOX1 To sTest
Control Get Text CBHNDL, %TXT_TEXTBOX2 To tTest
Control Get Text CBHNDL, %TXT_TEXTBOX3 To vTest
Control Set Color CBHNDL, %TXT_TEXTBOX3, -1, Rgb(190, 240, 240)
l = Val(stest)
b = Val(ttest)
f = l * b
Control Set Text CBHNDL, %TXT_TEXTBOX3, Str$(f)
End If

Case %div
If CBCTLMSG = %BN_CLICKED Or CBCTLMSG = 1 Then
Control Get Text CBHNDL, %TXT_TEXTBOX1 To sTest
Control Set Color CBHNDL, %TXT_TEXTBOX1, Rgb(255,0,0), Rgb(0,0,0)
Control Get Text CBHNDL, %TXT_TEXTBOX2 To tTest
Control Get Text CBHNDL, %TXT_TEXTBOX3 To vTest

If Val(vTest) <> 0 Then
l = Val(stest)
b = Val(ttest)
If b > 0 or b < 0 Then
str = Str$(l / b)
End If
Control Set Text CBHNDL, %TXT_TEXTBOX3, str
End If
End If
If tTest = "0" Then
MsgBox 0,"[error] = 0 division", %MB_OK, "error!"
End If
If sTest = "0" Then
MsgBox 0,"[error]= 0 division", %MB_OK, "error!"
End If
If str = "0" Then
MsgBox 0,"[error]= 0 division", %MB_OK, "error!"
End If

Case %Numbers
zText = "5"
Control Set Text CBHNDL, %TXT_TEXTBOX1, Str$(zText)
MsgBox 0,"shows: number 5 in editfield1"

Case %Numbers2
zText2 = "10"
Control Set Text CBHNDL, %TXT_TEXTBOX2, Str$(zText2)
MsgBox 0,"shows: number 10 in editfield2"

Case %Numbers3
zText = "2"
Control Set Text CBHNDL, %TXT_TEXTBOX1, Str$(zText)
MsgBox 0,"shows: number 2 in editfield1"

Case %Numbers4
zText2 = "8"
Control Set Text CBHNDL, %TXT_TEXTBOX2, Str$(zText2)
MsgBox 0, "shows: number 8 in editfield2"

Case %WM_DESTROY
MsgBox 0, "Window is to be destroyed."

End Select
End Select
End Function



@aurel:
I simply don't have time to translate this to thinBasic but i will....
good to hear that, I am curious to see that ;)

good night, servus, frank

zlatkoAB
29-08-2010, 11:43
I think that there will be no to trouble translate Joske code becose
with few changes work fine on Creative and of course thinbasic
have all nececery option to do this- even some things maby works
better on thinBasic then on creative but with little big amount
of code so..soo...little deference...

Lionheart008
15-09-2010, 10:49
good morning :)

I wanted to play with letters and try to make a difference by using various words like a) "love" (that's ok for this example) and other way b) "elephant".

I have the intention to get the whole word "elephant" and if this is valid to say, ok there should be a function in future for it (I've done here only for test purpose a msgbox, that's nerving ;) )

perhaps anybody can help and say what's the best way to verify a complete word that's valid for text field input. thanks in advance. nice day, frank


' Empty GUI script created on 09-15-2010 10:19:53 by (ThinAIR)

Uses "console", "ui"

Begin Const
%bClose = 1001
%myInput = 1002
%ButtonClose = 1003
End Const

Function TBMain () As Long

Local hDlg As DWord

Dialog New 0, "..Use only L,o,v,e, E,l,e,p,h,a,n,t ",100,100, 220, 90, _
%WS_POPUP Or %WS_VISIBLE Or %WS_CAPTION Or %WS_SYSMENU Or %WS_MINIMIZEBOX To hDlg
Control Add Textbox, hDlg, %myInput, "", 5, 5, 170, 24, %WS_CHILD Or %WS_VISIBLE Or %ES_MULTILINE Or %ES_WANTRETURN Or _
%ES_LEFT Or %WS_VSCROLL Or %ES_NOHIDESEL Or %ES_AUTOVSCROLL Or %WS_TABSTOP, %WS_EX_CLIENTEDGE, Call bInputProc
Control Add Button , hDlg, %ButtonClose, "Click to close", 5, 50, 170, 14, Call bCloseProc

Dialog Show Modal hDlg, Call dlgProc
End Function

CallBack Function dlgProc()
Select Case CBMSG
Case %WM_INITDIALOG
Case %WM_CLOSE
End Select
End Function


CallBack Function bCloseProc()
Select Case CBMSG
Case %WM_COMMAND
If CBWPARAM = %ButtonClose Then Dialog End CBHNDL
End Select
End Function

CallBack Function bInputProc()
Local s As String, posy, selStart, selEnd, k, v, max_len As Long
max_len = 8 '4

If CBMSG = %WM_COMMAND Then
If CBCTLMSG = %EN_UPDATE Then

Control Get Text CBHNDL, %myInput To s
If Len(s) > 0 Then

Control Send CBHNDL, %myInput, %EM_GETSEL, VarPtr(selStart), VarPtr(selEnd)
Control Send CBHNDL, %myinput, %EM_SETLIMITTEXT, MAX_LEN, 0
posy = Verify(s, "loveElphant") '
If posy Then s = LEFT$(s, posy-1)
'----------------------------------------------------------------------------------------------------
If InStr(s, Any "ELEPHANT") Then
'depending what you allow regarding spaces...
If posy = posy + InStr(s, " ELEPHANT ") Then
MsgBox 0, "well we are testing only Elephant here!", %MB_OK, "testing Love does make it too"
End If
End If
'----------------------------------------------------------------------------------------------------

If posy > 0 Then
Beep(100, 20)
s = Remove$(s, Mid$(s, posy, 1))
Control Set Text CBHNDL, %myInput, s
Control Send CBHNDL, %myInput, %EM_SETSEL, posy-1, posy-1
End If
Control Send CBHNDL, %myInput, %EM_SETSEL, selStart, selEnd
End If
End If
End If

End Function

Lionheart008
15-09-2010, 18:09
problem solved, solution very simple (uargh!) :P
see code example below.


' Empty GUI script created on 09-15-2010 10:19:53 by (ThinAIR)

Uses "console", "ui"

Begin Const
%bClose = 1001
%myInput = 1002
%ButtonClose = 1003
End Const

Function TBMain () As Long

Local hDlg As DWord

Dialog New 0, "..Use only L,o,v,e, E,l,e,p,h,a,n,t ",100,100, 220, 90, _
%WS_POPUP Or %WS_VISIBLE Or %WS_CAPTION Or %WS_SYSMENU Or %WS_MINIMIZEBOX To hDlg
Control Add Textbox, hDlg, %myInput, "", 5, 5, 170, 24, %WS_CHILD Or %WS_VISIBLE Or %ES_MULTILINE Or %ES_WANTRETURN Or _
%ES_LEFT Or %WS_VSCROLL Or %ES_NOHIDESEL Or %ES_AUTOVSCROLL Or %WS_TABSTOP, %WS_EX_CLIENTEDGE, Call bInputProc
Control Add Button , hDlg, %ButtonClose, "Click to close", 5, 50, 170, 14, Call bCloseProc

Dialog Show Modal hDlg, Call dlgProc
End Function

CallBack Function dlgProc()
Select Case CBMSG
Case %WM_INITDIALOG
Case %WM_CLOSE
End Select
End Function


CallBack Function bCloseProc()
Select Case CBMSG
Case %WM_COMMAND
If CBWPARAM = %ButtonClose Then Dialog End CBHNDL
End Select
End Function

CallBack Function bInputProc()
Local s As String, posy, selStart, selEnd, k, v, max_len As Long
max_len = 8 '4

If CBMSG = %WM_COMMAND Then
If CBCTLMSG = %EN_UPDATE Then

Control Get Text CBHNDL, %myInput To s
If Len(s) > 0 Then

Control Send CBHNDL, %myInput, %EM_GETSEL, VarPtr(selStart), VarPtr(selEnd)
Control Send CBHNDL, %myinput, %EM_SETLIMITTEXT, MAX_LEN, 0
posy = Verify(s, "LoveElephant") '
If posy Then s = LEFT$(s, posy-1)

'---> simple solution ! -----------------------------------<
If s = "Elephant" Then
MsgBox 0, "success Elephant"
End If

If s = "Love" Then
MsgBox 0, "success Love"
End If
'-------------------------------------------------------------------------------------
' If InStr(s, Any "ELEPHANT") Then
'depending what you allow regarding spaces...
' If posy = posy + InStr(s, " ELEPHANT ") Then
' MsgBox 0, "well we are testing only Elephant here!", %MB_OK, "testing Love does make it too"
' End If
' End If
'----------------------------------------------------------------------------------------------------

If posy > 0 Then
Beep(100, 20)
s = Remove$(s, Mid$(s, posy, 1))
Control Set Text CBHNDL, %myInput, s
Control Send CBHNDL, %myInput, %EM_SETSEL, posy-1, posy-1
End If
Control Send CBHNDL, %myInput, %EM_SETSEL, selStart, selEnd
End If
End If
End If

End Function

best regards, frank