|
Post by wexhammer on Nov 22, 2019 16:45:05 GMT -5
Hello again... Basically in my textbox #1.1 when i press the plus button the days go up. I have automatically set a timer to constantly check that if equal to or greater than Day 3 appears within this textbox, the graphics box in the window which is default grey changes to green. It works, however a few problems i have with my code, one being when i constantly press that plus button and it reaches day 10 the color changes back to grey. I want it to remain green as my code lays out if greater or equal to day 3 then stay green. Were am i going wrong? also when i close the program i get error message.
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
button #1.plus, "+", [plus], LR, 50, 330, 60, 30
button #1.check, "CHECK", [check], LR 50, 250, 60, 30
graphicbox #1.box, 50, 290, 60, 60
open "Splash Screen" for window as #1
#1.box "down; fill Lightgray; flush"
print #1.1, value1$
print #1.2, value2$
if num >= 100 then
#1.1 "!hide"
else
#1.2 "!show"
end if
timer 400, [check]
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
[plus]
#1.1, "!contents? val3$"
if trim$(val3$) = "" then
val3=0
else
val3=val(word$(val3$,2))
end if
val3=val3+1
print #1.1, "Day ";val3
wait
[check]
#1.1, "!contents? val3$"
if val3$ >= "Day 3" then
#1.box "down; fill Green; flush"
else
#1.box "down; fill Lightgray; flush"
end if
wait
|
|
|
Post by tsh73 on Nov 22, 2019 17:32:51 GMT -5
Compare with your code, there are comments
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 button #1.plus, "+", [plus], LR, 50, 330, 60, 30 button #1.check, "CHECK", [check], LR 50, 250, 60, 30 graphicbox #1.box, 50, 290, 60, 60
open "Splash Screen" for window as #1 #1 "trapclose [quit]" 'add TRAPCLOSE STATEMENT #1.box "down; fill Lightgray; flush" print #1.1, value1$ print #1.2, value2$ if num >= 100 then #1.1 "!hide" else #1.2 "!show" end if timer 400, [check] 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 [plus] #1.1, "!contents? val3$" if trim$(val3$) = "" then val3=0 else val3=val(word$(val3$,2)) end if val3=val3+1 print #1.1, "Day ";val3 wait
[check] #1.1, "!contents? val3$" 'if val3$ >= "Day 3" then 'no good 'should get number and compare a number, not strings val3=val(word$(val3$,2)) if val3 >= 3 then #1.box "down; fill Green; flush" else #1.box "down; fill Lightgray; flush" end if wait
[quit] 'closing routine referred in TRAPCLOSE timer 0 'set timer off, just for a case close #1
|
|
|
Post by wexhammer on Nov 23, 2019 2:38:49 GMT -5
Thanks, my understanding is now broadening. I have added another graphics box so now there are two. When my textbox value hits Day 3 or above the graphic box 1 changes green and remains green which is perfect. I have added code so when i keep pressing the plus button once the textbox detects Day 6 in it the second graphics box i have added changes to green. However its not? I am aiming for the first box to stay green as day 3 or above has been detected, but once i hit day 6 i still want my first graphics box to remain green and the second box to change to green, and therefor both remain green. The code doesn't seem to work?
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
button #1.plus, "+", [plus], LR, 50, 330, 60, 30
button #1.check, "CHECK", [check], LR 50, 250, 60, 30
graphicbox #1.box, 50, 290, 60, 60 graphicbox #1.box2, 70, 340, 60, 60
open "Splash Screen" for window as #1
#1.box "down; fill Lightgray; flush"
#1.box "down; fill Lightgray; flush"
print #1.1, value1$
print #1.2, value2$
if num >= 100 then
#1.1 "!hide"
else
#1.2 "!show"
end if
timer 400, [check]
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
[plus]
#1.1, "!contents? val3$"
if trim$(val3$) = "" then
val3=0
else
val3=val(word$(val3$,2))
end if
val3=val3+1
print #1.1, "Day ";val3
wait
[check]
#1.1, "!contents? val3$" val3=val(word$(val3$,2)) if val3 >= 3 then #1.box "down; fill Green; flush" else #1.box "down; fill Lightgray; flush" end if
#1.1, "!contents? val3$" val3=val(word$(val3$,2)) if val3 >= 6 then #1.box2 "down; fill Green; flush" else #1.box2 "down; fill Lightgray; flush" end if
wait
[quit] timer 0 close #1
|
|
|
Post by Rod on Nov 23, 2019 3:36:33 GMT -5
The code works for me and the logic is ok.
|
|
|
Post by Rod on Nov 23, 2019 4:08:46 GMT -5
When I say the logic was ok I meant it worked. To make it all work better have a look at this. There are two main changes. The first is to properly check for the files existence, if it isn't found it can be created or you can use startup data. The second is to stop redrawing the colored boxes every 400ms The timer loops so you are creating unnecessary processing and drawing. You can change that by using the plus button as the trigger to check. This code dispenses with the timer and simply falls through to [check] If you put a minus button in, send it to [check] once you have completed the decrement.
The main point is that you don't need the timer, just react to any user input and do the checks in response to that.
dim info$(10, 10)
'make sure file exists if fileExists(DefaultDir$,"savedData.txt") then 'we found the file ,read it else dummy data open "savedData.txt" for input as #3 'if it has content read it else dummy data if not(eof(#3)) then line input #3,value1$ line input #3,value2$ else value1$="Day 0" value2$="Day 1" end if close #3 else value1$="Day 0" value2$="Day 1" end if
nomainwin UpperLeftX = 250 UpperLeftY = 100 WindowWidth = 400 WindowHeight = 450 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 button #1.plus, "+", [plus], LR, 50, 330, 60, 30 button #1.check, "CHECK", [check], LR 50, 250, 60, 30 graphicbox #1.box, 50, 290, 60, 60 graphicbox #1.box2 150,290,60,60 open "Splash Screen" for window as #1 #1 "trapclose [quit]" #1.box "down; fill Lightgray; flush" #1.box2 "down; fill lightgray; flush" #1.1 value1$ #1.2 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 #3 value1$ #3 value2$ #3 value3$ close #3 wait
[plus] #1.1 "!contents? val3$" if trim$(val3$) = "" then val3=0 else val3=val(word$(val3$,2)) end if val3=val3+1 #1.1 "Day ";val3
[check] #1.1 "!contents? val3$" if val3$ >= "Day 3" then #1.box "down; fill Green; flush" if val3$ >= "Day 6" then #1.box2 "down; fill Green; flush" else #1.box2 "down; fill Lightgray; flush" end if else #1.box "down; fill Lightgray; flush" end if wait
[quit] timer 0 close #1 end
function fileExists(path$, filename$) 'dimension the array info$( at the beginning of your program files path$, filename$, info$() fileExists = val(info$(0, 0)) 'non zero is true end function
|
|
|
Post by wexhammer on Nov 23, 2019 4:31:35 GMT -5
Ok Perfect, however there still seems to be a problem. When hit hits day 10 the boxes go back to grey, seems like its detecting 10 as 1 again?
|
|
|
Post by Rod on Nov 23, 2019 10:14:47 GMT -5
Yep, because you are mixing text and numbers so "Day 10" is not alphabetically greater than "Day 3"
Try a different strategy if you must mix text and numbers get the value of the number.
print "Day 10" > "Day 3" v=val(word$("Day 10",2)) print v>3
better still if it is numeric store it as numeric so don't mix "day" and "1"
Consider statictext to show your "Day" label.
|
|
|
Post by wexhammer on Nov 23, 2019 11:29:01 GMT -5
Ok, i have decided to opt in for the static text option instead. Copied the code and input the static text #name, and now its giving me an error.
dim info$(10, 10)
'make sure file exists
if fileExists(DefaultDir$,"savedData.txt") then
'we found the file ,read it else dummy data
open "savedData.txt" for input as #3
'if it has content read it else dummy data
if not(eof(#3)) then
line input #3,value1$
line input #3,value2$
else
value1$="Day 0"
value2$="Day 1"
end if
close #3
else
value1$="Day 0"
value2$="Day 1"
end if
nomainwin
UpperLeftX = 250
UpperLeftY = 100
WindowWidth = 400
WindowHeight = 450
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
button #1.plus, "+", [plus], LR, 50, 330, 60, 30
button #1.check, "CHECK", [check], LR 50, 250, 60, 30
statictext #1.day, "Day", 90, 70, 25, 20
statictext #1.daynum, "0", 115, 70, 25, 20
graphicbox #1.box, 50, 290, 60, 60
graphicbox #1.box2 150,290,60,60
open "Splash Screen" for window as #1
#1 "trapclose [quit]"
#1.box "down; fill Lightgray; flush"
#1.box2 "down; fill lightgray; flush"
#1.1 value1$
#1.2 value2$
wait
[save]
'get texbox content
#1.daynum "!contents? value1$"
#1.2 "!contents? value2$"
#1.3 "!contents? value3$"
'save textbox content
open "savedData.txt" for output as #3
#3 value1$
#3 value2$
#3 value3$
close #3
wait
[plus]
#1.daynum "!contents? val3$"
if trim$(val3$) = "" then
val3=0
else
val3=val(word$(val3$,2))
end if
val3=val3+1
#1.1 "Day ";val3
[check]
#1.daynum "!contents? val3$"
if val3$ >= "Day 3" then
#1.box "down; fill Green; flush"
if val3$ >= "Day 6" then
#1.box2 "down; fill Green; flush"
else
#1.box2 "down; fill Lightgray; flush"
end if
else
#1.box "down; fill Lightgray; flush"
end if
wait
[quit]
timer 0
close #1
end
function fileExists(path$, filename$)
'dimension the array info$( at the beginning of your program
files path$, filename$, info$()
fileExists = val(info$(0, 0)) 'non zero is true
end function
<span style="font-family: Verdana, Arial; font-size: 10pt;"></span>
|
|
|
Post by wexhammer on Nov 23, 2019 13:51:47 GMT -5
All Fixed Now
|
|
|
Post by wexhammer on Nov 24, 2019 12:01:42 GMT -5
How would i find value between? For instance anything in between 400 & 600 range, trigger the graphics box to change color? I think i have got it terribly wrong.
#main.textbox12 "!contents? num" if num <> 400 or 600 or hen #main.test1 "down; fill Cyan; flush" else #main.test1 "down; fill Lightgray; flush" end if
|
|
|
Post by tsh73 on Nov 24, 2019 14:25:52 GMT -5
It should be
if 400 <= num and num < 600 then
|
|