Alpha Video Training
Results 1 to 13 of 13

Thread: It worked in A4V7

  1. #1
    "Certified" Alphaholic
    Real Name
    Richard Coleman
    Join Date
    Oct 2000
    Location
    Franklin, TN
    Posts
    1,206

    Default It worked in A4V7

    Have a lotto application...
    Need to update records in one table from the input to a second table...
    Cannot find any way to do this on a field by field basis, so I figure that I have to do it with the OnSave event????
    Much rather do it as each field is entered, cuz then it's only one small script activated as the field is entered; as opposed to a longer script that must read each field individually and then act.... maybe in a loop ????
    BUT just spent the better part of an hour going thru the XBasic Reference and I cannot find what I 'think' I am looking for...
    Here's the scenario....
    Winning number data: date is entered and then 6 fields.
    Need to take each field value (ie 18), access a second table, add one (1) to a running count number for that field value AND then repeat for each of the remaining 5 fields... It was rather easy using the 'Read' command in A4.....
    here's my 'cobolized' xbasic.....?????

    assuming all the 'dim' statements are valid....

    dim fld[6] as N

    tbl1=table.open("db-name")
    tbl2=table.open("db1-name")

    tbl1.fetch_last()

    for i = 1 to 6
    var1=fld[i].value_get()
    tbl2.fetch(var1)
    count = count + 1
    next i

    var1 in this case is both the number value and the record number...
    tbl2 is already established with all counts initialized to zero.

    then close both tables

  2. #2
    "Certified" Alphaholic
    Real Name
    Richard Coleman
    Join Date
    Oct 2000
    Location
    Franklin, TN
    Posts
    1,206

    Default RE: It worked in A4V7

    As usual, while working on something else, I ran across some data and NOW I have:

    dim fld[6] as N
    dim n_var as N
    tbl1=table.open("db_name")
    tbl2=table.open("db1_name")
    tbl1.fetch_last()
    for i = 1 to 6
    n_var = fld[i].value_get()
    tbl2.fetch_goto(n_var)
    count = count + 1 where count is the fieldname
    next i
    tbl1.close()
    tbl2.close()
    This compiled OK so now I will go and try it..
    D

  3. #3
    "Certified" Alphaholic
    Real Name
    Richard Coleman
    Join Date
    Oct 2000
    Location
    Franklin, TN
    Posts
    1,206

    Default RE: It worked in A4V7

    Well, that did not work....
    Must be a problem with the update clause...
    Probably because I don't have the correct syntax to access the 'count' field in the second file....
    BTTDB

    D

  4. #4
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,310

    Default RE: It worked in A4V7

    Richard,

    Alpha Four you have to place the table in change or enter mode before you can edit a record's field values or before you can enter field values for a new record. Remember?

    The same is true in Alpha Five.

    If you want to create a new record in the second table you use

    "tbl".enter_begin()

    If you have found the record you want to edit (in table 2) you use

    "tbl".change_begin()



    In each case these simply initiate the change or enter. You then write to the fields.
    You then save the change or enter using other commands.

    Check the Xbasic Reference Manual for examples.

    -- tom

  5. #5
    "Certified" Alphaholic
    Real Name
    Richard Coleman
    Join Date
    Oct 2000
    Location
    Franklin, TN
    Posts
    1,206

    Default RE: It worked in A4V7

    OK -- I surrender..
    I have been thru (twice +) every occurrence of the words 'save' and 'put' in the XBasic Reference Manual.
    Nowhere can I find any mention of saving the record changes. If I am missing something, any clue would help..
    D

  6. #6
    "Certified" Alphaholic
    Real Name
    Richard Coleman
    Join Date
    Oct 2000
    Location
    Franklin, TN
    Posts
    1,206

    Default RE: It worked in A4V7

    Latest version that still does not work. I get 'argument is wrong type' error -- even after the 'fetch_last' command......????

    'Date Created: 14-May-2004 12:22:01 AM
    'Last Updated: 14-May-2004 08:51:22 PM
    'Created By :
    'Updated By :


    dim fld[6] as N
    dim n_var as N
    dim adder as N

    tbl1=table.open("lotto_south_winners")
    tbl2=table.open("lotto_south_numbers")

    tbl1.fetch_last()

    for i = 1 to 6
    n_var = fld[i].value_get()
    tbl2.index_get(number)
    tbl2.fetch_find(n_var)
    tbl2.change_begin()
    adder = tbl2.Frequency.value_get()
    adder = adder + 1
    tbl2.Frequency.value_put(adder)
    tbl2.change_end()
    ? n_var;? adder
    next i
    tbl1.close()
    tbl2.close()

  7. #7
    "Certified" Alphaholic
    Real Name
    Richard Coleman
    Join Date
    Oct 2000
    Location
    Franklin, TN
    Posts
    1,206

    Default RE: It worked in A4V7

    Here's another try. This time I get : ERROR field types don't match...
    In tbl1, date, fields 1 thru 6 are date and numeric.
    In tbl2, number is N, frequency is N, last_date is D
    I'm at a complete loss
    D

    'Date Created: 14-May-2004 12:22:01 AM
    'Last Updated: 14-May-2004 09:29:13 PM
    'Created By :
    'Updated By :


    dim fld[6] as N
    dim n_var as N
    dim n_adder as N
    dim d_ldt as D

    tbl1=table.open("j:\program files\a5v5\development\lotto pgms\lotto_south_winners")
    tbl2=table.open("j:\program files\a5v5\development\lotto pgms\lotto_south_numbers")

    tbl1.fetch_last()

    for i = 1 to 6
    n_var = fld[i].value_get()
    tbl2.index_get(number)
    tbl2.fetch_find(n_var)
    n_adder = tbl2.Frequency.value_get()
    n_adder = n_adder + 1
    d_ldt = tbl2.Last_date.value_get()
    tbl2.change_begin()
    tbl2.Frequency.value_put(n_adder)
    tbl2.Last_date.value_put(d_ldt)
    tbl2.change_end()
    '? n_var;? n_adder;? d_ldt
    next i
    tbl1.close()
    tbl2.close()

  8. #8
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,310

    Default RE: It worked in A4V7

    richard,

    I'm sorry you had trouble.

    I use the Alpha Five Help file (the CHM version) available from the Learning Center, and forget sometimes that others may not.

    "tbl".enter_begin() is a method of the table object. You'll find it in the chapter of the Xbasic Ref. Manual on tables.

    ditto "tbl".change_begin()

    If you were using the CHM help documentation you just click the index tab, enter either term as i presented it and you get to the right page instantly.

  9. #9
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,310

    Default RE: It worked in A4V7

    Richard,

    I don't have your tables or field names.

    The following assumes your second table (the one you're trying to update in your script) has a separate record for each possible "integer" that the lottomachine might generate.

    In pseudo code this is how I'd approach your script:

    1) establish a pointer to the current data entry table using "tbl" = table.current()
    2) verify that data entry is finished i.e. that table is not still in change or enter mode.
    3) if not in VIEW mode promptuser to cancel or commit thepending changes
    4) end script if user opts to quit, otherwise
    5) open the second table and establish a pointer to it using "tbl2" = table.open()
    6) set the index to that table using "tbl2".index_primary_put() (not primary_get() as you have done)
    7) fetch the first record in tbl2
    8) fetch the first integer value record using "tbl2".fetch_find() and a search key from your first number field in "tbl"
    9) place the second table in change mode, using "tbl2".change_begin()
    10) assign the new running count value to the running count field for the current integer using "tbl2".your_fieldname = var-"your_new_count value
    11) commit the change to disk using "tbl2".change_end(.t.)
    12) fetch the second integer value record using "tbl2".fetch_find() and a search key from your second number field in "tbl"
    13) repeat steps 9 through 11
    14) fetch the third integer value record using "tbl2".fetch_find() and a search key from your third number field in "tbl"
    15) repeat steps 9 through 11

    and so on

    nn) close the second table with "tbl2".close()

    -- tom

  10. #10
    "Certified" Alphaholic
    Real Name
    Richard Coleman
    Join Date
    Oct 2000
    Location
    Franklin, TN
    Posts
    1,206

    Default RE: It worked in A4V7

    I got a bit hung up on the PDF books and forgot about the CHM help file..
    Thanx for the reminder.
    D

  11. #11
    VAR Pat Bremkamp's Avatar
    Real Name
    Pat Bremkamp
    Join Date
    Apr 2000
    Location
    Oregon, USA
    Posts
    2,629

    Default RE: It worked in A4V7

    Richard,

    I think there is a problem with your philosophy on this. You are worried about putting a "big" script at the end of entry to enter all six values at once, so you want a script on each field as you exit.

    This can lead to big problems. First, what happens if you are half way through entry and then decide you don't want to enter that record? How do you go back and "unenter" the values you have already entered? Second, what if you exit a field and then discover that you made a mistake (maybe you wouldn't, but I do all the time)?

    In terms of the time it takes, entering these six values will happen so fast, you won't notice.

    Put code something like this on a "post" button on your entry form:

    dim fromtable as P
    dim totable as P

    fromtable=table.current()
    totable=table.open("your-table-name")
    fromtable.commit() 'saves the values
    totable.enter_begin()
    totable.your-field1-name=fromtable.your-field1-name
    totable.your-field2-name=fromtable.your-field2-name
    .
    .
    totable.your-field6-name=fromtable.your-field6-name
    totable.enter_end()
    totable.close()
    end

    You may also want to think about a way to tell that you've entered this record so you don't post it twice.

    Pat

  12. #12
    "Certified" Alphaholic
    Real Name
    Richard Coleman
    Join Date
    Oct 2000
    Location
    Franklin, TN
    Posts
    1,206

    Default RE: It worked in A4V7

    Well -- in a way you're correct...
    First tho, I am trying to put the 'script' in the "OnSave" event for the form....
    To me that means that all the fields have been 'entered' and are correct (might need a ui-box here)and the record is being 'saved'.....
    But what I found (while trying to formulate) was that there are complications caused by deleting, or changing any field in, the record.
    So now I am beginning to think 'buttons' to accomplish the various tasks and attaching the "correct" script to each button. This would basically mean a manual 'posting' operation for the data.... so the data could be corrected both plus and minus...
    Right now, I don't see Field Rule Posting as a viable option, but this might change ??????
    Meanwhile BTTDB and thanx to everyone for the help...
    D

  13. #13
    "Certified" Alphaholic
    Real Name
    Richard Coleman
    Join Date
    Oct 2000
    Location
    Franklin, TN
    Posts
    1,206

    Default RE: It worked in A4V7

    Quick question ---

    If the last record entered is 'sorted' and becomes the first record displayed (ie sort by date last -"first); then which record do I 'fetch' to get the latest date????

    I would think that it would be the first record...

    D

Similar Threads

  1. worked in v4.5 but not in v5
    By urbanski in forum Alpha Five Version 5
    Replies: 16
    Last Post: 12-11-2003, 01:47 AM
  2. I have given up on A4V7!!
    By William Fike in forum Alpha Four Versions 7 and 8
    Replies: 49
    Last Post: 05-05-2002, 03:05 AM
  3. Calculating Hours Worked
    By Brian Mates in forum Alpha Five Version 4
    Replies: 8
    Last Post: 12-18-2001, 04:36 AM
  4. A4v7 How about the UK
    By Keith George in forum Alpha Four Version 6 and Prior
    Replies: 4
    Last Post: 11-10-2001, 07:41 AM
  5. A4V7 & DOS
    By Daniel Earley in forum Alpha Four Version 6 and Prior
    Replies: 5
    Last Post: 11-07-2001, 12:04 PM

Bookmarks

Posting Permissions

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