Board Logo
« COMBOBOX (and Running Win Apps) »

Welcome Guest. Please Login or Register.
Mar 22nd, 2018, 8:12pm

Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

This board is not meant for general discussion, it is meant for posting articles to help others.
For general discussions use the appropriate board, which best describes your problem area.

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: COMBOBOX (and Running Win Apps)  (Read 375 times)

member is offline


Never let your beliefs get in the way of learning.


Gender: Male
Posts: 4407
xx COMBOBOX (and Running Win Apps)
« Thread started on: Mar 3rd, 2005, 10:32am »

A COMBOBOX to Run Windows Applications

Text and code may be downloaded as a zip file from the JB Archives,

Previously, we discussed a LISTBOX to make choices avalable to a user, and hopefully introduce a few chuckles. This time we'll use a COMBOBOX, which is used much the same way but takes up less space on the graphic user interface. Another subject we'll venture into this time, is running Windows applications from within Just Basic. Many tools we consider to be standard on any computer running Windows can be opened using the RUN command. Many programs which are not bundled with Windows can also be run, provided you can include the full path to the EXE file. Because you can never know if the user has 'Lord of the Rings' or 'Mega-Death Attacks New York,' you'll have to decide which applications you want to 'call' from Just Basic. The worst that can happen is your program will close with a 'File not found' error, so your decision is not critical.

What is a COMBOBOX? You've seen many of them when you fill out a web form. Click a little arrow to select whether you will pay by VISA, Master Card, DISCOVER, or AMEX, or to make a selection for the state in which you live. A COMBOBOX can have as many items listed as you need. All listed items are identified as a string and stored in an array to be loaded when you run your program. The syntax to place a COMBOBOX on your GUI looks like this:
COMBOBOX #main.cbx, appList$(), [doApp], 20,145, 300, 48

Because Just Basic is pretty standard in organization, you should have no difficulty understanding the parameters. This COMBOBOX will be placed on window #main with a control extension of .cbx. The list of items to be displayed can be found in an array named appList$(). When an item is clicked, branch to [doApp]. Place the COMBOBOX 20 pixels right and 145 pixels down from the upper-left corner of the GUI. Make the COMBOBOX 300 pixels wide and 48 pixels high. The actual height of the COMBOBOX control on the GUI will be determined by the font size you have specified for the control. You don't have to worry about the size of the drop-down list when the user clicks on the COMBOBOX, JB will auto-size that for you to allow for all items in the array$() with no blank space at the bottom of the list.

You can also get text input from the user by treating a COMBOBOX just as you would a TEXTBOX. For a complete list of information you can retrieve from a COMBOBOX, see the help topic COMBOBOX.

The code below includes an array for 8 selections the user may choose from. In this case, the user cannot enter a selection not provided, so we don't expect the 'Selection not understood' to ever be displayed, but we tossed it in just as a matter of covering all our bases.
'Combobox selects MS Apps for use with JB


appList$(1)="     *Internet Explorer"
appList$(2)="     MSN Instant Messenger"
appList$(3)="     *Notepad (text editing)"
appList$(4)="     *MS Calculator"
appList$(5)="     *MS Paint (bmp imaging)"
appList$(6)="     *Windows Volume Controls"
appList$(7)="     *Outlook Express"
appList$(8)="     WinRAR (zip utility)"

STATICTEXT #main.stxt, "", 10, 10, 340, 135
COMBOBOX #main.cbx, appList$(), [doApp], 20,145, 300, 48
BUTTON #main.btn, "QUIT", [quit], UL, 150, 190, 50, 24

OPEN "MS Applications For Just Basic" FOR window as #main
PRINT #main, "trapclose [quit]"
PRINT #main.stxt, "!font times_new_roman 14"
PRINT #main.stxt, "You can run any of the applications below by choosing "+ _
"from the combobox.  Inspect the code to see the appropriate command "+ _
"and syntax to run from Just Basic.  An asterisk (*) indicates these "+ _ 
"programs should be on most Windows computers."

