Home Why Omnibasic Features FAQ Examples
Reviews Keyword/Syntax On-Line Manual Download Manual ScreenShots

Chapter 11

Graphical Statements

Construct

The CONSTRUCT statement is used to construct visual objects as well as non-visual objects such as timers.

The IDE automatically constructs objects that are placed onto the form. The result of this may be viewed in the Construct Module of the Text Editor.

While working in the Graphical Project Mode, manually generated objects and forms need to be created in the Event module or the Function Module.

In the simplest case the assumption is made that the object being constructed will belong to the main window (OBMain). To construct a BUTTON on OBMain, the following code is all that is required:

CONSTRUCT Button1 as BUTTON

Some objects require a “holder”. An example would be a group of Radio Buttons. These normally reside in a Frame. First we construct the Frame and then we construct an array of 3 Radio Buttons in the Frame. Example:

CONSTRUCT Frame1 as Frame
CONSTRUCT Radio Buttons (3) as RADIOBUTTON in Frame1

Also notice that the array size is specified inside parentheses immediately following the object name.

There are several variations on Construct based on the type object being constructed.

For ICONS and Images:

CONSTRUCT MyIcon AS ICON WITH Test.gif
CONSTRUCT MyImage AS IMAGE WITH Pic.gif

For FONTS:

CONSTRUCT Font1 AS FONT WITH "Courier,12"

NOTE: There are other ways of dealing with fonts in the Font Property Section.

For secondary Forms:

CONSTRUCT Test Form AS FORM [Placement = Default]

In the last example, the Placement argument is optional. The additional types of placement are:

Default – Place at upper left corner.
Cursor – Place at current cursor position.
Owner – Center on owner.
Screen – Center on screen.
Maximized – Fill screen.

BEGINWAITCURSOR

This statement is used to set the cursor to a wait cursor. This is used when it is desired to provide a wait indication to the user. There are no arguments to this statement.

ENDWAITCURSOR

This statement is used to set the cursor back to normal after having displayed a wait cursor. There are no arguments to this statement.

DESTROY

The DESTROY statement is used to remove an object which was previously CONSTRUCTED. Example:

CONSTRUCT Button1 \Causes the object to be created.



DESTROY Button1 \Causes the object to be removed.

Dialog Boxes

Dialog boxes are pre-built modal windows that are used to display a message, prompt the user or allow a particular type of selection to be made.

The types of dialogs with accompanying syntax are as follows:

Message Box

MSGBOX MessageBoxType,”TitleString”,”ContentString”[,AnswerOption]

The MessageBoxTypes are:

INFO (or INFORMATION)




WARN (or WARNING)




ERROR

br />

QUESTION


The AnswerOptions are:

OK
OK_CANCEL
YES_NO
YES_NO_CANCEL
QUIT_CANCEL
QUIT_SAVE_CANCEL

The answer codes returned to OBDialogCode are:

1 OK
2 NO
3 OK
4 CANCEL
5 QUIT
6 SAVE

Note: If the AnswerOption is OK, the last argument may be omitted. This is to say that if the AnswerOption is omitted, OK is assumed as the AnswerOption.

Some examples follow:

MSGBOX QUESTION,”Delete File”,”Are you sure?”,YES_NO_CANCEL

MSGBOX WARNING,”System”,”System resources are low”

MSGBOX ERROR,”Save”,”Illegal file name”

MSGBOX QUESTION,”Quit”,”Do you really want to quit?”,YES_NO

Input Dialog

INPUTDIALOG “TitleString”,PromptString”[,Text]

If the OK button is clicked, OBDialogFlag will be true and OBDialogText will contain the text enter by the user. If the Cancel button is clicked, OBDialogFlag will be false.

An example follows:

INPUTDIALOG “Name”,”Please enter your name”

This Dialog Box was created in the DialogText Program. This program is unique in that it shows graphics, control and data entry without having any variables. So this program only has a Form and a Button constructed and a click event off of that button.

Editor Construct Module:

Editor Event Module

Color Dialog

COLORDIALOG ColorCode

The ColorCode is an integer representing the RGB numeric value that will be displayed when the color dialog pops up.

The user uses sliders, input boxes, or check buttons to select a color. If the user clicks on the Accept button, OBDialogFlag will be true with the color code or RGB value in OBDialogCode. If the user clicks on the Cancel button, OBDialogFlag will be false.

An example:

COLORDIALOG OBRed

File Dialog

FILEDIALOG Type,”Path”,”FileFilter”,FileFilterNumber

The Types are:

OPEN
SAVE
SAVEAS

The Path specifies a starting point for the file specification. It may be entered as a null string (“”) in which case the current directory or folder is the default. FileFilter is a string describing the types of files to be displayed on the combobox within the file dialog and subsequently in the file display section. FileFilterNumber is the number of the FileFilter to be set as the default filter.

An example:

FILEDIALOG SaveAs,"C:/OB/","Graphical Programs (*.obp)\nConsole Programs (*.b)",1

This will cause a file dialog with a title of “SaveAs” and a default to the entered directory (folder) including file type description to appear. All “obp” files will be displayed.

FILEDIALOG OPEN,”C:/DownLoad/”,”*.zip\n*.exe”,1 

This will cause a file dialog with a title of “Open”, a combobox containing “*.zip”, and “*.exe” with *.zip displayed (preselected).

