TechTricks
Technical answers from the trenches 
 
 
 
 

     
   
Script Tutorial: Converting Field Values to Mixed Case
 
   
 Posted: 5 October 2000
 
   
 
 Applies to: All versions
 
   
 
Audience: Beginner
 
       
   

Question: I've heard that I can use a script to convert field values to mixed case. What are scripts and how do I do this?

In many software packages, you can automate various actions using macros. Paradox lets you automate tasks through its ObjectPAL programming language. In general, you attach code to events associated with specific objects and user activities. For example, button objects have a pushButton() event that is triggered when the user clicks the button. To perform some action when your users click the button, you need to add code the button's pushButton() event.

Scripts are somewhat similar to macros, though they cannot be recorded in Paradox for Windows or Linux. They are basically standalone "containers" for ObjectPAL code that is executed outside of a form.

The following steps you through the process of creating a Paradox 9 script to convert field values to mixed case.

  1. To start, choose File | New | Script from the main Paradox menu.

  2. This opens an Editor window containing an event called run(). This event is triggered by opening (also called playing) the script.

  3. Type in (or paste from the Clipboard) the following code between the method/endmethod lines:
    var
       tc tCursor
    endVar

    errorTrapOnWarnings( Yes )
    try
       tc.open( "contacts" ) ; use your table name...
       tc.edit()
       scan tc :
          message( tc.recNo() )

          ; replace "First Name" as needed
          tc."First Name" =
             format( "cc", lower( tc."First Name" ) )

       endScan
       tc.close()
    onFail
        errorShow( "Can't Convert",
                   "Use [>>] for details..." )
    endTry
    beep()
    Message( "Done..." )
  1. Press F9 to check your syntax and verify that it's correct. If any errors are displayed, check your code for typographic errors.

  2. Choose File | Save and give your scipt a name that's easy to remember (perhaps MixedCase).

  3. Press F8 to run your script.

  4. Once you save your script, you can close it at any time.

This code does the following:

  1. Declares a variable called tc that lets you manipulate a table.

  2. Sets Paradox to display all errors that occur when they occur.

  3. Starts a try block, which lets you "protect" a block of code; that is, wrap it with some basic error-handling.

  4. Uses tc to open the table named between the quotes, Contacts.db in this case.

  5. Loops through each record in Contacts and converts the value in the First Name field to mixed case by first converting the value to lower case.

    As each record is processed, its record number appears in the status bar.

  6. Closes the address table (very important).

  7. Defines what happens if an error occurs in the protected block of code. In this case, we display the error and adds a hint.

  8. Closes the protected block of code.

  9. Lets you know that the process has finished.

Scripts can be used for a wide range of purposes; we generally use them for utilities and starting Paradox applications.

For more information, see the Paradox ObjectPAL tutorial under the Help menu

 

       

Top

Feedback About Paradox Delphi Assorted Web Stuff
 
 
Copyright © 2000-2004, techtricks.com; All Rights Reserved.
Acknowledgements, Disclaimers, Terms and Conditions.
Article last updated on 31 May 2003

 

Other Sites: Paradox, Delphi, Perl, Web Stuff, and More


 

[- End -]