A Better Way?
		Post by CharlesB on Mar 13th, 2015, 8:24pm
		I have a menu of sorts in my program and the user must pick one option.
I looked at the tutorial and think that this "pick the number" method is the best, for I have two many options for the "hit an alpha key."
Yet, I think that you'll agree that this is awkward.
Does anyone have a better suggestion for me?
I think that this explains itself; the user is working a quotation program for tubing with cutting options.
Thanks.
I know that for even intermediate programmers this will seem very crude. 
               DEF PROC_AskForFeetOrPieces
        PRINT
        COLOUR(12)
        PRINT "This quotation is for 1) Normal uncut tubing footage?"
        PRINT "                      2) Saw-Cut Tubing in inch lengths?"
        PRINT "                      3) Saw-Cut Tubing in foot lengths?"
        PRINT "                      4) Core-Cut Tubing in inch lengths?"
        PRINT "                      5) Core-Cut Tubing in foot lengths?"
        PRINT "                      6) Lathe-Cut Tubing in inch lengths?"
        PRINT "                      7) Lathe-Cut Tubing in foot lengths?"
        PRINT "                      8) Other type of fabrication?"
        INPUT:
        COLOUR(0)
        FeetOrPieces$ = GET$
  
        FeetPieces% = VAL(FeetOrPieces$)
        IF FeetPieces%=0 THEN
          PRINT "Oops . . . try again"
        ENDIF
        ENDPROC
		
		
		Re: A Better Way?
		Post by Richey on Mar 13th, 2015, 9:31pm
		on Mar 13th, 2015, 8:24pm, CharlesB  wrote:| | I have a menu of sorts in my program and the user must pick one option. 
 I looked at the tutorial and think that this "pick the number" method is the best, for I have two many options for the "hit an alpha key."
 
 Yet, I think that you'll agree that this is awkward.
 Does anyone have a better suggestion for me?
 
 I think that this explains itself; the user is working a quotation program for tubing with cutting options.
 Thanks.
 I know that for even intermediate programmers this will seem very crude.
 
 
 DEF PROC_AskForFeetOrPieces
 PRINT
 COLOUR(12)
 PRINT "This quotation is for 1) Normal uncut tubing footage?"
 PRINT "                      2) Saw-Cut Tubing in inch lengths?"
 PRINT "                      3) Saw-Cut Tubing in foot lengths?"
 PRINT "                      4) Core-Cut Tubing in inch lengths?"
 PRINT "                      5) Core-Cut Tubing in foot lengths?"
 PRINT "                      6) Lathe-Cut Tubing in inch lengths?"
 PRINT "                      7) Lathe-Cut Tubing in foot lengths?"
 PRINT "                      8) Other type of fabrication?"
 INPUT:
 COLOUR(0)
 FeetOrPieces$ = GET$
 
 FeetPieces% = VAL(FeetOrPieces$)
 IF FeetPieces%=0 THEN
 PRINT "Oops . . . try again"
 ENDIF
 ENDPROC
 
 
 
 
 
 
 | 
 | 
Hi Charles
I'm a beginner myself but I think the CASE statement is probably an appropriate alternative for you to use when presenting a menu of different options:
See this chapter in the beginners tutorial - 
http://bbcbasic.co.uk/bbcwin/tutorial/chapter10.html
		
		
		Re: A Better Way?
		Post by CharlesB on Mar 14th, 2015, 03:08am
		Thanks Richey
		
		
		Re: A Better Way?
		Post by sveinioslo on Mar 18th, 2015, 11:41am
		It is a good investment to spend a few days into learning about dialog boxes.
