|
Post by wexhammer on Nov 19, 2019 15:10:09 GMT -5
Good Evening!
I have a massive headache trying to get around my code and after 2 hours i still cant work it out. Please help, what im looking to accomplish is entering data in all the text boxes so when i press save the program saves the string in the text boxes and when i open the program again the saved strings will appear in the textboxes.
Can anyone help me pleeease?
nomainwin UpperLeftX = 250 UpperLeftY = 100 WindowWidth = 400 WindowHeight = 450
'make sure file exists open "savedData.txt" for append as #3 close #3 'read from file open "savedData.txt" for input as #3 if not(eof(#3)) then line input #3,value1$
end if close #3
textbox #1.1, 90, 20, 40,20 textbox #1.2, 90, 110, 40,20 textbox #1.3, 90, 210, 40,20
button #1.exit, "Save",[save],LR,30,30,55,35 open "Splash Screen" for window as #1
print #1.1, value1$ print #1.2, value2$ wait
[save] 'get texbox content #1.1 "!contents? value1$" 'save textbox content open "savedData.txt" for output as #3 print #3,value1$ print #3,value2$ close #3 '------------------------- wait
|
|
|
Post by Chris Iverson on Nov 19, 2019 15:24:29 GMT -5
You're almost there, but after a quick look, I can spot a few things.
1) When you're reading the data in from the file, you only input value1$. value2$ and value3$ are still blank. You need to input all three.
2) You never actually print a value3$ to the third textbox, so nothing will ever get filled in there. You need to PRINT the three values you input to their respective textboxes.
3) When saving the file, you only get the contents of the first textbox. You never actually retrieve the value in the second or third. You need to send a "!contents?" command to all of them.
4) When writing the data out to the file, you only save value1$ and value2$. You need to get value3$ and save that as well, if you want to save the contents of all three textboxes.
|
|
|
Post by wexhammer on Nov 20, 2019 7:09:21 GMT -5
Brilliant thanks for your response/help! I have managed to make it work! One more favour please....
I have added a spinner control as i want to have this program save numbers, however when i enter a number greater than 1 and press save, when i reload the program the spinner doesn't show my saved string. Whats the reason for this?
nomainwin UpperLeftX = 250 UpperLeftY = 100 WindowWidth = 400 WindowHeight = 450
'make sure file exists open "savedData.txt" for append as #3 close #3 'read from file open "savedData.txt" for input as #3 if not(eof(#3)) then line input #3,value1$ line input #3,value2$ line input #3,value3$
end if close #3
textbox #1.1, 90, 20, 40,20 textbox #1.2, 90, 110, 40,20 textbox #1.3, 90, 210, 40,20
button #1.exit, "Save",[save],LR,30,30,55,35 open "Splash Screen" for window as #1
print #1.1, value1$ print #1.2, value2$ print #1.3, value3$
UpperLimit = 1460 LowerLimit = 1 CurrentPosition = 1 hWnd = hWnd(#1) hText = hWnd(#1.1)
UDS.ARROWKEYS = hexdec("20") UDS.WRAP = hexdec("1") UDS.SETBUDDYINT = hexdec("2") UDS.ALIGNRIGHT = hexdec("4") dwStyle = _WS_CHILD or _WS_BORDER or _WS_VISIBLE or UDS.ARROWKEYS or UDS.WRAP or UDS.SETBUDDYINT or UDS.ALIGNRIGHT
hSpinner = CreateSpinner(hWnd, dwStyle, hText, UpperLimit, LowerLimit, CurrentPosition)
wait
[save] 'get texbox content #1.1 "!contents? value1$" #1.2 "!contents? value2$" #1.3 "!contents? value3$" 'save textbox content open "savedData.txt" for output as #3 print #3,value1$ print #3,value2$ print #3,value3$ close #3 '------------------------- wait
Function CreateSpinner(hWnd, style, hTxt, upr, lwr, pos) CallDLL #comctl32, "InitCommonControlsEx",_ re as void
CallDLL #user32, "GetWindowLongA",_ hWnd as ulong,_ _GWL_HINSTANCE as long,_ hInst as ulong
CallDLL #comctl32, "CreateUpDownControl",_ style as ulong,_ x as long,_ y as long,_ w as long,_ h as long,_ hWnd as ulong,_ id as long,_ hInst as ulong,_ hTxt as ulong,_ upr as long,_ lwr as long,_ pos as long,_ CreateSpinner as ulong End Function
|
|
|
Post by tsh73 on Nov 20, 2019 9:08:15 GMT -5
Try to move
print #1.1, value1$ (setting data to spinner)
after
hSpinner = CreateSpinner(hWnd, dwStyle, hText, UpperLimit, LowerLimit, CurrentPosition) (creating spinner)
|
|
|
Post by wexhammer on Nov 20, 2019 12:31:12 GMT -5
Thank you! One last question i hope.... i am trying to add both value1$ and value2$ together and print the total in the 3rd text box, however its placing the numbers together and not adding them up. For example 22+22 should equal 44 but my code instead gives a value of 2222. Were am i going wrong?
nomainwin
UpperLeftX = 250
UpperLeftY = 100
WindowWidth = 400
WindowHeight = 450
'make sure file exists
open "savedData.txt" for append as #3
close #3
'read from file
open "savedData.txt" for input as #3
if not(eof(#3)) then
line input #3,value1$
line input #3,value2$
end if
close #3
textbox #1.1, 90, 20, 40,20
textbox #1.2, 90, 110, 40,20
textbox #1.3, 90, 210, 40,20
button #1.exit, "Save",[save],LR,30,30,55,35
open "Splash Screen" for window as #1
UpperLimit = 1460
LowerLimit = 1
CurrentPosition = 1
hWnd = hWnd(#1)
hText = hWnd(#1.1)
UDS.ARROWKEYS = hexdec("20")
UDS.WRAP = hexdec("1")
UDS.SETBUDDYINT = hexdec("2")
UDS.ALIGNRIGHT = hexdec("4")
dwStyle = _WS_CHILD or _WS_BORDER or _WS_VISIBLE or UDS.ARROWKEYS or UDS.WRAP or UDS.SETBUDDYINT or UDS.ALIGNRIGHT
hSpinner = CreateSpinner(hWnd, dwStyle, hText, UpperLimit, LowerLimit, CurrentPosition)
UpperLimit = 1460
LowerLimit = 1
CurrentPosition = 1
hWnd = hWnd(#1)
hText = hWnd(#1.2)
UDS.ARROWKEYS = hexdec("20")
UDS.WRAP = hexdec("1")
UDS.SETBUDDYINT = hexdec("2")
UDS.ALIGNRIGHT = hexdec("4")
dwStyle = _WS_CHILD or _WS_BORDER or _WS_VISIBLE or UDS.ARROWKEYS or UDS.WRAP or UDS.SETBUDDYINT or UDS.ALIGNRIGHT
hSpinner = CreateSpinner(hWnd, dwStyle, hText, UpperLimit, LowerLimit, CurrentPosition)
print #1.1, value1$
print #1.2, value2$
'i want to add value1 and 2 together as if it were a proper addition calculation
print #1.3, value1$ + value2$
wait
[save]
'get texbox content
#1.1 "!contents? value1$"
#1.2 "!contents? value2$"
#1.3 "!contents? value3$"
'save textbox content
open "savedData.txt" for output as #3
print #3,value1$
print #3,value2$
print #3,value3$
close #3
'-------------------------
wait
Function CreateSpinner(hWnd, style, hTxt, upr, lwr, pos)
CallDLL #comctl32, "InitCommonControlsEx",_
re as void
CallDLL #user32, "GetWindowLongA",_
hWnd as ulong,_
_GWL_HINSTANCE as long,_
hInst as ulong
CallDLL #comctl32, "CreateUpDownControl",_
style as ulong,_
x as long,_
y as long,_
w as long,_
h as long,_
hWnd as ulong,_
id as long,_
hInst as ulong,_
hTxt as ulong,_
upr as long,_
lwr as long,_
pos as long,_
CreateSpinner as ulong
End Function
|
|
|
Post by tsh73 on Nov 20, 2019 12:42:16 GMT -5
You should convert string ("22") to number (22) with VAL function. Numbers will add properly.
print "22"+"22" 'gives 2222 print val("22")+val("22") 'gives 44
|
|
|
Post by wexhammer on Nov 20, 2019 14:11:29 GMT -5
I would like to times a value against the total of the two added strings, this code below doesn't seem to work... How would i go about this? Its giving me the wrong total eg: 5 + 5: 10 x 9 should equal 90 but its not.
print #1.3, val(value1$) + val(value2$) * val("9")
|
|
|
Post by Chris Iverson on Nov 20, 2019 14:18:32 GMT -5
Mathematical evaluation is based on the mathematical order of operations. Multiplication and division are evaluated before addition and subtraction.
5 + 5 * 9 is evaluated as (5 * 9) = 45 + 5 = 50.
If you want it to explicitly be evaluated left-to-right, use parenthesis.
(5 + 5) * 9 will give 90, as you expected.
|
|
|
Post by wexhammer on Nov 20, 2019 14:32:41 GMT -5
Its giving me a total beyond expected now... Is this correct because its now not giving me the correct total still.
print #1.3, val(value1$ + value2$) * val("9")
nomainwin UpperLeftX = 250 UpperLeftY = 100 WindowWidth = 400 WindowHeight = 450
'make sure file exists open "savedData.txt" for append as #3 close #3 'read from file open "savedData.txt" for input as #3 if not(eof(#3)) then line input #3,value1$ line input #3,value2$
end if close #3
textbox #1.1, 90, 20, 40,20 textbox #1.2, 90, 110, 40,20 textbox #1.3, 90, 210, 40,20
button #1.exit, "Save",[save],LR,30,30,55,35 open "Splash Screen" for window as #1
UpperLimit = 1460 LowerLimit = 1 CurrentPosition = 1 hWnd = hWnd(#1) hText = hWnd(#1.1)
UDS.ARROWKEYS = hexdec("20") UDS.WRAP = hexdec("1") UDS.SETBUDDYINT = hexdec("2") UDS.ALIGNRIGHT = hexdec("4") dwStyle = _WS_CHILD or _WS_BORDER or _WS_VISIBLE or UDS.ARROWKEYS or UDS.WRAP or UDS.SETBUDDYINT or UDS.ALIGNRIGHT
hSpinner = CreateSpinner(hWnd, dwStyle, hText, UpperLimit, LowerLimit, CurrentPosition)
UpperLimit = 1460 LowerLimit = 1 CurrentPosition = 1 hWnd = hWnd(#1) hText = hWnd(#1.2)
UDS.ARROWKEYS = hexdec("20") UDS.WRAP = hexdec("1") UDS.SETBUDDYINT = hexdec("2") UDS.ALIGNRIGHT = hexdec("4") dwStyle = _WS_CHILD or _WS_BORDER or _WS_VISIBLE or UDS.ARROWKEYS or UDS.WRAP or UDS.SETBUDDYINT or UDS.ALIGNRIGHT
hSpinner = CreateSpinner(hWnd, dwStyle, hText, UpperLimit, LowerLimit, CurrentPosition)
print #1.1, value1$ print #1.2, value2$
'i want to add value1 and 2 together as if it were a proper addition calculation print #1.3, val(value1$ + value2$) * val("9")
wait
[save] 'get texbox content #1.1 "!contents? value1$" #1.2 "!contents? value2$" #1.3 "!contents? value3$" 'save textbox content open "savedData.txt" for output as #3 print #3,value1$ print #3,value2$ print #3,value3$ close #3 '------------------------- wait
Function CreateSpinner(hWnd, style, hTxt, upr, lwr, pos) CallDLL #comctl32, "InitCommonControlsEx",_ re as void
CallDLL #user32, "GetWindowLongA",_ hWnd as ulong,_ _GWL_HINSTANCE as long,_ hInst as ulong
CallDLL #comctl32, "CreateUpDownControl",_ style as ulong,_ x as long,_ y as long,_ w as long,_ h as long,_ hWnd as ulong,_ id as long,_ hInst as ulong,_ hTxt as ulong,_ upr as long,_ lwr as long,_ pos as long,_ CreateSpinner as ulong End Function
|
|
|
Post by Chris Iverson on Nov 20, 2019 14:37:39 GMT -5
Sorry, wasn't clear about that.
I meant this:
print #1.3, (val(value1$) + val(value2$)) * val("9")
The problem with what you've done is, if you fill the variables in, it executes like this:
val("5" + "5") * val("9")
'"5" + "5" = "55"
val("55") * val("9")
55 * 9 = 495
|
|
|
Post by wexhammer on Nov 20, 2019 14:50:57 GMT -5
Thanks! Also one last bit of help needed i am sure! I have a bmp image integrated within the window and i would like the bmp to appear if my total in the third textbox is over 100. And if its under 100 to not appear. How would i go about this?
nomainwin UpperLeftX = 250 UpperLeftY = 100 WindowWidth = 400 WindowHeight = 450
'make sure file exists open "savedData.txt" for append as #3 close #3 'read from file open "savedData.txt" for input as #3 if not(eof(#3)) then line input #3,value1$ line input #3,value2$
end if close #3
textbox #1.1, 90, 20, 40,20 textbox #1.2, 90, 110, 40,20 textbox #1.3, 90, 210, 40,20
button #1.exit, "Save",[save],LR,30,30,55,35 bmpbutton #1.ico "a.bmp", [aclick], UR, 200, 55 open "Splash Screen" for window as #1
#1.ico "hide"
UpperLimit = 1460 LowerLimit = 1 CurrentPosition = 1 hWnd = hWnd(#1) hText = hWnd(#1.1)
UDS.ARROWKEYS = hexdec("20") UDS.WRAP = hexdec("1") UDS.SETBUDDYINT = hexdec("2") UDS.ALIGNRIGHT = hexdec("4") dwStyle = _WS_CHILD or _WS_BORDER or _WS_VISIBLE or UDS.ARROWKEYS or UDS.WRAP or UDS.SETBUDDYINT or UDS.ALIGNRIGHT
hSpinner = CreateSpinner(hWnd, dwStyle, hText, UpperLimit, LowerLimit, CurrentPosition)
UpperLimit = 1460 LowerLimit = 1 CurrentPosition = 1 hWnd = hWnd(#1) hText = hWnd(#1.2)
UDS.ARROWKEYS = hexdec("20") UDS.WRAP = hexdec("1") UDS.SETBUDDYINT = hexdec("2") UDS.ALIGNRIGHT = hexdec("4") dwStyle = _WS_CHILD or _WS_BORDER or _WS_VISIBLE or UDS.ARROWKEYS or UDS.WRAP or UDS.SETBUDDYINT or UDS.ALIGNRIGHT
hSpinner = CreateSpinner(hWnd, dwStyle, hText, UpperLimit, LowerLimit, CurrentPosition)
print #1.1, value1$ print #1.2, value2$
'i want to add value1 and 2 together as if it were a proper addition calculation print #1.3, (val(value1$) + val(value2$)) * val("10")
wait
[save] 'get texbox content #1.1 "!contents? value1$" #1.2 "!contents? value2$" #1.3 "!contents? value3$" 'save textbox content open "savedData.txt" for output as #3 print #3,value1$ print #3,value2$ print #3,value3$ close #3 '------------------------- wait
Function CreateSpinner(hWnd, style, hTxt, upr, lwr, pos) CallDLL #comctl32, "InitCommonControlsEx",_ re as void
CallDLL #user32, "GetWindowLongA",_ hWnd as ulong,_ _GWL_HINSTANCE as long,_ hInst as ulong
CallDLL #comctl32, "CreateUpDownControl",_ style as ulong,_ x as long,_ y as long,_ w as long,_ h as long,_ hWnd as ulong,_ id as long,_ hInst as ulong,_ hTxt as ulong,_ upr as long,_ lwr as long,_ pos as long,_ CreateSpinner as ulong End Function
|
|
|
Post by tsh73 on Nov 20, 2019 15:00:57 GMT -5
Make it simple.
op1=val(value1$) op2=val(value2$) op3=9 res=(op1+op2)*op3 print #1.3, res
|
|