Page 1 of 1

Create Database

Posted: Fri Feb 14, 2020 7:22 am
by omni
Roger,

I have always just created new databases manually, but I have to do one to copy to a csv, so the field names are not relevant. It is a special export for invoices with wayyyyyyyyyyyy too many fields.

Anyway, I want to create a database and use an array to assign the fields (ie, data001-datea110) all the same field length, c30.

I tried to use your examples but it just give an error, even for one field (testing it). No ch files are missing, if they are necessary.

Tried on like this, but all give an error

aStru := { ;
{ 'DESC', 'C', 50, 0 }, ;
{ 'INTERPRET', 'C', 5000, 0 } }

dbCreate( cPath + 'DCSCRIPT.DBF', aStru, 'DBFNTX' )

Does not like the array set up. I must be missing something. I would rather create a loop on an array. to create the fields
'DATA'+strzero(n,3) where n is the next field up to 110. But I cannot get by the array structure(?)

Any suggestions is appreciated.

Thanks

Fred
Omni

Re: Create Database

Posted: Fri Feb 14, 2020 8:00 am
by PedroAlex
Fred,

This code works for you?

Code: Select all

//----------------------------------------------
Proc Main()
LOCAL aStru := {}, MyFolder := 'D:\Data', MyFile:= 'MyDbf.dbf', cDbe := 'DBFNTX'

IF ! File( MyFolder, 'D' )
	CreateDir( MyFolder )
Endif

For x:=1 to 110
	aadd( aStru, {'MyField'+StrZero(x,3),'C',50,0} )
Next

DbCreate( MyFolder + '\' + MyFile, aStru, cDbe )

If File( MyFolder + '\' + MyFile )
	Msgbox('File Create Sucess')
Else
	Msgbox('File Create Fail')
Endif

Return

Re: Create Database

Posted: Fri Feb 14, 2020 8:33 am
by Koverhage
Fred,
a char field with 5000 characters ?

Re: Create Database

Posted: Fri Feb 14, 2020 8:36 am
by omni
Yes, works. I see what I did not do...old age kicking in.
The 5000 was just a copy issue. The error was the initialization of the array in the beginning. It was somewhere else in his example and I just neglected to do it.

thanks

Re: Create Database

Posted: Sat Feb 15, 2020 10:15 pm
by Eugene Lutsenko
Hi, Fred!

Look for "dbCreate" in the text of my system: http://lc.kubagro.ru/__AIDOS-X.txt.
There are different options for creating databases, including what you want to do