From the manual:
"The WINLIB2 library contains a set of procedures and functions for creating and controlling custom dialogue boxes. These allow you to adopt the preferred Windows™ method of requesting input from the user."
Here you have three runnable examples, just to get you started.  
Svein
Using listbox:
 Code:      LB_GETCURSEL = 392
      LB_ADDSTRING = 384
      INSTALL @lib$+"winlib2"
      REM create dialogbox ----------------------------------------
      dlg% = FN_newdialog("Select cutting",100,100,180,120,8,500)
      PROC_listbox(dlg%,"",100,10,10,160,90,0)
      PROC_pushbutton(dlg%,"Ok",1,20,95,50,16,0)
      PROC_pushbutton(dlg%,"Cancel",2,110,95,50,16,0)
      PROC_showdialog(dlg%)
      REM create dialogbox ----------------------------------------
      REM fill listbox --------------------------------------------
      READ text$
      REPEAT
        SYS "SendDlgItemMessage", !dlg%, 100, LB_ADDSTRING, 0, text$
        READ text$
      UNTIL text$=".."
      REM fill listbox --------------------------------------------
      REM read user selection -------------------------------------
      Click% = 0
      ON SYS Click% = @wparam% : RETURN
      REPEAT WAIT 1
        click% = 0
        SWAP click%,Click%
        IF click% = 1 THEN
          SYS "SendDlgItemMessage", !dlg%, 100, LB_GETCURSEL, 0, 0 TO FeetPieces%
          PRINT "User selected ";FeetPieces%
        ENDIF
        IF click% = 2 THEN PROC_closedialog(dlg%) : END
      UNTIL !dlg% = 0
      END
      REM read user selection -------------------------------------
      DATA "     This quotation is for:"
      DATA " 1)  Normal uncut tubing footage?"
      DATA " 2)  Saw-Cut Tubing in inch lengths?"
      DATA " 3)  Saw-Cut Tubing in foot lengths?"
      DATA " 4)  Core-Cut Tubing in inch lengths?"
      DATA " 5)  Core-Cut Tubing in foot lengths?"
      DATA " 6)  Lathe-Cut Tubing in inch lengths?"
      DATA " 7)  Lathe-Cut Tubing in foot lengths?"
      DATA " 8)  Other type of fabrication?"
      DATA ".."
 
Using combobox:
 Code:      CB_SETCURSEL = 334
      CB_ADDSTRING = 323
      CB_GETCURSEL = 327
      CBS_DROPDOWNLIST = 3
      INSTALL @lib$+"winlib2"
      REM create dialogbox ----------------------------------------
      dlg% = FN_newdialog("Select cutting",100,100,180,120,8,500)
      PROC_combobox(dlg%,"",100,10,10,160,90,CBS_DROPDOWNLIST)
      PROC_pushbutton(dlg%,"Ok",1,20,95,50,16,0)
      PROC_pushbutton(dlg%,"Cancel",2,110,95,50,16,0)
      PROC_showdialog(dlg%)
      REM create dialogbox ----------------------------------------
      REM fill combobox --------------------------------------------
      READ text$
      REPEAT
        SYS "SendDlgItemMessage", !dlg%, 100, CB_ADDSTRING, 0, text$
        READ text$
      UNTIL text$=".."
      SYS "SendDlgItemMessage", !dlg%, 100, CB_SETCURSEL, 0, 0
      REM fill combobox --------------------------------------------
      REM read user selection -------------------------------------
      Click% = 0
      ON SYS Click% = @wparam% : RETURN
      REPEAT WAIT 1
        click% = 0
        SWAP click%,Click%
        IF click% = 1 THEN
          SYS "SendDlgItemMessage", !dlg%, 100, CB_GETCURSEL, 0, 0 TO FeetPieces%
          PRINT "User selected ";FeetPieces%
        ENDIF
        IF click% = 2 THEN PROC_closedialog(dlg%) : END
      UNTIL !dlg% = 0
      END
      REM read user selection -------------------------------------
      DATA "     This quotation is for:"
      DATA " 1)  Normal uncut tubing footage?"
      DATA " 2)  Saw-Cut Tubing in inch lengths?"
      DATA " 3)  Saw-Cut Tubing in foot lengths?"
      DATA " 4)  Core-Cut Tubing in inch lengths?"
      DATA " 5)  Core-Cut Tubing in foot lengths?"
      DATA " 6)  Lathe-Cut Tubing in inch lengths?"
      DATA " 7)  Lathe-Cut Tubing in foot lengths?"
      DATA " 8)  Other type of fabrication?"
      DATA ".."
 