PRINT #main.cbx, "font arial 14"
PRINT #main.btn, "!font arial 12"
PRINT #main.cbx, "!     Make selection here."

    PRINT #main.cbx, "selectionindex? mySel"  'Get value of selected choice
    CASE 1 : RUN "explorer.exe"  'Use full URL
    CASE 2 : RUN "C:\Program Files\MSN Messenger\msnmsgr.exe"  'MSN IM
    CASE 3 : RUN "notepad.exe"  'Text composition
    CASE 4 : RUN "calc.exe"  'MS Calculator
    CASE 5 : RUN "mspaint.exe"  'BMP imaging and drawing
    CASE 6 : RUN "sndvol32.exe"  'Adjust Windows volume settings
    CASE 7 : RUN "C:\Program Files\Outlook Express\msimn.exe"
    CASE 8 : RUN "C:\Program Files\WinRAR\WinRAR.exe"
    CASE ELSE : PRINT #main.cbx, "!Selection not understood."

    CLOSE #main

The first thing we do in this program is load the appList$() array with 8 selections to be displayed to the user. When the user clicks on any item, the click event branches to [doApp] and the selection index is compared by the SELECT CASE block. The SELECT CASE branches the program to run the selected application. In particular, notice the "selectionindex? mySel" command comes after branching to [doApp]. This retrieves the index number of the item we clicked on and sets mySel as the value for the SELECT CASE comparison.

Notice some RUN commands simply say RUN application.exe, while others specify the full path. Some programs bundled with Window are common to all users and can be opened with the RUN command. Other programs may or may not be installed on the user's computer, and the full path will need to be specified. In this demo, I've marked some selections with an asterisk. If you click on those and they are not installed on your computer, or are not in the directory specified, a 'File not found' error will result. Paths may vary depending upon your user's operating system, so you will have to use care when specifying some programs. You may be able to run any program installed on your computer, but you'll never be certain without trying. Just be sure to add the title to the appList() array, and the RUN command to the SELECT CASE block.

If you're running programs on your own computer, you can probably type in the complete path to most any EXE file and run it from Just Basic. I haven't found any of my custom programs which cannot be opened from within Just Basic. In fact, I'm creating the text file for this tutorial using Notepad from the COMBOBOX we just created.

Looking at CASE 1, above, we will OPEN "explorer.exe" to the URL following explorer.exe with a space. If you are opening a text application, such as with CASE 3, you can specify the file by inserting a space following "notepad.exe" and including the file name. Of course, you'll receive a 'File not found' error if your text file is not located in the same folder as this basic program. When software is distributed to a user, often a text or HTML file will be included and can be opened when the user clicks on Help, or About. The syntax to open a specified file looks like this:
RUN "notepad.exe comboBox.txt"

Put the name of your file in place of comboBox.txt. If the file is not found within this folder, you must include the path to the file.

On many occasions your may find it necessary, or at least useful, to directly access Windows applications from within your Just Basic code. You probably will not need a COMBOBOX to run the desired application, so a BUTTON control can be used to take the user directly to the application. Fortunately, most Windows applications also allow you to click on FILE and the user will be able to navigate to a specific file by using the Windows FILEDIALOG.

How many other uses can you think of for a COMBOBOX? How about linking to a text file with the bio and stats of your favorite high-school football players? Perhaps a data file for your favorite hobby or collection? Because you can link directly to many Windows applications, you can run spreadsheets, documents, even music and videos directly from your Whiz-Bang program created using Just Basic!

« Last Edit: Mar 3rd, 2005, 11:03am by Welopez » User IP Logged

JB 1.01
Win7 64bit, 4 GB RAM, Pentium 6200@2.13 GHz (laptop)
WinXP, 1 GB RAM, Intel N270@1.6 GHz (netbook)
Member in Training

member is offline



Posts: 27
xx Re: COMBOBOX (and Running Win Apps)
« Reply #1 on: Dec 28th, 2012, 10:50am »

Thank you for this tutorial! I'm making an app launcher so this is PERFECT!
User IP Logged
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls