guides:o4w:examples:example_1

Example 1    

The following code will create a simple entry form.  Screen images are displayed below, after the code.

 

Subroutine O4W_EXAMPLE_1(CtrlEntId, Event, Request)

* Example #1: A simple entry/collection form

* Always include our equates

$Insert O4WEquates

* Determine how we were called, and what to do

Begin Case

Case event _eqc "CREATE" ; Gosub Create_Event

Case event _eqc "CLICK" ; Gosub Click_Event

End Case

*

Return 0

 

CREATE_EVENT:

* Creation event - called the first time through for each application

* Specify that this will generate a full web page

O4WForm()

* Put up the 'header' describing the page

O4WHeader("Revelation Software POS (Pizza Ordering System)", 4)

* "Space down" a few blank lines

O4WBreak()

O4WBreak()

* Use a table to align everything neatly

O4WTableStart("mainTable")

* Display a prompt in the first 'cell' of the table

O4WSetCell(1,1)

O4WText("Delivery Address: ")

* And put up a 'textbox' for the response in the next 'cell'

O4WSetCell(1,2)

O4WTextbox('', '', '', 'ADD1')

* Repeat for the other desired information

* Notice the shortcut: only specifying the 'row number' to O4WSetCell automatically puts you in the first column of that row

O4WSetCell(2)

O4WText("Address 2:")

/*

Notice the shortcut: if neither the row nor column is specified in O4WSetCell,

it automatically puts you in the next column of the current row

*/

O4WSetCell()

O4WTextbox('','','','ADD2')

O4WSetCell(3)

O4WText("City:")

O4WSetCell()

O4WTextBox('','','','CITY')

O4WSetCell(4)

O4WText("State:")

O4WSetCell()

O4WTextBox('','','','STATE')

O4WSetCell(5)

O4WText("Zip:")

O4WSetCell()

O4WTextBox('','','','ZIP')

O4WSetCell(6)

O4WText("Pizza Size:")

O4WSetCell()

* Display a list of choices as radio buttons (allowing only a single choice)

O4WRadioButton("Small", "S", "SIZE")

O4WRadioButton("Medium", "M", "SIZE")

O4WRadioButton("Large", "L", "SIZE")

O4WSetCell(7)

O4WText("Toppings:")

O4WSetCell()

* Display a list of toppings as checkboxes (allowing multiple choices)

O4WCheckBox("Pepperoni", "P", "TOPPINGS")

O4WBreak()

O4WCheckBox("Sausage", "S", "TOPPINGS")

O4WBreak()

O4WCheckBox("Extra Cheese", "C", "TOPPINGS")

O4WBreak()

O4WCheckBox("Mushrooms", "M", "TOPPINGS")

* End the table

O4WTableEnd("mainTable")

O4WBreak()

* Display a button for them to submit the order

O4WButton("Order!", "BTNORDER")

* Tell O4W you wish to be notified when the user clicks on this button

O4WQualifyEvent("BTNORDER", "CLICK")

RETURN

 

CLICK_EVENT:

* Click event - called when the button is pressed

* Read in all the values

ADD1 = O4WGetValue("ADD1")

ADD2 = O4WGetValue("ADD2")

CITY = O4WGetValue("CITY")

STATE = O4WGetValue("STATE")

ZIP = O4WGetValue("ZIP")

* 'SIZE' will return the S/M/L code from the SIZE radio buttons

SIZE = O4WGetValue("SIZE")

* 'TOPPINGS' will return an @VM-delimited list of the selected toppings

TOPPING = O4WGetValue("TOPPINGS")

* Calculate the price from the toppings and size selected

cost = 0

 

Begin Case

Case SIZE = "S" ; cost = 700

Case SIZE = "M" ; cost = 1000

Case SIZE = "L" ; cost = 1300

Case 1

* Not a valid size - return an error

O4WError("We're sorry, but the size '":size:"' doesn't appear to be valid!")

Return

End Case

* Now find each of the toppings

num.toppings = dcount(topping, @VM)

For each.topping = 1 To num.toppings

this.topping = topping<1,each.topping>

Begin Case

Case THIS.TOPPING = "P" ; cost += 100

Case THIS.TOPPING = "S" ; cost += 100

Case THIS.TOPPING = "C" ; cost += 50

Case THIS.TOPPING = "M" ; cost += 100

Case 1

* Not a valid topping?  Report an error

O4WError("We're sorry, but the topping '":this.topping:"' doesn't appear to be valid!")

Return

End Case

Next each.topping

* In a 'real' application, you'd now write all the information we collected into a database somewhere

orderNum = DATE():"*":TIME()

* <WRITE INFORMATION HERE>

* Notify the customer that his order has been received, and give him/her the total

O4WError('Thank you for your order!  Your order number is ':orderNum:'.  Your total is ':OCONV(cost,'MD2,$'):'.', 'Thank You')

RETURN

 

Figure 1:  The Entry Form

 

o4w_example0_1.jpg

 

Figure 2: Thank you message

 

o4w_example0_2.jpg

  • guides/o4w/examples/example_1.txt
  • Last modified: 2024/06/19 20:19
  • by 127.0.0.1