Xbasic

Object Properties Table Lookups

Description

The value of using object properties to populate a list is that the developer can use a variety of other control types. The Object Properties tab of the Table Lookups form demonstrates five different ways to do table lookups.

Each of the following examples has extra fields (for your information only) that display the stored values of the quote_vendor_no and quote_product_no fields.

List Box Configuration

The List Box tab of the Table Lookups form contains two list boxes.

images/UG_Object_Properties_tab.gif

Vendor Choices for List Box

The Choices tab of the list box displays the vendor_name field and stores the vendor_no field from the Vendor table. The records are sorted alphabetically by vendor_name.

images/UG_Vendor_Choices.gif
  1. Select the list box and right click.

  2. Select Properties... .

  3. Display the Choices tab.

  4. Select "Computed Automatically" in the Choices for control are list.

  5. Select "Values from a table/set" in the Source list.

  6. Select "vendor" in the From Table list.

  7. In the Field/expression value to display control enter " vendor_name + "|" + vendor_no ". This expression returns two fields: vendor_name, which is displayed, and vendor_no, which is stored.

  8. Select "vendor_name" in the Display order list. This sorts the records alphabetically on the vendor_name field.

  9. Click OK to return to the Form Editor.

Product Choices for List Box

The Choices tab of the List Box displays the product_name field and stores the product_no field from the Product table. The records are sorted alphabetically by product_name.

images/UG_Product_Choices.gif
  1. Select the list box and right click.

  2. Select Properties... .

  3. Display the Choices tab.

  4. In the Choices for control are list select "Computed Automatically".

  5. In the Source list select "Values from a table/set".

  6. In the From Table list select "product".

  7. In the Field/expression value to display control enter " product_name + "|" + product_no ". This expression returns two fields: product_name, which is displayed, and product_no, which is stored.

  8. In the Display order list select "product_name". This sorts the records alphabetically on the product_name field.

  9. Select Enable Filter Expression and click Edit Filter Expression.

    • Product Filter for List Box

      In addition, the product_name records are limited to those where product_vendor_no field equals quote_vendor_no_op1. A change in the quote_vendor_no_op1 field triggers a refresh of the Product list.

      images/UG_Product_Choices_Filter.gif
      The table name in the Field Expression (in target table) must not be fully qualified. However, the table names in Field Expression (in current table) and Watch Expression fields must be fully qualified. The reason is that Alpha Anywhere evaluates the expression from the point of view of the Product table.
  10. Enter "Product_Vendor_No" in the Field Expression (in target table) list.

  11. Select "=" in the Operator list.

  12. Select "Quote_Vendor_No_OP1" in the Field Expression (in current table) list.

  13. Select "Quote_Vendor_No_OP1" in the Watch Expression list.

  14. Click OK to return to the Field Properties dialog.

  15. Click OK to return to the Form Editor.

Combo Box Configuration

The Combo Box tab of the Table Lookups form contains two combo boxes.

images/UG_Object_Properties_tab_2.gif

Vendor Choices for Combo Box

The Choices tab of the Vendor combo box displays the vendor_name field from the Vendor table. The records are sorted alphabetically by vendor_name. The implementation is the same as described in Vendor Choices for List Box.

Product Choices for Combo Box

The Choices tab of the Product combo box displays the product_name field from the Product table. The records are sorted alphabetically by product_name. The implementation is the same as described in Product Choices for List Box.

Product Filter for Combo Box

In addition, the product_name records are limited to those where product_vendor_no field equals quote_vendor_no_op2. A change in the quote_vendor_no_op2 field triggers a refresh of the Product list. The implementation is the same as described in Product_Filter_for_List_Box, with the exception of that the variable names change from Quote_Vendor_No_Op1 to Quote_Vendor_No_Op2.

The table name in Field Expression (in target table) must not be fully qualified. However, the table names in Field Expression (in current table) and Watch Expression fields must be fully qualified. The reason is that Alpha Anywhere evaluates the expression from the point of view of the Product table.

Record List - List Box Configuration

The Record List - List Box tab of the Table Lookups form contains two record list boxes.

images/UG_Object_Properties_tab_3.gif

Vendor Choices for Record List - List Box

The Choices tab of the record list - list box displays the vendor_name field and stores the vendor_no from the Vendor table. The records are sorted alphabetically by vendor_name.

images/UG_Vendor_Choices_2.gif
  1. Select the record list - list box and right click.

  2. Select Properties... .

  3. Display the Choices tab.

  4. Select "vendor" in the From Table list.

  5. Select "vendor_no" in the Return Value list. This is the field that the form will store.

    images/UG_Vendor_Choices_3.gif
  6. Click Add New Column to Record List.

  7. Select "vendor_name" in the Field list.

  8. Change the column title in the Header control to "Name".

  9. Click OK.

  10. Click A dd New Column to Record List.

  11. Select "vendor_no" in the Field list.

  12. Change the column title in the Header control to "Number".

Product Choices for Record List - List Box

