This tutorial will show you how to create a form that will display information from a memory table in a grid.
Go to Navigator > Setup > Form Designer. Form Designer will open with a blank form.
Add an Edit Grid component. You can do this by selecting Edit Grid from the Component menu, then clicking the form, or by clicking the Edit Grid component icon, then clicking the form.
Add a Memory Table component. This component is not shown on the form, so it doesn't matter where you place it.
Double-click the Memory Table, or right-click the Memory Table and select Memory Table Designer. Add fields to the Memory Table. For example you could add:
No.
Name
Display Label
Type
Domain
Uppr
1
Product
Product
String
IC Product Code
Selected
2
Quantity
Quantity
Integer
Clear
3
Price
Price
Float
Amount
Clear
Click Save.
Click the Edit Grid. In the Properties, set the Table to the MemoryTable. The memory table fields will be displayed in the grid.
Right-click the Edit Grid, and select Create Default Editors. Resize the Edit Grid if necessary to show all the fields.
You have now created a form that allows you to enter a list of products, quantities and prices. Click save and give your form a name such as memorytableform.pfd.
If you want to add a running total of the Price x Quantities added, do the following.
Add a Label component under the grid.
Go to the Code tab and enter the following code:
Sub RefreshTotal tblMemoryTable1.First Dim totalbalance As Number totalbalance = 0 Do While Not tblMemoryTable1.eof totalbalance = totalbalance + (tblMemoryTable1.price * tblMemoryTable1.quantity) tblMemoryTable1.Next Loop lLabel1.caption = totalbalance End Sub
This creates a sub-procedure that goes through each row in the Memory Table, and adds the Price * Quantity to the total balance. It then displays the total balance in the Label.
Go back to the Layout tab. Click on the Quantity Spin Edit in the Edit Grid. Go to the Events tab. Set the OnAfterChange to RefreshTotal. This means that when the Quantity is changed, the RefreshTotal sub-procedure will run, and will update the Total Balance shown in the label.
Click on the Price Number Edit in the Edit Grid. Go to the Events tab. Set the OnAfterChange to RefreshTotal. This means the Total Balance will also be refreshed when the Price is changed.
You have now added a running total, showing the running total of information entered in the Edit Grid.
If you want to automatically extract the NZRETAIL sell price for the Product, do the following.
Go to the Code tab and enter the following code:
Sub GetSellPrice Dim tbltemp as Object SQL = "SELECT ICSELL.Price " & _ " ,ICSELL.ProductCode " & _ "FROM ICSELL " & _ "WHERE (ICSELL.PriceCode = 'NZRETAIL') " tblTemp = ExecuteSQL(SQL) tbltemp.First Do Until tbltemp.eof If tbltemp.ProductCode = tblMemoryTable1.Product Then tblMemoryTable1.Price = tblTemp.Price Exit Do End If tbltemp.Next Loop End Sub
This will extract all the Product Codes and Sell Prices for ICSELL where the Price Code is NZRETAIL. It then searches through these to find the Product Code selected in the Edit Grid, and sets the Edit Grid Price to the corresponding Sell Price.
Go to the Layout tab. Select the Product Data Combo on the Edit Grid. Go to the Events tab. Set the OnAfterChange to GetSellPrice.
Now when you select a Product in your Edit Grid, the Price will be automatically updated.