FILEDIALOG OPEN,”C:/DownLoad/”,”Zip Files (*.zip)\nExe Files (*.exe)”,2

This one is the same as the previous one except that descriptive titles precede the FileFilters. Also the second entry will be the displayed default.

If the user selects (or enters) a file and clicks on the Accept button, OBDialogText will contain the full path to that file and OBDialogFlag will be true. OBDialogCode will contain an integer indicating which filter was selected. If the user clicks on the Cancel button, OBDialogFlag will be false.

Font Dialog

An example:

FONTDIALOG

This will cause the font dialog to appear.

If the user selects a font and clicks on the Accept button, a set of font variables comprising the font descriptor will be set according to the user’s choice. OBDialogFlag will be set to true. The variables are:

OBFontName
OBFontSize
OBFontWeight
OBFontSlant
OBFontEncoding
OBFontWidth
OBFontFlags

If the user clicks on the Cancel button, OBDialogFlag will be set to false.

When using the Font Dialog, we recommend sticking with the Western Character Set. Some of the more exotic choices on some of the fonts can lead to less than desirable results. The two primary adjustments to the fonts are type of font and the size of the font.

Print Dialog

An example:

PRINTDIALOG

This will cause the print dialog to appear.

If the user selects a printer and clicks on the Accept button, OBDialogFlag will be set to true, OBDialogText will contain the full printer name as well as the printer ID (or path) inside angle brackets (<>). OBPrinterID will contain the parsed ID or path. This ID is used to open the selected printer for use. Typical code example:

PRINTDIALOG
IF OBDialogFlag=TRUE THEN
   PrintFlag=TRUE
   PrinterName=OBPrinterID
   STATUS:OPEN #Printer,PrinterName:WRITE
   IF STATUS<0 THEN
      MSGBOX ERROR,"Printer",PrinterName
      EXIT EVENT
   ENDIF
ELSE
   EXIT EVENT
ENDIF

If one of your printers is on an NT server and your printer name has a back slash in it, it may not appear on the list of available printers, at least in the 2.10 release version of the software. If this is the case then you can still set up a way to that printer, using a direct dialog box and then using the information you type into the Dialog Box to direct the print output. In this example we are reading the printer path out of a dialog box:

INPUTDIALOG "Printer","Enter Printer PathName",PrinterName
IF OBDialogFlag=TRUE THEN
   PrinterName=OBDialogText
   DELETE "_pnx"
   CREATE #PrintSpec,"_pnx":WRITE
   PUT #PrintSpec,PrinterName
   CLOSE #PrintSpec
   PrintFlag=TRUE
   STATUS:OPEN #Printer,PrinterName:WRITE
   IF STATUS<0 THEN
      MSGBOX ERROR,"Printer",PrinterName
      EXIT EVENT
   ENDIF
ELSE
   EXIT EVENT
ENDIF

If the user clicks on the Cancel button, OBDialogFlag will be set to false.

Search Dialog

The Search Dialog is a tool for gathering the information from the user on what to search for and how to search for it. When the program invokes the Search Dialog Box, The user will fill in the information and then the information will be available to the program using the special variables. In the following example we will invoke the Search Dialog Box on a Button1.click event. If the user presses search then the OBDialogFlag will be True, if the user presses Cancel then it will be False. If OBDialogFlag is True then the Text in the “Search for:” Window will be available in OBDialogText. The search modes “Exact, Ignore Case, Expression and Backward are available in the OBDialogCode. The OBDialogCode is a bit flag word. The first bit is used for the Backward checkbox and the backward arrow. The third bit is used for the Ignore Case flag and the fourth bit is used for the Expression Flag. Here is a Table:

OBDialogCode = 0   User requests a forward search and an exact match
OBDialogCode = 1   User requests a reverse search and an exact match
OBDialogCode = 4   User requests a forward search with ignore case
OBDialogCode = 5   User requests a reverse search with ignore case
OBDialogCode = 8   User requests a forward search with special C expression case
OBDialogCode = 9   User requests a reverse search with special C expression case

The programmer can set a default OBDialogCode when the SearchDialog is invoked as the first argument. The second argument is a preset for the “Search for:” string. Here is an example:

Button1.click
SearchDialog 0,””
IF OBDialogFlag=TRUE THEN
   SearchString = OBDialogText
   SearchType = OBDialogCode
   Gosub SearchRoutine
ENDIF

Replace Dialog

The Replace Dialog is similar to the Search Dialog except it will return the text from the “Replace with:” window in the OBDialogText2 special string variable. The text strings for “Search for:” and “Replace with:” can be preset. In the following example, the “nothing” and “something” in the above display are preset.

Button2.click
ReplaceDialog 0,"nothing","something"
TextField1.Text=STR$(OBDialogCode)
TextField2.Text=OBDialogText
TextField3.Text=OBDialogText2
Exit Event

Next Page: Chapter 12
Table of Contents


Home || Why Omnibasic || Features || FAQ || Examples
Reviews || Links || Privacy Statement || Top of Page

 

   Innomation Systems, Inc.

117 Morrison Ave. Morrison, MO 65061 (573) 294-6130

OmniBasic is a trademark of Innomation Systems, Inc., other trademarks are the property of their respective owners.
Innomation Systems, Inc. reserves the right to change prices and specifications without prior notice.
Copyright © 2000, 2001, 2002 Innomation Systems, Inc.