Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2012
    Posts
    24

    Unanswered: To set a constant (double) by loading it in from a table

    Hi

    I have a table in dbf format and I want to read in the values as constants in my program written in FoxPro. My table of constants looks like

    Constants.dbf
    --------------------------------
    Con1 Con2 Con3
    0.235 1.422 3445

    And I want 0.235 to be used in my program as a named constant "IamAconstant"

    help.... (not feeling to big about this query.... )

  2. #2
    Join Date
    Nov 2012
    Posts
    24
    Hi
    I found the answer, so for future readers here is how I solved it.

    USE Constants.dbf
    STORE VAL(Constants.vi) TO VnI
    STORE VAL(Constants.Vredestein) TO Vredestein
    STORE VAL(Constants.N01) TO N01
    STORE VAL(Constants.N37) TO N37
    CLOSE TABLES

  3. #3
    Join Date
    Nov 2002
    Posts
    128
    Provided Answers: 1
    STORE TO is the OLD syntax and is seldom used any more with new FP/VFP development.

    Instead you use the equal sign ( = )
    Code:
    * --- Open the desired data table ---
    USE Constants.dbf
    * --- Make sure that table is SELECTED among the various table workgroups ---
    SELECT Constants
    Now you need to go to the desired record within the table
    This can be done various ways depending on what your application needs.

    Code:
    SELECT Constants
    * --- GO to the TOP (or BOTTOM) of the table ---
    GO TOP   && Note TOP is the Default record immediately after USE of a table
    or

    Code:
    SELECT Constants
    * --- GO to a specific record number ---
    GO 20  && Record No 20
    or

    Code:
    SELECT Constants
    * --- GO to a specific record where a field value matches ---
    LOCATE FOR Year = 20
    or

    Code:
    SELECT Constants
    * --- Find the specific record where a field value matches ---
    nThisYear = 20
    
    SET ORDER TO Year  && An Index on Year was previous created
    SEEK nThisYear
    Now make memory variable assignments from the values in the data table fields

    Code:
    VnI = VAL(Constants.vi)
    Vredestein = VAL(Constants.Vredestein)
    N01 = VAL(Constants.N01)
    N37 = VAL(Constants.N37)
    If you only want to close that single specific data table
    Code:
    USE  && will only close the specifically selected data table and leave others open for use
    If you want to close ALL open data tables
    Code:
    CLOSE DATABASE ALL

    Good Luck

  4. #4
    Join Date
    Nov 2002
    Posts
    128
    Provided Answers: 1
    An additional note about naming conventions...

    You are showing the assignment of the value from a data table field into a memory variable, but in most cases you are not differentiating the difference between the two different value sources with differing names - and the application might get "confused", let alone the application developer.

    For example you show:
    Code:
    STORE VAL(Constants.N01) TO N01
    
    * --- My version of that would be: ---
    N01 = VAL(Constants.N01)
    If, within your application, you leave the data table open and should reference something by N01 how will the application 'know' which one you are referencing.

    Generally we modify the memory variable name to differentiate it from the data table field name.
    One way many of us do that is be prefixing the memory variable with one or more letters.
    One to designate where that memory variable might be 'visible' within the application ('g' for globally, 'l' for locally only, etc.)
    And another to designate the variable content type ('n' for Numeric - both Integer and Numeric, 'c' for Character, 'd' for Date, 't' for DateTime, etc.)

    Then wherever in your application you (as the developer) need to use the value, you will clearly remember what you are using and the application will not get 'confused'.

    So, for example, if this value was Numeric and the variable was Global, you might want to use something like:
    Code:
    STORE VAL(Constants.N01) TO gnN01
    
    * --- My version of that would be: ---
    gnN01 = VAL(Constants.N01)
    Good Luck

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •