Alpha DevCon 2018
Results 1 to 4 of 4

Thread: Use a loop to define fields?

  1. #1
    Member
    Real Name
    Bill Warner
    Join Date
    Apr 2000
    Posts
    905

    Default Use a loop to define fields?

    I would like to define the values of many fields with a group of common variables; i.e. VAR->N1=S1, VAR->N2=S2, etc., where N1, N2, etc. are the names of the fields (there are 20 fields). Can I do this with something like N[x] = S[x] in a FOR or WHILE loop?

    Thanks for any help.

  2. #2
    Alpha Software Employee Selwyn Rabins's Avatar
    Real Name
    Selwyn Rabins
    Join Date
    Mar 2000
    Location
    Boston, MA
    Posts
    5,222

    Default RE: Use a loop to define fields?

    yes you can.

    say that you have a table with these fields:

    N1, N2, N3, N4

    and you want to put values into these fields.

    The values are stored in variables S1, S2, S3 etc.

    Do I have this correct?

    Then

    t=table.open("tablename")

    t.change_begin()
    for i = 1 to 4
    f = t.field_get("N"+alltrim(str(i)))
    f.value_put(s1)
    next i
    t.change_end(.t.)

  3. #3
    Member
    Real Name
    Bill Warner
    Join Date
    Apr 2000
    Posts
    905

    Default RE: Use a loop to define fields?

    Many thanks! This isn't exactly what I want, but your syntax should guide me well enough.

    Y'know, I think YOU should be making $100M a year, NOT Bill Gates!!

  4. #4
    "Certified" Alphaholic
    Real Name
    Peter Wayne
    Join Date
    Apr 2000
    Posts
    1,728

    Default RE: Use a loop to define fields?

    I think this is what Bill wants:

    Code:
    dim shared S1 as c
    dim shared S2 as c
    ...
    dim shared S20 as c
    
    t=table.open("mytable")
    for i=1 to 20
       eval("t.N"+alltrim(str(i)))=eval("S"+alltrim(str(i)))
    next
    t.close

Similar Threads

  1. Define Calculated Fields Screen issue?
    By peterg000 in forum Alpha Five Version 6
    Replies: 3
    Last Post: 10-08-2005, 11:43 AM
  2. Continue in For loop
    By elidaho in forum Alpha Five Version 6
    Replies: 5
    Last Post: 06-30-2005, 01:03 PM
  3. Error Message - Define Calc. Fields
    By Elke in forum Alpha Five Version 6
    Replies: 5
    Last Post: 03-02-2005, 06:05 AM
  4. Creating A Loop ?
    By Russell Sanderlin Sr in forum Alpha Five Version 5
    Replies: 4
    Last Post: 12-22-2004, 06:03 AM
  5. Infinite Loop
    By Melvin Davidson in forum Alpha Five Version 5
    Replies: 9
    Last Post: 04-03-2003, 06:28 AM

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
  •