Using radiobuttons:
 Code:      INSTALL @lib$+"winlib2"
      REM create dialogbox ----------------------------------------
      dlg% = FN_newdialog("Select cutting",100,100,180,140,8,1100)
      READ text$
      PROC_static(dlg%,text$,100,10,10,160,10,0)
      Y%=1
      READ text$
      REPEAT
        PROC_radiobutton(dlg%,text$,100+Y%,20,10+Y%*10,160,10,0)
        Y%+=1
        READ text$
      UNTIL text$=".."
      PROC_pushbutton(dlg%,"Ok",1,20,110,50,16,0)
      PROC_pushbutton(dlg%,"Cancel",2,110,110,50,16,0)
      PROC_showdialog(dlg%)
      REM create dialogbox ----------------------------------------
      REM read user selection -------------------------------------
      Click% = 0
      ON SYS Click% = @wparam% : RETURN
      REPEAT WAIT 1
        click% = 0
        SWAP click%,Click%
        IF click% = 1 THEN
          FeetPieces%=0
          FOR I%=1 TO 8
            SYS "IsDlgButtonChecked", !dlg%, 100+I% TO state%
            IF state%=1 THEN FeetPieces%=I%
          NEXT I%
          PRINT "User selected ";FeetPieces%
        ENDIF
        IF click% = 2 THEN PROC_closedialog(dlg%) : END
      UNTIL !dlg% = 0
      END
      REM read user selection -------------------------------------
      DATA "     This quotation is for:"
      DATA " 1)  Normal uncut tubing footage?"
      DATA " 2)  Saw-Cut Tubing in inch lengths?"
      DATA " 3)  Saw-Cut Tubing in foot lengths?"
      DATA " 4)  Core-Cut Tubing in inch lengths?"
      DATA " 5)  Core-Cut Tubing in foot lengths?"
      DATA " 6)  Lathe-Cut Tubing in inch lengths?"
      DATA " 7)  Lathe-Cut Tubing in foot lengths?"
      DATA " 8)  Other type of fabrication?"
      DATA ".."
 
		
		
		Re: A Better Way?
		Post by CharlesB on Mar 19th, 2015, 04:32am
		Svein - - - Thanks for guiding me to the Windows section for dialogue boxes. I read all, and digested some of the document. I also found that Richard had written an example program for dialogue boxes. 
I had, several times, looked for such a program, but somehow missed it. I think the problem is that I did not know that what I wanted was called a "dialogue box."
The example program did have a slightly different name than the manual name and I am learning from observing it. 
In any event, as for your examples, I really liked your third example with the radio buttons. I'm trying to find out how I can extend the menu to allow a 9th and 10th line. As yet, I have not found the number to change, but I'm looking and reading.
Many thanks.
I certainly will invest a few days here.
Especially I thank you for the examples.
This is exactly what I was looking for and I was searching under "menu boxes" and came up with nothing.
This was a lot of work, so again, thank you.
		
		
		Re: A Better Way?
		Post by sveinioslo on Mar 20th, 2015, 10:13pm
		The downside of constructing the dialogbox manually (as in the example), is that even a small change in the design, may require a lot of editing.
Consider using one of the dialogue editors.There is one in the bbc/examples/tools folder named dlgedit.bbc.
To add lines to the radiobutton example, you need to increase the dialog size, reserve more memory for it and move the ok/cancel buttons down.
In FN_newdialog increase the cy% value and for each new line, add 50 (bytes) to last value.
In PROC_pushbutton increase the y% values.
You need to experiment a little with the values.
Then just add one or more DATA lines.
Good luck
Svein
		
		
		Re: A Better Way?
		Post by CharlesB on Mar 21st, 2015, 10:46pm
		Thanks.
