BBC BASIC for Windows
Programming >> User Interface >> MENU2.BBC
http://bb4w.conforums.com/index.cgi?board=ui&action=display&num=1425549213

MENU2.BBC
Post by CharlesB on Feb 28th, 2015, 9:55pm

I'm very new to BBC BASIC and even the message board, so sorry if this thread is in the wrong place.
I'm trying to understand the MENU2.BBC that was created in 2011.
I did go to "Help" and did read the comments on the program.
I was wondering if someone can try to explain it to me in more layman's words.
I assume that this Menu2 Program runs in the background and it sends a global variable (something that I do not understand) that will open another program?
I appreciate your help and thank you.

To add:

The ON SYS help indicates that . . .

The ON SYS statement is activated whenever a menu item is selected (either by clicking with the mouse or using the keyboard shortcut). The system variable @wparam% contains a menu identifier which is equal to the third parameter of the relevant AppendMenu function (these values have been chosen to correspond directly to colour numbers), and this is copied to the global variable Click%.


So, I imagine that this part of the program is where I need to concentrate.

on sys Click% = @wparam% : return

So, I did modify the first Popup Menu, and I hope you can see what I am trying to do.

Ha, this is not a porno, it's a program that will work on pricing plastics tubing by its outer diameter.

sys "CreatePopupMenu" to hpop1%
sys "AppendMenu", hpop1%, 0, 1, "&0 to 2 inches"
sys "AppendMenu", hpop1%, 0, 2, "&2 to 3 inches"
sys "AppendMenu", hpop1%, 0, 4, "&3 to 4 inches"
sys "AppendMenu", hpop1%, 0, 6, "&4 to 5 inches"
sys "AppendMenu", hpop1%, 0, 7, "&5 to 6 inches"
sys "AppendMenu", hpop1%, 0, 3, "&6 to 8 inches"
sys "AppendMenu", hpop1%, 0, 9, "&8 to 10 inches"
sys "AppendMenu", hpop1%, 0, 5, "&Over 10 inches"

So, how do I get the "third parameter" which above is a number that colors the screen to, rather, go to my code that does the pricing?

I hope that this makes sense to someone.





Re: MENU2.BBC
Post by rtr2 on Feb 28th, 2015, 10:44pm

on Feb 28th, 2015, 9:55pm, CharlesB wrote:
I'm trying to understand the MENU2.BBC that was created in 2011.

In fact created about ten years earlier than that, I think, and it does show its age (as do several other example programs, to be honest). I'm not sure I would write it that way now.

These days I'm more inclined to vector mouse click events directly to handler procedures, rather than using the 'polling loop' approach that MENU and MENU2 do. There are pros and cons: the polling method does at least guarantee that the events are 'serialised', but the direct procedure call method is probably easier for a beginner to understand.

At the risk of adding confusion rather than clarity, here is a rewritten version of MENU2.BBC which uses a separate handler procedure for each menu item:

Code:
      INSTALL @lib$+"WINLIB5"

      SYS "CreatePopupMenu" TO hsub%
      SYS "AppendMenu", hsub%, 0, FN_setproc(PROCblack), "&Black"
      SYS "AppendMenu", hsub%, 0, FN_setproc(PROCwhite), "&White"
      :
      SYS "CreatePopupMenu" TO hpop1%
      SYS "AppendMenu", hpop1%, 0, FN_setproc(PROCred), "&Red"
      SYS "AppendMenu", hpop1%, 0, FN_setproc(PROCgreen), "&Green"
      SYS "AppendMenu", hpop1%, 0, FN_setproc(PROCblue), "&Blue"
      :
      SYS "CreatePopupMenu" TO hpop2%
      SYS "AppendMenu", hpop2%, 0, FN_setproc(PROCyellow), "&Yellow"
      SYS "AppendMenu", hpop2%, 0, FN_setproc(PROCmagenta), "&Magenta"
      SYS "AppendMenu", hpop2%, 0, FN_setproc(PROCcyan), "&Cyan"
      SYS "AppendMenu", hpop2%, 16, hsub%, "&Others"
      :
      SYS "CreateMenu" TO hmenu%
      SYS "AppendMenu", hmenu%, 16, hpop1%, "&Primary"
      SYS "AppendMenu", hmenu%, 16, hpop2%, "&Secondary"
      SYS "SetMenu", @hwnd%, hmenu%
      SYS "DrawMenuBar", @hwnd%

      REPEAT WAIT 1 : UNTIL FALSE
      END

      DEF PROCblack   : COLOUR 128 : CLS : ENDPROC
      DEF PROCwhite   : COLOUR 143 : CLS : ENDPROC
      DEF PROCred     : COLOUR 129 : CLS : ENDPROC
      DEF PROCgreen   : COLOUR 130 : CLS : ENDPROC
      DEF PROCblue    : COLOUR 132 : CLS : ENDPROC
      DEF PROCyellow  : COLOUR 139 : CLS : ENDPROC
      DEF PROCmagenta : COLOUR 133 : CLS : ENDPROC
      DEF PROCcyan    : COLOUR 134 : CLS : ENDPROC 

