|
Post by johnking on Mar 15, 2024 5:35:06 GMT -5
I am using some very basic lines to ask a user for input using PROMPT I would like to have the PROMPT window at the same position every time (here x=200, y=400) With locate before the PROMPT command the window shifts every time to the right and below
I expect it might be caused because the locate command does not refer to pixels but to lines and colums But I cannot find the solution
So how can I get the PROMPT window on the same postion every time? Below parts of the code
OPEN menutekst$ for Text as #main
PRINT #main, "!Trapclose [EndProgram]"
PRINT #main, "!cls" ;
WAIT
[Starttest]
[temperatuurvoor]
temperatuurvoor=23.0
locate 200,400
prompt "Temperatuur voor meting [20..26 gr.C)/0=stop";temperatuurvoor
if temperatuurvoor=0 then close #main
if temperatuurvoor=0 then goto [Startprogramma]
if temperatuurvoor <20 goto [temperatuurvoor]
if temperatuurvoor >26 goto [temperatuurvoor]
[luchtvochtigheidvoor]
luchtvochtigheidvoor=50.0
locate 200,400
prompt "Luchtvochtigheid voor meting [25..70 %)/0=stop";luchtvochtigheidvoor
if luchtvochtigheidvoor=0 then close #main
if luchtvochtigheidvoor=0 then goto [Startprogramma]
if luchtvochtigheidvoor <25 goto [luchtvochtigheidvoor]
if luchtvochtigheidvoor >70 goto [luchtvochtigheidvoor]
[luchtdrukvoor]
luchtdrukvoor=1013.5
locate 200,400
prompt "Luchtdruk voor meting [800..1050 hPa)/0=stop";luchtdrukvoor
if luchtdrukvoor=0 then close #main
if luchtdrukvoor=0 goto [Startprogramma]
if luchtdrukvoor <800 goto [luchtdrukvoor]
if luchtdrukvoor >1050 goto [luchtdrukvoor]
|
|
|
Post by tsh73 on Mar 15, 2024 5:47:02 GMT -5
Locate does not affect where PROMPT appears, at all (or at least should not) - as you use it, it affects PRINT position in a Mainwin.
Make your own window (probably Dialog window) and use it instead of PROMPT.
|
|
|
Post by tsh73 on Mar 15, 2024 6:41:10 GMT -5
Try these functions.
'problem to be solved: 'sequential propmts migrate over desktop 'We want it to appear at UpperLeftX, UpperLeftY nomainwin
UpperLeftX=200 UpperLeftY=400
res$ = customPrompt$("", "", "") notice ">";res$;"<"
res$ = customPrompt$("", "Temperatuur voor meting [20..26 gr.C)/0=stop", "23.5") notice ">";res$;"<"
res$ = customPrompt$("Temperature", "Temperatuur voor meting [20..26 gr.C)/0=stop", "23.5") notice ">";res$;"<"
'now with numbers res = customPrompt("as a number", "Temperatuur voor meting [20..26 gr.C)/0=stop", 23.5) notice ">";res+0.0001;"<" 'to show it's a number and we could add to it
function customPrompt(title$, prompt$, preSet) 'for numbers customPrompt=val(customPrompt$(title$, prompt$, str$(preSet))) end function
'for strings function customPrompt$(title$, prompt$, preSet$) 'auxiliary window to position dialog over it 'at UpperLeftX, UpperLeftY oldPosX=UpperLeftX oldPosY=UpperLeftY WindowWidth =1 'actually pretty invisble WindowHeight=1 open "Auxiliary window" for window_popup as #auxiliary
WindowWidth = 264 WindowHeight = 130 UpperLeftX =1 UpperLeftY =1
statictext #custPrompt.statictext1, prompt$, 6, 6, 232, 20 textbox #custPrompt.textbox2, 6, 26, 232, 25 button #custPrompt.Default, "OK", [OKClick], UL, 6, 61, 56, 25 button #custPrompt.Cancelbutton, "Cancel", [CancelClick], UL, 70, 61, 64, 25
open title$ for dialog_nf_modal as #custPrompt 'use dialog for Enter to work 'but it needs special things to position print #custPrompt, "trapclose [CancelClick]" 'restore position for the next time UpperLeftX=oldPosX UpperLeftY=oldPosY
print #custPrompt, "font ms_sans_serif 10"
#custPrompt.textbox2 preSet$
wait
[OKClick] 'OK button (or Enter) 'Insert your own code here #custPrompt.textbox2 "!contents? customPrompt$" close #custPrompt close #auxiliary exit function
[CancelClick] 'Cancel button (or ESC) (or window close) close #custPrompt close #auxiliary exit function end function
|
|
|
Post by Rod on Mar 15, 2024 9:36:10 GMT -5
An alternative approach.
' set up a small window in the middle of the screen nomainwin WindowWidth = 550 WindowHeight = 410 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
' set up the controls that will be displayed in the window statictext #main.t1, "Temperatuur voor meting [20..26 gr.C)", 80, 20, 244, 20 statictext #main.t2, "Luchtvochtigheid voor meting [25..70 %)", 80, 80, 244, 20 statictext #main.t2, "Luchtdruk voor meting [800..1050 hPa)", 80, 140, 244, 20 textbox #main.tb1, 80, 40, 100, 25 textbox #main.tb2, 80, 100, 100, 25 textbox #main.tb3, 80, 160, 100, 25
' put a button on the screen to action the input button #main.getinput,"Set",[getinput], UL, 80, 200, 60, 25
' open the window and set where it goes if the user closes it open "User Input" for window as #main #main "trapclose [quit]"
'put default values in textbox #main.tb1 "23.0" #main.tb2 "50%" #main.tb3 "1013.5"
'wait for user input or closure #main.tb1 "!setfocus" wait
' when the button is clicked this code is actioned [getinput] #main.tb1 "!contents? t1$" #main.tb2 "!contents? t2$" #main.tb3 "!contents? t3$"
'once you have the data do your range checks here notice "Result ";chr$(13);"Temperatuur ";t1$;chr$(13);"Luchtvochtigheid ";t2$;chr$(13);"Luchtdruk ";t3$ wait
' when the user closes the window this code is actioned [quit] close #main end
|
|
|
Post by johnking on Mar 15, 2024 9:49:36 GMT -5
Thank you both, I need to look into this further. User input like this is asked 15 times throughout the program. With the PROMPT method it is very simple, only a few lines of code, but with the unwanted result that the PROMPT windows location changes. The proposed methods mean a lot of extra coding lines which makes the program a lot more complicated as I have to insert this code each time input is asked. Perhaps I stick to the old method and accept the position issue as it is. Thanks for the help.
|
|
|
Post by tsh73 on Mar 15, 2024 13:24:23 GMT -5
The proposed methods mean a lot of extra coding lines which makes the program a lot more complicated as I have to insert this code each time input is asked.
No you copy/paste functions, once
function customPrompt(title$, prompt$, preSet) function customPrompt$(title$, prompt$, preSet$)
After that, instead of single line
prompt "Temperatuur voor meting [20..26 gr.C)/0=stop";temperatuurvoor you write another single line
temperatuurvoor = customPrompt("", "Temperatuur voor meting [20..26 gr.C)/0=stop", temperatuurvoor)
|
|
|
Post by Rod on Mar 16, 2024 4:41:01 GMT -5
Building on the use of controls offered by Liberty. Comboboxes restrict user choice and aid input.
' set up a small window in the middle of the screen nomainwin WindowWidth = 550 WindowHeight = 410 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2) dim t$(26) for t=20 to 26 t$(t)=str$(t) next dim h$(70) for h=25 to 70 step 5 h$(h)=str$(h) next dim m$(25) for m=0 to 25 m$(m)=str$(800+10*m) next
' set up the controls that will be displayed in the window statictext #main.t1, "Temperatuur voor meting [20..26 gr.C)", 80, 20, 244, 20 statictext #main.t2, "Luchtvochtigheid voor meting [25..70 %)", 80, 80, 244, 20 statictext #main.t2, "Luchtdruk voor meting [800..1050 hPa)", 80, 140, 244, 20 combobox #main.cb1, t$(, [settemp],80, 40, 100, 40 combobox #main.cb2, h$(, [sethumidity],80, 100, 100, 40 combobox #main.cb3, m$(, [setpressure],80, 160, 100, 40 button #main.getinput,"Set",[getinput], UL, 80, 200, 60, 25 open "User Input" for window as #main #main "trapclose [quit]"
'put default values in textbox #main.cb1 "select 23" #main.cb2 "select 50" #main.cb3 "select 1010"
'wait for user input or closure wait
' when the button is clicked this code is actioned [getinput] #main.cb1 "selection? t1$" #main.cb2 "selection? t2$" #main.cb3 "selection? t3$"
'once you have the data do your range checks here notice "Result ";chr$(13);"Temperatuur ";t1$;chr$(13);"Luchtvochtigheid ";t2$;chr$(13);"Luchtdruk ";t3$ wait
' when the user closes the window this code is actioned [quit] close #main end
|
|
|
Post by johnking on Mar 17, 2024 4:30:51 GMT -5
Correct tsh73, it is a function, my misinterpretation. Thank you Rod also.
|
|