kerry
Member in Training
Posts: 21
|
Post by kerry on Feb 29, 2020 0:26:27 GMT
Here is a piece of code that works perfectly when not run in a GUI. I can not seem to figure out the right way to use it in a window window or dialog window or do I need to use a different type of window?
print " The following is the information you provided:"
print
print " Gender: "; tab(30), genderword$
print " Type of drink: "; tab(30), drink$
print " Number of drinks: "; tab(30), number
print " Hours you drink: "; tab(30), using ("##.##", hours)
print " Your body weight: "; tab(30), weight
print " Hours before driving: "; tab(30), using ("##.##",delay)
print
|
|
|
Post by B+ on Feb 29, 2020 0:30:13 GMT
Yeah printing in windows is completely different than PRINT in mainwin.
Might want a texteditor control which is nice multi-line control box (that can easily be made into editor) for just showing a bunch of strings.
Your code looks like it best be used in a mainwin app. Otherwise you'd set up a textbox control for each of your inputs and use statictext controls to label the textboxes. The user would just go down the GUI form and fill out their answers and then click a button (button control) to process the contents of the textboxes. All the info they typed would be sitting before them so no need to review, they just click a button to process whatever you want to do with text box inputs.
BTW you can put all that info in a Notice (see help) form which is like a Windows message box that is displayed until user clicks OK but again you'd have to format the lines yourself by building up the string to display.
s$ = " The following is the information you provided:" + chr$(13) ' <<<< title first string spearted by CHR$(13) << line end and start new line s$ = s$ + " Gender: "; "male"; chr$(13) s$ = s$ +" Type of drink: "; "lemonade"; chr$(13) s$ = s$ + " Number of drinks: "; 1; chr$(13) s$ = s$ + " Hours you drink: "; .25 ;chr$(13) s$ = s$ + " Your body weight: "; "NOYB"; chr$(13) s$ = s$ +" Hours before driving: "; 0; chr$(13) notice s$
|
|
|
Post by B+ on Feb 29, 2020 1:43:48 GMT
And here's putting all that stuff in a texteditor with a label "Report" in a window you design:
nomainwin
WindowWidth = 560 WindowHeight = 410
UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
statictext #main.statictext1, "Report", 6, 11, 144, 20 texteditor #main.TE, 6, 31, 520, 300 open "textedit demo" for window as #main print #main, "trapclose [quit.main]" print #main, "font ms_sans_serif 16"
s$ = " The following is the information you provided:" + chr$(10) s$ = s$ + " Gender: "; "male"; chr$(10) s$ = s$ +" Type of drink: "; "lemonade"; chr$(10) s$ = s$ + " Number of drinks: "; 1; chr$(10) s$ = s$ + " Hours you drink: "; .25 ;chr$(10) s$ = s$ + " Your body weight: "; "NOYB"; chr$(10) s$ = s$ +" Hours before driving: "; 0; chr$(10) print #main.TE,"!contents s$";
wait
[quit.main] Close #main END
Here text lines end with CHR$(10) and this text is completely editable so user could correct (edit) the info theoretically.
|
|
kerry
Member in Training
Posts: 21
|
Post by kerry on Feb 29, 2020 1:47:57 GMT
Not sure you understand my intent here. In the first line I want to display the text "Gender" and then print the variable the genderword$ on the same line.
|
|
|
Post by B+ on Feb 29, 2020 1:57:12 GMT
Not sure you understand my intent here. In the first line I want to display the text "Gender" and then print the variable the genderword$ on the same line. I did. I just want to demo the NOTICE popup and the TextEditor control in a window so I plugged in values. Surely you know that if you don't want my first line in s$ you plug in your own, the same goes with all of s$.
|
|
|
Post by tsh73 on Feb 29, 2020 8:50:17 GMT
Yeah, nice one, B+ Couple of things. 1) you can write to texteditor just as to console, line by line. So instead of print " Gender: "; genderword$ you write print #main.TE, " Gender: "; genderword$ It works the same but might be easier to think of (like, "I do same printing") 2) BUT you cannot use TAB when printing to anything but console! Not in JB, anyway. So we have to make up something to get something like this print " Gender: "; tab(30), genderword$ For example, we could pad first line to 30 print #main.TE, rpad$(" Gender: ", 30); "male" where function rpad$(a$, n) 'adds a$ to n characters, adding spaces to the right 'so rpad$(a$, n);b$ is roughly the same as a$;tab(n);b$ rpad$=left$(a$+space$(n), n) 'it does truncate if len(a$)>n. You have been warned. end function
3) last thing, for words to align on 30 spaces you need to use monospaced font (like Courier, Lucida Console or Consolas). So print #main, "font courier_new 12" Final code nomainwin
statictext #main.statictext1, "Report", 6, 11, 144, 20 texteditor #main.TE, 6, 31, 520, 300 open "textedit demo" for window as #main print #main, "trapclose [quit.main]" print #main, "font courier_new 12"
print #main.TE, " The following is the information you provided:" print #main.TE, rpad$(" Gender: ", 30); "male" print #main.TE, rpad$(" Type of drink: ", 30); "lemonade" print #main.TE, rpad$(" Number of drinks: ", 30); 1 print #main.TE, rpad$(" Hours you drink: ", 30); .25 print #main.TE, rpad$(" Your body weight: ", 30); "NOYB" print #main.TE, rpad$(" Hours before driving: ", 30); 0
wait
[quit.main] Close #main END
function rpad$(a$, n) 'adds a$ to n characters, adding spaces to the right 'so rpad$(a$, n);b$ is roughly the same as a$;tab(n);b$ rpad$=left$(a$+space$(n), n) 'it does truncate if len(a$)>n. You have been warned. end function
|
|
kerry
Member in Training
Posts: 21
|
Post by kerry on Feb 29, 2020 14:16:24 GMT
Thanks much for the replies. This is what I came up with that fits what I was looking for. Also, just opened a window as window.
statictext #info.a, "Gender:", 10, 5, 60, 20 statictext #info.b genderword$, 300, 5, 30,20 statictext #info.c, "Type of drink: ", 10, 30, 90, 20 statictext #info.d, drink$, 300, 30, 60, 20 statictext #info.e, "Number of Drinks:", 10, 55, 200, 20 statictext #info.f, str$(number), 300, 55, 300, 20 statictext #info.g, "Hours you drank:", 10, 80, 200, 20 statictext #info.h, str$(hours), 300, 80, 300, 20 statictext #info.i, "Your body Weight:", 10, 105, 200, 20 statictext #info.j, str$(weight), 300, 105, 300, 20 statictext #info.k, "Hours before driving:", 10, 130, 200, 20 statictext #info.l, str$(delay), 300, 130, 300, 20
|
|
|
Post by Rod on Feb 29, 2020 15:01:34 GMT
Eventually you will progress from old style printing to using GUI style controls. Here is how it might look.
nomainwin 'set up arrays for comboboxes with preselected data gender$(1)="Male" gender$(2)="Female" drink$(1)="Beer" drink$(2)="Wine" drink$(3)="Spirits" drink$(4)="Cocktails" dim num$(20) for n= 1 to 20 num$(n)=str$(n) next dim kgs$(50) for n=1 to 20 kgs$(n)=str$(45+n*5)+" Kgs" next
'now establish all the controls we will use on the window statictext #1.st0 "Please provide the following information",20,10,200,25 statictext #1.st1 "Gender", 20,40,100,25 statictext #1.st2 "Type of drink", 20,70,100,25 statictext #1.st3 "Number of drinks", 20,100,100,25 statictext #1.st4 "Hours you drink", 20,130,100,25 statictext #1.st5 "Your weight (kgs)", 20,160,100,25 statictext #1.st6 "Hours before driving", 20,190,100,25 statictext #1.st7 "",20,220,260,25 combobox #1.cb1, gender$(),[gender],120, 40, 160, 25 combobox #1.cb2, drink$(),[drink],120, 70, 160, 25 combobox #1.cb3, num$(),[number],120, 100, 160, 25 combobox #1.cb4, num$(),[hours],120, 130, 160, 25 combobox #1.cb5, kgs$(),[weight],120, 160, 160, 25 combobox #1.cb6, num$(),[delay],120, 190, 160, 25 button #1.calc, "Calculate",[calculate],UL, 300,160,100,50 graphicbox #1.gb1, 300,40,100,100
'now open the window WindowWidth = 450 : WindowHeight = 300 open "Alcohol Test" for window as #1 #1 "trapclose [quit]"
'set the default display, could be blank to start #1.gb1 "down ; fill buttonface ; backcolor buttonface ;font comic sans 24" #1.gb1 "place 15 30 ;\BAC" #1.gb1 "place 10 80 ;\0.000" #1.cb1 "select Male" : gender=1 #1.cb2 "select Beer" : drink=.5 #1.cb3 "select 2" : number=2 #1.cb4 "select 1" : hours =1 #1.cb5 "select 85 Kgs" : weight=85 #1.cb6 "select 1" : delay=1
'now wait and see what the user does wait
[gender] 'set the gender value #1.cb1 "contents? gender$" if gender$="Male" then gender=1 else gender=.75 wait
[drink] 'set the unit alcohol value #1.cb2 "contents? drink$" select case drink$ case "Beer" drink=.5 case "Wine" drink=.5 case "Spirits" drink=1 case "Cocktails" drink=1.5 end select wait
[number] 'set the number of drinks consumed #1.cb3 "contents? num$" number=val(num$) wait
[hours] 'set the drinking period #1.cb4 "contents? hr$" hours=val(hr$) wait
[weight] 'set the weight in Kgs #1.cb5 "contents? kg$" weight=val(kg$) wait
[delay] 'set the delay till driving value #1.cb6 "contents? hr$" delay=val(hr$) wait
[calculate] 'this will not be correct, its just a semi working example Avolume = (drink * number) Wvolume = (weight * 0.453) Wvolume = Wvolume * gender bac = (Avolume / Wvolume) bac = bac / 10 bac = bac * 0.8065 bac = bac - (hours * 0.015) bac = bac - (delay * 0.015) select case case bac <= 0.0001 bac = 0.000 m$="EXCELLENT!" c$="green" case bac>0 and bac<.03 m$="NOT BAD!" c$="green" case bac>=.03 and bac<.05 m$="USE CAUTION!" c$="yellow" case bac>=.05 and bac<.79 m$="DO NOT GET BEHIND THE WHEEL!" c$="red" case bac>.079 m$="WALKING MIGHT BE DANGEROUS!" c$="red" end select 'show the results bac$=using("#.###",bac) #1.gb1 "cls ; fill ";c$ #1.gb1 "backcolor ";c$ #1.gb1 "place 15 30 ;\BAC" #1.gb1 "place 10 80 ;\";bac$ #1.st7 m$
'now wait for the user to make changes, recalculate or quit wait
[quit] close #1 end
|
|
|
Post by B+ on Feb 29, 2020 15:46:24 GMT
Ha, Rod! I was going to say kerry you are this close to a real GUI: nomainwin WindowWidth = 560 WindowHeight = 410 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
statictext #info.stGender, "Gender:", 10, 5, 190, 30 textbox #info.tbGender, 200, 5, 300, 30 statictext #info.stdrink, "Type of drink: ", 10, 55, 190, 30 textbox #info.tbdrink, 200, 55, 300, 30 statictext #info.stnumber, "Number of Drinks:", 10, 105, 190, 30 textbox #info.tbnumber, 200, 105, 300, 30 statictext #info.sthours, "Hours you drank:", 10, 155, 190, 30 textbox #info.tbhours, 200, 155, 300, 30 statictext #info.stweight, "Your body Weight:", 10, 205, 190, 30 textbox #info.tbweight, 200, 205, 300, 30 button #info.btCalc, "Calc Hours", [doCalc], ul, 10, 255, 500, 40 statictext #info.stHourslabel, "Hours before driving:", 100, 320, 190, 30 statictext #info.stHoursCalc, "N/A", 320, 320, 300, 30
open "kerry's window" for window as #info print #info, "trapclose [quit]" print #info, "font consolas 12"
wait
[doCalc] 'kerry put your calc code here for hours to wait before driving
#info.stHoursCalc, "Kerry's calc here" wait
[quit] close #info end
But Rod goes ahead and does a really great one!
|
|
|
Post by zzz000abc on Mar 6, 2020 1:08:47 GMT
hi here is a simple way use the functions in your program as shown here:
global grow,gcol,isopen,lmax grow=20:gcol=20 :isopen=0
'--------------------------------------------------------------------------------- genderword$="male" drink$="hot drinks" number=3 hours=21 weight=65 delay=4
t0$= " The following is the information you provided:" t1$= " Gender: " t2$= " Type of drink: " t3$= " Number of drinks: " t4$= " Hours you drink: " t5$= " Your body weight: " t6$= " Hours before driving: "
tt0$=" " tt1$=genderword$ tt2$= drink$ tt3$=str$(number) tt4$=using ("##.##", hours) tt5$=str$(weight) tt6$=using ("##.##",delay) '------------------------------------------------------------------------------------
l$=t1$+";"+t2$+";"+t3$+";"+t4$+";"+t5$+";"+t6$ 'list for left hand entries ll$=tt1$+";"+tt2$+";"+tt3$+";"+tt4$+";"+tt5$+";"+tt6$ 'list for right hand entries lmax=mxlen(l$,6) ' add title after using this function l$=t0$+";"+l$ :ll$=tt0$+";"+ll$ w=win1("g") 'use g for graphical window t for text window clr2$="darkblue" :clr1$="darkgray" for i=1 to 7 'number of entries including title is 7 in the example txt1$=word$(l$,i,";"):txt2$=word$(ll$,i,";") p=gprint(txt1$,txt2$,clr1$,clr2$,40) 'use gprint for graphical n tprint for text editor p=tprint(txt1$,txt2$,20) next wait [close1] close #1: end wait '----------------------------------functions -------------------------------------- function win1(type$) WindowWidth=DisplayWidth/2 :WindowHeight=DisplayHeight/2 if isopen>0 then isopen=0 :close #1 if type$="g" then open "grp" for graphics as #1 :isopen=1:t$="trapclose [close1]" if type$="t" then open "txt" for text as #1 :isopen =2:t$="!trapclose [close1]" #1,t$ win1=0 end function function gprint(txt1$,txt2$,clr1$,clr2$,s) if isopen<>1 then print "graphical window not defined":goto [nxt] grow=grow+0 : gcol=gcol+40:fs=16:t$="" for i=1 to lmax t$=t$+"w" next #1,"down;place ";grow;" ";gcol;";font mono ";fs #1,"color ";clr1$;";\";txt1$ #1,"stringwidth? t$ sw" #1,"place ";sw+s;" ";gcol #1,"color ";clr2$;";\";txt2$ [nxt] printg=0 end function function tprint(txt1$,txt2$,s) if isopen<>2 then print "text window not defined":goto [nxt] grow=grow+20 : gcol=gcol+20 #1,"";txt1$;space$(s);txt2$ [nxt] printg=0 end function function mxlen(s$,n) for i=1 to n lmax=max(len(word$(s$,i,";")),lmax) next mxlen=lmax end function
|
|