Richard.

Re: MENU2.BBC
Post by Joe68 on Feb 28th, 2015, 11:27pm

Basically you just need to use the third parameters in the Menu setup to make your program do something other than colour the screen.

As a relative newcomer to BB4W myself, I am sure those with more experience would write a more elegant solution, but this should at least get you going.

Code:
 
rem using this frees processor time otherwise used solely by BB4W
install @lib$+"NOWAIT"

sys "CreatePopupMenu" to hpop1%
sys "AppendMenu",hpop1%,0,1,"&0 to 2 inches"
sys "AppendMenu",hpop1%,0,2,"&2 to 3 inches"
sys "AppendMenu",hpop1%,0,3,"&3 to 4 inches"
sys "AppendMenu",hpop1%,0,4,"&4 to 5 inches"
sys "AppendMenu",hpop1%,0,5,"&5 to 6 inches"
sys "AppendMenu",hpop1%,0,6,"&6 to 8 inches"
sys "AppendMenu",hpop1%,0,7,"&8 to 10 inches"
sys "AppendMenu",hpop1%,0,8,"&Over 10 inches"
sys "CreateMenu" to hmenu%
sys "AppendMenu",hmenu%,16,hpop1%,"&Size-Price"
sys "SetMenu",@hwnd%,hmenu%
sys "DrawMenuBar",@hwnd%

rem activate Windows system
Click%=-1
on sys Click%=@wparam%:return

rem set variable 'price' to zero initially (also makes price global)
price=0

rem check for menu selection
repeat
procwait(10)
click%=-1
rem make click% same as menu selection number
swap click%,Click%
if click% procChecks
until false
end

defprocChecks
rem check which menu item is selected and set 'price' accordingly
case click% of
when 1 price=1
when 2 price=2
when 3 price=3
when 4 price=4
when 5 price=5
when 6 price=6
when 7 price=7
when 8 price=8
endcase
print tab(0,0)click%
print tab(0,1)price
endproc

Re: MENU2.BBC
Post by CharlesB on Mar 1st, 2015, 12:28am

Thanks Joe
I'll work on this tomorrow.
This does shoe me how I can get a variable "price," I understand this, and this is what I was trying to do.
So thanks.
Re: MENU2.BBC
Post by Joe68 on Mar 1st, 2015, 07:57am

Apologies for a small error.
In the loop, the line
"if click% ...." should read: "if click%<>-1 procChecks"
otherwise the checks are called every loop instead of when you actually select a menu item.
Glad to help. smiley
Re: MENU2.BBC
Post by CharlesB on Mar 1st, 2015, 9:04pm

Thanks so much for your help.
I did get a working handle on the Menu2 Program.

Now I have a new design problem before me.
Now that I have the menu program, I plan on using it to run a dozen or more utility programs. They will range from computing price lists to computing die sizes, radius forms etc. Many of the programs will be quite small of 25 lines of code, and a few of several hundred lines of code.

Can you suggest how I go about this from the Menu Program.
In my old Qbx Basic days the file sizes needed to be small and I would chain, shell, or run.

Should I just keep all of my source code within the large Menu2 Program, or would it make more sense to write and compile my smaller programs separately?

If I would do the latter, what would be the best way to run them? I don't see "shell" as an option in BBC

Also, one last question for now. Some of my utility programs are Excel files. Is there any way that I could run these files from the BBC Menu 2 Program?

Again, thanks for all of your help. I am looking through the help documents but I can't find my answers there as of yet.

Charles

O Yes, should this be a new thread question as the subject matter is not quite the same as getting the Menu2 program to work?
Re: MENU2.BBC
Post by rtr2 on Mar 2nd, 2015, 02:01am

on Mar 1st, 2015, 9:04pm, CharlesB wrote:
In my old Qbx Basic days the file sizes needed to be small and I would chain, shell, or run.

Should I just keep all of my source code within the large Menu2 Program, or would it make more sense to write and compile my smaller programs separately?

From your description, your code will be at most a few thousand lines long so there is little cause to complicate things by splitting it up. In your position I would put it all in one program.