The Choices tab of the record list - list box displays the product_name field and stores the product_no field from the Product table. The records are sorted alphabetically by product_name.

  1. Select the record list - list box and right click.

  2. Click Properties... .

  3. Display the Choices tab.

  4. Select "product" in the From Table control.

  5. Select "product_no" in the Return value control. This is the field that the form will store.

  6. Click Add New Column to Record List.

  7. Select "product_name" in the Field list.

  8. Change the column title in the Header field to "Name".

  9. Click OK.

  10. Click Add New Column to Record List.

  11. Select "product_symbol" in the Field list.

  12. Change the column title in the Header field to "Symbol".

images/UG_Product_Choices_2.gif

Product Filter for Record List - List Box

In addition, the product_name records are limited to those where product_vendor_no field equals quote_vendor_no_op3. A change in the quote_vendor_no_op3 field triggers a refresh of the Product list.

images/UG_Product_Choices_Filter_2.gif
  1. Select Enable Filter Expression and click Edit Filter Expression.

  2. In the Field Expression (in target table) control enter "Product_Vendor_No".

  3. Select "=" in the Operator list.

  4. In the Field Expression (in current table) control enter "Product_Vendor_No_OP3".

  5. Select "Quote_Vendor_No_OP3" in the Watch Expression control.

  6. Select "product_name" in the Display order list.

  7. Click OK to return to the Field Properties dialog.

  8. Click OK to return to the Form Editor.

Record List - Combo Box Configuration

The Record List - List Box tab of the Table Lookups form contains two list boxes.

images/UG_Object_Properties_tab_4.gif

Vendor Choices for Record List - Combo BoxThe Choices tab of the record list - combo box displays the vendor_name field and stores the vendor_no field from the Vendor table. The records are sorted alphabetically by vendor_name. The implementation is the same as described in Vendor Choices for Record List-List Box.Product Choices for Record List - Combo BoxThe Choices tab of the record list - combo box displays the product_name field and stores the product_no field from the Product table. The records are sorted alphabetically by product_name. The implementation is the same as described in Product Choices for Record_List-List Box.Product Filter for Record List - Combo BoxIn addition, the product_name records are limited to those where product_vendor_no field equals quote_vendor_no_op4. A change in the quote_vendor_no_op4 field triggers a refresh of the Product list. The implementation is the same as described in Product Filter for Record List-List Box, except that the variable quote_vendor_no_op3 changes to quote_vendor_no_op4.Radio Button ConfigurationThe Radio Button tab of the Table Lookups form contains two radio buttons. There are no field rules or choices defined in object properties. The implementation is based on Xbasic code as follows.

  • Tabbed2 OnTabChange

    This event refreshes the list of Vendors when the user arrives at the Event Driven tab. The code retrieves a list of Vendors, counts the number of records, and limits the list to a maximum of 7 items (because of the size of the area allocated to radio buttons).

  • Table_Lookups OnFetch

    This event refreshes the list of Products when the user reads a new record. The script calls a function named Refresh_Products.

  • Vendor OnChange

    This event refreshes the list of Products when the user selects a different vendor. The script calls a function named Refresh_Products.

  • Refresh_Products()

    This function receives pointers to the Vendor and Product radio button objects. It uses this information to retrieve the appropriate list of Product_name fields. It limits the list to a maximum of 7 items.

    images/UG_Object_Properties_tab_5.gif

Tabbed2 OnTabChange Event

dim cFieldList as C
dim nCounter as N
dim nRecordCount as N
dim cWord as C
cFieldList = table.external_record_content_get("Vendor", \ "Vendor_Name + '|' + Vendor_No", "Vendor_Name", "")
nRecordCount = w_count(cFieldList, crlf())
nRecordCount = min(7, nRecordCount)
if (nRecordCount = 0) then
    end
end if
vendor.choice.list.redim(nRecordCount)
for nCounter = 1 to nRecordCount
    cWord = word(cFieldList, nCounter, crlf())
    vendor.choice.listnCounter.value = word(cWord, 2, "|")
    vendor.choice.listnCounter.text = word(cWord, 1, "|")
next nCounter

Vendor OnChange Event

dim vendor_ptr as P
dim product_ptr as P
dim nRecordCount as N
vendor_ptr = Vendor.this
product_ptr = Product.this
nRecordCount = refresh_products(vendor_ptr, product_ptr)

Table Lookups OnFetch Event

dim vendor_ptr as P
dim product_ptr as P
dim nRecordCount as N
vendor_ptr = Vendor.this
product_ptr = Product.this
nRecordCount = refresh_products(vendor_ptr, product_ptr)

Refresh_Products() function

FUNCTION Refresh_Products as C (Vendor as P, Product as P)
dim cFieldList as C
dim nCounter as N
dim nRecordCount as N
dim cWord as C
dim cVendor as C
cVendor = Vendor.value
cFieldList = table.external_record_content_get("Product",\ "Product_Name + '|' + Product_No","Product_Name",\ "Product_Vendor_No = " + quote(cVendor))
nRecordCount = w_count(cFieldList,crlf())
if (nRecordCount = 0) then
    end
end if
nRecordCount = min(7, nRecordCount)
Product.choice.list.redim(nRecordCount)
for nCounter = 1 to nRecordCount
    cWord = word(cFieldList, nCounter, crlf())
    Product.choice.listnCounter.value = word(cWord, 2, "|")
    Product.choice.listnCounter.text = word(cWord, 1, "|")
next nCounter
END FUNCTION