Two questions (about database structure & controls)

Hello.

Today I've stumbled upon two problems I couldn't solve myself.

1. How can I get the structure of a dbf file (in order to make a query for creating the same table in MS SQL)

2. How can I address objects in a form by a cycle. For example
   for i=1 to 10
      thisform.command(i).caption = str(i)
   endif

Thanks a lot in advance


Answer this question

Two questions (about database structure & controls)

  • Lars Kjetil Sørhus

    2) You'd do that as Drew said but be aware not all containers have a controls collection (ie: Pages,Buttons...).
    if you mean how you'd address a situation like assigning captions to commandbuttons named say cmd1...cmd10, then:

    for i=1 to 10
     with evaluate('thisform.cmd' + ltrim(str(m.i)))
        .Caption = str[m.i]
     endwith
    endfor

  • Bixler

    Thanks very, very much.

    Both suggestions are perfecct & work Smile

  • shasunder

    To get the structure of any open cursor, try the AFIELDS() function, which populates an array with pretty much everything you need to know about the structure of that cursor.

    To iterate thru the objects in your form, you can loop thru the THISFORM.Controls collection:
    LOCAL loControl
    FOR EACH loControl in THISFORM.Controls
      loControl.MessagePEMHere
    ENDFOR
    of course, if you want to "drill down" into the containers at the form level, you will have to construct the method where you put the above code so that it can be called recursively each time it encounters an loControl that is a container (has its own Controls collection).

    Drew Speedie
    VFP MVP

  • AdamSane

    Hi!

    Besides examining an array as Drew suggested, you can use Visual FoxPro's GenDBC.prg to generate the DDL for your database. Mine's in C:\Program Files\Microsoft Visual FoxPro 9\Tools\Gendbc\GenDBC.prg.



  • Two questions (about database structure & controls)