Of course I would strongly encourage the use of structured programming techniques to keep the various functions isolated, for example by using as few global variables as possible.

Quote:
Some of my utility programs are Excel files. Is there any way that I could run these files from the BBC Menu 2 Program?

If these are .XLS files the only practical way is likely to be by having Excel (or maybe Open Office) installed on the same PC; then you can simply run them as external programs (e.g. using OSCLI "RUN" or SYS "ShellExecute").

If however you can use Excel to convert the files to CSV format it may be possible to run them in your BASIC program itself, if they are not too complex.

Richard.
Re: MENU2.BBC
Post by CharlesB on Mar 2nd, 2015, 03:39am

Well I tried. No lock in converting the excel programs, yet. I need to learn more.
But I tried your sample commands as best as I understood them. Both failed.
Here was the way I went about it.

command$ = "excel c:\busadafiles\cbformulas2.xlsx"

oscli "run", command$

sys "Shellexecute", command$

I tried it with the commas, without them, with the quotations, without them. I kept getting a rapidly fading dos box and a syntax error.
Any ideas?

Re: MENU2.BBC
Post by rtr2 on Mar 2nd, 2015, 08:51am

on Mar 2nd, 2015, 03:39am, CharlesB wrote:
I tried it with the commas, without them, with the quotations, without them. I kept getting a rapidly fading dos box and a syntax error. Any ideas?

I'm afraid I disapprove of this trial-and-error style of programming. The BB4W documentation describes the syntax of all the commands, including what punctuation is needed. Hopefully, after more than 13 years, it is reasonably error-free.

In the case of *RUN it tells you that the syntax is:

Code:
OSCLI "RUN " + command$ 

You appear not to have included the space after RUN, and to have omitted the + sign (string concatenation operator):

http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin8.html#starun

Richard.
Re: MENU2.BBC
Post by CharlesB on Mar 2nd, 2015, 11:38pm

My sincere apologies.

It was late at night and yes, I did error.
But, I so much appreciate your help. It's just that at this stage I'm so unfamiliar with the language that the help documentation is a new language in itself. I certainly do not ask my questions before consulting the help documentation.
These kinds of errors are common in beginners, for we don't see what is obvious to an expert; but I'll try to be more careful, and go more slowly.
But, I thank you for creating such a masterful platform (if that is the right word) to write my programs.
Re: MENU2.BBC
Post by rtr2 on Mar 3rd, 2015, 08:41am

on Mar 2nd, 2015, 11:38pm, CharlesB wrote:
These kinds of errors are common in beginners, for we don't see what is obvious to an expert

Your admonishment is noted. If you browse the messages in the Complaints section of this forum you will see that you are far from being the first person to criticise the 'tone' of my replies; if you feel strongly enough post your own comment there.

Richard.
Re: MENU2.BBC
Post by CharlesB on Mar 3rd, 2015, 12:55pm

O Richard,, please this was no admonishment at all.

I only feel bad that I was sloppy and hasty. I am thankful that one, as yourself, would even consider to help a beginner. I'm sorry if my last post, an apology, was written in that it could have been interpreted as an admonishment.

I have no complaint to file; I deserved this.

I have a PhD, (HA), in philosophy, but feel like a grade school student in programming.

I just need to slow down and stay within myself.

However, I think that this is how I made my mistake: and although your help files are error free, this may be positive feedback as how a beginner can misunderstand a section.

You replied to me a few threads ago that I needed to try three options in running the Excel file. Here were two of them.

********************
using OSCLI "RUN" or SYS "ShellExecute")[/size].
**********************

I tried looking both of these commands up in your help files.

I found "SYS" but "ShellExecute" did not show up in my search, so I went with "OSCLI" which I found in your index.

But in description of OSCLI the syntax was "OSCLI <string>.

I see now that the "RUN" could have been part of the string, and now I see why it would need a space after it and not a comma. I see this now, but did not understand this at all the other evening.

I feel as a child learning math right now. I'm trying to work the symbols without an intuition as to what the symbols mean.

So, now in my head, I think of OSCLI as "go back to MSDOS days" ( I guess this is what you meant as a "statement which allows a string expression to be interpreted a an 'operating system' command"

So, I tried the following last night ...

"OSCLI "RUN C:\busadafiles\cbformulas.xlsx"
And it worked.
Now, I understand the meaning of the space after "RUN"

So, no admonishment here. Just sincere thanks.

So, before I had this understanding I was trying all sorts of ways that "RUN" would work after OSCLI. I tried spaces, commas, etc. It was not really a "trial by error" method of programming by design. It was "trial by error" as a last means.

Sorry again, and I hope that we are good.