After you first showed me the dialog boxes I did find the example program. I am fascinated with it for what it can do. I have been able to DIM string arrays for over 50 strings and the text just scrolls down in the Combo Box.
The below is an example. I am uploading an array  THE_NAME$() from a data file
With a FOR - NEXT Loop, it works great in the combo box. 
I disabled this for the example that I'm sending you.
I wanted a second combo box, and I seem to have managed!
I am so happy. I feel that I am the remedial child of BBC BASIC, but I did manage to pull this off.
The only thing that I seemed to have messed up is the arrow keys; they should be with the "VAL" box. But, rather, they are with my second Combo Box. Any suggestions as how I can fix this?
I have tried to find the solution, but no luck yet as to what I did. I did save files along the way with my steps though. 
I did figure out, with your help, and trial and error to enlarge my dialogue box.
I tired to move down the pushbuttons, but with moderate success. 
I just need to read the dialogue instructions again and again to get a better handle on them.
In the meantime, this is a new world, and I'm very happy to be learning about these dialog boxes.
Here is what I have as I have modified the Example Program.
Thanks so much!!
           REM. Program to demonstrate a Dialogue Box
      INSTALL @lib$+"WINLIB2"
      REM PROC_OPEN_BENDNAME_FIL
      BS_DEFPUSHBUTTON = &1
      CB_ADDSTRING = &143
      CB_SETCURSEL = &14E
      CBS_DROPDOWNLIST = &3
      ES_AUTOHSCROLL = &80
      ES_NUMBER = &2000
      LB_ADDSTRING = &180
      LB_GETCURSEL = &188
      UDM_SETRANGE = &465
      UDS_ALIGNRIGHT = &4
      UDS_AUTOBUDDY = &10
      UDS_SETBUDDYINT = &2
      WS_CHILD = &40000000
      WS_GROUP = &20000
      WS_VISIBLE = &10000000
      REM These are the old values dlg%=FN_newdialog("Bends Quote", 20, 20, 160, 128, 8, 560)
      dlg%=FN_newdialog("Bends Quote", 20, 20, 175, 128, 10, 600)
      PROC_groupbox(dlg%, "Enter Degree   Enter Number", 0, 4, 4, 152, 96, WS_GROUP)
      REM PROC_editbox(dlg%, "Enter Degree", 101, 12, 20, 64, 12, ES_AUTOHSCROLL)
      PROC_editbox(dlg%, "QTY", 102, 82, 20, 64, 12, ES_NUMBER)
      PROC_combobox(dlg%, "Degree", 101, 12, 20, 64, 12, CBS_DROPDOWNLIST)
      PROC_dlgctrl(dlg%, "", 109, 0, 0, 12, 12, WS_VISIBLE OR WS_CHILD OR \
      \ UDS_AUTOBUDDY OR UDS_ALIGNRIGHT OR UDS_SETBUDDYINT, "msctls_updown32")
      PROC_combobox(dlg%, "", 103, 12, 40, 64, 60, CBS_DROPDOWNLIST)
      REM Would like another combo box here.
      PROC_listbox(dlg%, "", 104, 82, 40, 64, 48, 0)
      PROC_radiobutton(dlg%, "Std Tangents", 105, 12, 64, 64, 10, 0)
      PROC_radiobutton(dlg%, "Extd Tangents", 106, 12, 82, 64, 10, 0)
      REM Tried this but with no success yet  PROC_radiobutton(dlg%, "Third", 107, 13, 83, 64, 10, 0)
      REM proc_checkbox(dlg%, "Checkbox", 107, 82, 82, 64, 10, 0)
      PROC_pushbutton(dlg%, "OK", 1, 12, 108, 56, 14, WS_GROUP OR BS_DEFPUSHBUTTON)
      PROC_pushbutton(dlg%, "Cancel", 2, 92, 108, 56, 14, 0)
      REM experiment with new values . . . not good PROC_pushbutton(dlg%, "OK", 2, 14, 112, 62, 18, WS_GROUP OR BS_DEFPUSHBUTTON)
      REM experiment with new values . . . not good PROC_pushbutton(dlg%, "Cancel", 6, 100, 115, 60, 18, 2)
      PROC_showdialog(dlg%)
      ON CLOSE PROC_closedialog(dlg%):QUIT
      ON ERROR PROC_closedialog(dlg%) RINT'REPORT$:END
