Post by Rod on Jan 12, 2022 6:14:39 GMT -5
Ken, the code as presented will not crash mainly because of modal, so you have shown the one instance where you might WAIT in a sub. But did you do it intentionally with full knowledge of the risk? The issue is that it can become extremely complex to manage events in a large program. You must enter that Sub entirely sure that all other events are off. For example if there were a Timer outstanding, a Mouse handler outstanding even Trapclose events catch folks out.
Here I just add a timer to fire an event while you are waiting. I have started another thread because it is an interesting subject and often catches other coders out.
Here I just add a timer to fire an event while you are waiting. I have started another thread because it is an interesting subject and often catches other coders out.
'----- Pre-window set up
nomainwin
WindowWidth = 1400
WindowHeight = 722
UpperLeftX = int((DisplayWidth-WindowWidth)/2)
UpperLeftY = int((DisplayHeight-WindowHeight)/2)
MWW = 1400
MWH = 722
BackgroundColor$ = "lightgray"
ForegroundColor$ = "black"
TextboxColor$ = "white"
global BadInfo
global MWW
global MWH
dim BldgInfo(4, 10)
dim RftrInfo(4, 1000)
dim group(4)
'----- Calculate button moved here to make it the last control in the tabbing order
button #main.calc0, "Calculate", [GetInfo], UL, 1120, 602, 245, 60
'----- Open main window
open "Rafter Master" for window_nf as #main
print #main, "font ms_sans_serif 10"
print #main.calc0, "!font ms_sans_serif 20 bold"
print #main, "trapclose [quit.main]"
timer 3000,[errorout]
call instruct
call numFormat
'----- Wait for "instant" input or calculate button to be clicked
[main.inputLoop]
if BadInfo = 1 then
x = 0
y = 0
end if
wait
[GetInfo]
wait
'----- End the program
[quit.main]
close #main
end
sub instruct
'----- Pre-window set up
nomainwin
WindowWidth = 550
WindowHeight = 445
UpperLeftX = int((MWW - WindowWidth) / 2)
UpperLeftY = int((MWH - WindowHeight) / 2)
'----- Information to be displayed
button #Instruct.button1,"GOT IT ",[quit.instruct], UL, 455, 380, 70, 25
statictext #Instruct.statictext1, "ALL ROOF PITCHES MUST MATCH! ALL WALL HEIGHTS MUST MATCH!", 5, 5, 525, 20
statictext #Instruct.statictext2, "If there is enough interest, these features may be added at a later time", 5, 35, 450, 20
statictext #Instruct.statictext3, "This program will calculate rafter, ridge, hip and valley lengths.", 5, 75, 490, 20
statictext #Instruct.statictext4, "It will also calculate the following jack rafter lengths:", 5, 105, 325, 20
statictext #Instruct.statictext5, "Ridge to Valley, Hip to Wall, Hip to Valley and Ridge to Ridge.", 5, 135, 400, 20
' statictext #Instruct.statictext6, "When inputting measurements, the following conventions must be followed:", 5, 175, 450, 20
' statictext #Instruct.statictext7, "Feet and inches must be separated with a dash, (e.g. 19-6).", 5, 205, 570, 20
' statictext #Instruct.statictext8, "Foot, ('), and inch, (" + chr$(34) + "), marks are allowed, (e.g. 19'-6" + chr$(34) + "), but are not required.", 5, 235, 500, 20
' statictext #Instruct.statictext9, "Use of the foot mark, (') does not require use of the inch mark, (e.g. 19'-6).", 5, 265, 520, 20
' statictext #Instruct.statictext10, "Fractional inches must be separated from whole inches with a space, (e.g. 19-6 3/8).", 5, 295, 530, 20
' statictext #Instruct.statictext11, "Decimal inches require a decimal point, (e.g. 19-6.375).", 5, 325, 450, 20
' statictext #Instruct.statictext12, "Ridge Width must be expressed as inches only, (e.g. 1 1/2 or 1.5).", 5, 355, 450, 20
' statictext #Instruct.statictext13, "Roof pitch must be expressed as a fraction, Rise / Run, (e.g. 6/12).", 5, 385, 450, 20
'----- Open "about" window
open "About Rafter Master" for dialog_modal as #Instruct
print #Instruct, "font times_new_roman 12"
print #Instruct, "trapclose [quit.instruct]"
'----- Wait here for button click
[Instruct.inputLoop]
wait
'----- Close "about" window
[quit.instruct]
close #Instruct
end sub
'----- Explain measurement entry formatting
sub numFormat
'-----Pre-window set up
nomainwin
WindowWidth = 675
WindowHeight = 420
UpperLeftX = int((MWW - WindowWidth) / 2)
UpperLeftY = int((MWH - WindowHeight) / 2)
'----- Information to display
button #Format.button1,"GOT IT ",[quit.format], UL, 565, 340, 90, 35
'statictext #Format.statictext1, "ALL ROOF PITCHES MUST MATCH! ALL WALL HEIGHTS MUST MATCH!", 5, 5, 525, 20
'statictext #Format.statictext2, "If there is enough interest, these features may be added at a later time", 5, 35, 450, 20
'statictext #Format.statictext3, "This program will calculate rafter, ridge, hip and valley lengths.", 5, 75, 490, 20
'statictext #Format.statictext4, "It will also calculate the following jack rafter lengths:", 5, 105, 325, 20
'statictext #Format.statictext5, "Ridge to Valley, Hip to Wall, Hip to Valley and Ridge to Ridge.", 5, 135, 400, 20
statictext #Format.statictext6, "When inputting measurements, the following conventions must be followed:", 5, 5, 600, 30
statictext #Format.statictext7, "Feet and inches must be separated with a dash, (e.g. 19-6).", 5, 55, 670, 30
statictext #Format.statictext8, "Foot, ('), and inch, (" + chr$(34) + "), marks are allowed, (e.g. 19'-6" + chr$(34) + "), but are not required.", 5, 105, 600, 30
statictext #Format.statictext9, "Use of the foot mark, (') does not require use of the inch mark, (e.g. 19'-6).", 5, 155, 620, 20
statictext #Format.statictext10, "Fractional inches must be separated from whole inches with a space, (e.g. 19-6 3/8).", 5, 205, 630, 20
statictext #Format.statictext11, "Decimal inches require a decimal point, (e.g. 19-6.375).", 5, 255, 550, 20
statictext #Format.statictext12, "Ridge Width must be expressed as inches only, (e.g. 1 1/2 or 1.5).", 5, 305, 550, 20
statictext #Format.statictext13, "Roof pitch must be expressed as a fraction, Rise / Run, (e.g. 6/12).", 5, 355, 550, 20
'----- Open format window
open "Rafter Master Format Assistant" for dialog_modal as #Format
print #Format, "font times_new_roman 14"
'print #Format.button1, "!font times_new_roman 12"
print #Format, "trapclose [quit.format]"
'----- Wait for button click
[format.inputLoop]
wait
'----- Close format window
[quit.format]
close #Format
end sub