Subject Re: create table
From Mervyn Bick <invalid@invalid.invalid>
Date Sat, 23 Jul 2016 10:06:05 +0200
Newsgroups dbase.getting-started

On 23-Jul-16 2:00 AM, Charlie wrote:
> Hi... In creating a table is there any way you can name it based on variables?  This is what I am trying to do below and it doesn't seem to want to work.  It only works if I create table nname and then the name is nname instead of the day of the week and date.  Thanks..
>
> function PUSHBUTTON2_onClick()
>            dw = trim(form.day_date1.rowset.fields["day_w"].value)
>                 dt = trim(dtos(form.day_date1.rowset.fields["t_date"].value))
>                 nname = dw+dt
>       close databases
>                 create table nname+".dbf" (;
>                 lname char(17), ;
>                 fname char(15), ;
>                 hdcp numeric(2,0), ;
>                 grs numeric(2,0), ;
>                 net numeric(2,0), ;
>                 plc numeric(2,0))
>                 form.close()
>       return
>


If the object of the exercise is to create a file such as
Saturday20160723.dbf then the following will do the trick.

        dt = form.day_date1.rowset.fields["t_date"].value)
        nName = cdow(dt)+dtos(dt)
        create table &nName (;
        lname char(17), ;
        fname char(15), ;
        hdcp numeric(2,0), ;
        grs numeric(2,0), ;
        net numeric(2,0), ;
        plc numeric(2,0))


Generally speaking, one shouldn't save values to a table if those values
can be calculated "on the fly" from other data in the table.  cdow()
will give you the day name for a given date so you don't really need the
day_w field to create your new table.

There is no need to trim the result returned by dtos().  There is also
no need to append ".dbf" as CREATE TABLE creates .dbf tables as a default.

You would, however, need to add the extension if you wanted to create a
Paradox .db file.  In that case you would use

       create table &nName..db (;

The first . tells dBASE that it has reached the end of the macro and the
.db is then included as part of the evaluated expression.

Mervyn.