RINT'REPORT$:END
      DIM Bendsize$(50)
      REM  FOR X = 1 TO 45
      SYS "SendDlgItemMessage", !dlg%, 103, CB_ADDSTRING, 0, "String example 1"
      SYS "SendDlgItemMessage", !dlg%, 103, CB_ADDSTRING, 0, "String example 2"
      SYS "SendDlgItemMessage", !dlg%, 103, CB_ADDSTRING, 0, "String example 3"
      SYS "SendDlgItemMessage", !dlg%, 103, CB_ADDSTRING, 0, "String example 4"
      SYS "SendDlgItemMessage", !dlg%, 103, CB_ADDSTRING, 0, "String example 5"
      REM NEXT X
      REM FOR X = 1 TO 45
      REM SYS "SendDlgItemMessage", !dlg%, 101, CB_ADDSTRING, 0, THE_NAME$(X)
      SYS "SendDlgItemMessage", !dlg%, 101, CB_ADDSTRING, 0, "String example x1"
      SYS "SendDlgItemMessage", !dlg%, 101, CB_ADDSTRING, 0, "String example x2"
      SYS "SendDlgItemMessage", !dlg%, 101, CB_ADDSTRING, 0, "String example x3"
      SYS "SendDlgItemMessage", !dlg%, 101, CB_ADDSTRING, 0, "String example x4"
      REM NEXT X
      SYS "SendDlgItemMessage", !dlg%, 103, CB_SETCURSEL, 0, 0
      SYS "SendDlgItemMessage", !dlg%, 101, CB_SETCURSEL, 0, 0
      SYS "SendDlgItemMessage", !dlg%, 104, LB_ADDSTRING, 0, "12 Rad"
      SYS "SendDlgItemMessage", !dlg%, 104, LB_ADDSTRING, 0, "18 Rad"
      SYS "SendDlgItemMessage", !dlg%, 104, LB_ADDSTRING, 0, "24 Rad"
      SYS "SendDlgItemMessage", !dlg%, 104, LB_ADDSTRING, 0, "30 Rad"
      SYS "SendDlgItemMessage", !dlg%, 104, LB_ADDSTRING, 0, "36 Rad"
      SYS "SendDlgItemMessage", !dlg%, 104, LB_ADDSTRING, 0, "48 Rad"
      SYS "SendDlgItemMessage", !dlg%, 104, LB_ADDSTRING, 0, "60 Rad"
      SYS "SendDlgItemMessage", !dlg%, 104, LB_ADDSTRING, 0, "72 Rad"
      SYS "CheckRadioButton", !dlg%, 105, 106, 105
      SYS "SendDlgItemMessage", !dlg%, 109, UDM_SETRANGE, 0, 999
      Click%=0
      ON SYS Click% = @wparam% : RETURN
      REPEAT
        WAIT 1
        click%=0
        SWAP Click%, click%
      UNTIL click%=1 OR click%=2 OR !dlg%=0
      IF click%=1 THEN
        PRINT "OK pressed, settings were:"'
  
        DIM text% 255
        SYS "GetDlgItemText", !dlg%, 101, text%, 255
        PRINT "Text box contained """$$text%""""
  
        SYS "GetDlgItemInt", !dlg%, 102, 0, 1 TO Val%
  
  
        SYS "GetDlgItemText", !dlg%, 103, text%, 255
  
  
        SYS "SendDlgItemMessage", !dlg%, 104, LB_GETCURSEL, 0, 0 TO sel%
        PRINT "Listbox selection index was ";sel%
  
        SYS "IsDlgButtonChecked", !dlg%, 105 TO rb1%
        IF rb1% PRINT "Radiobutton 1 was checked" ELSE PRINT "Radiobutton 2 was checked"
  
        SYS "IsDlgButtonChecked", !dlg%, 107 TO cb%
        IF cb% PRINT "Checkbox was checked" ELSE PRINT "Checkbox was not checked"
      ELSE
        PRINT "Cancel pressed"
      ENDIF
      PRINT Val%;" - "; $$text%; '"ID Bends";
      PROC_closedialog(dlg%)
      PRINT "Combobox selection was """$$text%""""
      END
      DEF PROC_OPEN_BENDNAME_FIL
      REM Program automatically translated from QBASIC to BBC BASIC
      REM using QB2BBC utility ver 0.36 on Fri.20 Mar 2015,18:02:22
      REM!Embed @lib$+"QBLIB"
      REM    INSTALL @lib$+"QBlib" : PROC_QBinit
      REM Initialise string variables:
      Title1$ = "" : Title2$ = ""
      DIM THELINE$(45)
      DIM THE_NAME$(45)
      DIM THE_WEIGHT(45)
      DIM THE_BASIC_PARTNUMBER$(45)
      f& = OPENIN("Bends Data Files\bendname.fil") : IF f&=0 ERROR 53, "Cannot open file"
      SWAP @hfile%(f&), @hfile%(5)
      INPUT #5, Title1$ : WHILE ASCTitle1$=10 Title1$ = MID$(Title1$,2) : ENDWHILE
      INPUT #5, Title2$ : WHILE ASCTitle2$=10 Title2$ = MID$(Title2$,2) : ENDWHILE
      REPEAT : WHILE EOF #5 EXIT REPEAT : ENDWHILE
        X = X + 1
        INPUT #5, THELINE$(X) : WHILE ASCTHELINE$(X)=10 THELINE$(X) = MID$(THELINE$(X),2) : ENDWHILE
        REM   OSCLI "OUTPUT 15" : PRINT THELINE$(X) : OSCLI "OUTPUT 0"
        THE_NAME$(X) = MID$(THELINE$(X),5,7)
        THE_WEIGHT(X) = VAL(MID$(THELINE$(X),17,7))
  
        THE_BASIC_PARTNUMBER$(X) =(MID$(THELINE$(X),38,4))
        REM PRINT THE_NAME$(X), THE_WEIGHT(X), "    ", THE_BASIC_PARTNUMBER$(X)
  
        REM PRINT THELINE$(X)
  
      UNTIL FALSE
      CLOSE #5
      ENDPROC
      END
		
		
		Re: A Better Way?
		Post by sveinioslo on Mar 22nd, 2015, 10:09am
		Good work.
 Quote:| | I seemed to have messed up is the arrow keys; they should be with the "VAL" box | 
 | 
They will automatically merge with the lastly created item.
Just move the PROC_dlgctrl up one line, and see the magic.
Svein
PS. Use the 'code' tags when posting code to avoid corruption of the code.
In this case there is a smiley instead of PRINT.
Which becomes 'tongueRINT' when pasted into the IDE.
Hint: press the # button and put your code in between the 'code' and '/code' .
		
		
		Re: A Better Way?
		Post by CharlesB on Mar 22nd, 2015, 9:06pm
		Love the magic!
Thanks for the advice; I was wondering where that smiley face came from.
		
		
		Re: A Better Way?
		Post by CharlesB on Mar 29th, 2015, 02:22am
		Svein,
Your advice was profitable! I have spent two weeks or so really getting to see how dialogue boxes work and they have really cleaned up my program.
Some of the boxes allow users to provide lots of information, and this is so much better than the old BASIC "INPUT" command that I was using.
Now, for a simple question (I hope).
Can you direct me, or give me a simple example of how a simple window text box would work.
I would like to put some printing-to-screen information (to the user) into a window. She can keep the window until she no longer requires the information. Also, with a "Snagit Utility" she can grab a window and directly copy it into an email.
Again, I thank you so much for your help. To see the dialogue box work was sort of a "lightbulb moment" for me. 
Thanks, Charles
		
		
		Re: A Better Way?
		Post by sveinioslo on Mar 30th, 2015, 08:45am
		Great work !
 Quote:| | simple window text box would work. and directly copy it into an email.
 
 | 
 | 
You could make a separate dialogbox with an editbox in it, n-lines tall.
And add ES_MULTILINE to the editbox_style% value.
Then the user can copy/paste the text as usual.
Can't remember how to fill it with text 'line by line' but all text at once (in one string), will work.
https://msdn.microsoft.com/en-us/library/windows/desktop/bb775464%28v=vs.85%29.aspx
Svein