Create a dBase file with Visual Basic 6

I have to write code to randomly generate dBase3/4 files with various structures.
I need to do this in real code.

How to connect to an existing dBase file is known, i just cannot create a new one.

So Please help me with an example
amannienAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VoiceOfDissentCommented:
DoCmd.TransferDatabase acExport, "dBase IV", [FORMNAME].Pathname, acTable, strQryName, [FORMNAME].PathName & "OUTPUTNAME.dbf"

This code would require you to reference the Access 9.0 (8.0?) library.

Also, I have presented it in Microsoft Access format to you, but it easily remedied into Visual Basic.  Hopefully this can at least get you started.
0
amannienAuthor Commented:
Sorry i am fairly new ti visual basic.

I read your example but i dont quite understand it.

Could you please give me another hint?

The database is openend and is tranferred to antoher database, type dbase4, including the 'table' and written to 'outputname.dbf'.

The abbreveation 'ac' in actable and acexport. What do you mean with that?



0
TimCotteeHead of Software ServicesCommented:
Here is a VB project and Form in flat Ascii which has two textboxes, one for the dbf file name and the other for the structure string e.g., "Name C(10),Number N(10),Price N(6,2),Desc M(10)". Enter the required info and click the create button.

This version uses the Microsoft Visual Foxpro ODBC driver, but if you do not have this then you should be able to use an alternative one.

To use it just copy and paste the sections into the filenames shown.

VBtoDBF.VBP

Type=Exe
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\WINNT\System32\STDOLE2.TLB#OLE Automation
Reference=*\G{22813728-8BD3-11D0-B4EF-00A0C9138CA4}#1.0#0#..\Program Files\Common Files\System\Ado\MSADOMD.DLL#Microsoft ActiveX Data Objects (Multi-dimensional) 1.0 Library
Reference=*\G{00000201-0000-0010-8000-00AA006D2EA4}#2.1#0#..\Program Files\Common Files\System\Ado\msado15.dll#Microsoft ActiveX Data Objects 2.1 Library
Reference=*\G{00000300-0000-0010-8000-00AA006D2EA4}#2.1#0#..\Program Files\Common Files\System\ADO\msador15.dll#Microsoft ActiveX Data Objects Recordset 2.1 Library
Reference=*\G{00000600-0000-0010-8000-00AA006D2EA4}#2.1#0#..\Program Files\Common Files\System\Ado\MSADOX.DLL#Microsoft ADO Ext. 2.1 for DDL and Security
Form=VBtoDBF.frm
Startup="Form1"
Command32=""
Name="Project1"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="Ocular Sciences UK Limited"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1

[RVB]
DeleteClass1=frmtemp

VBtoDBF.FRM

VERSION 5.00
Begin VB.Form Form1
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdCreate
      Caption         =   "Create DBF"
      Height          =   495
      Left            =   240
      TabIndex        =   2
      Top             =   2520
      Width           =   4215
   End
   Begin VB.TextBox Text2
      Height          =   1335
      Left            =   240
      TabIndex        =   1
      Top             =   1080
      Width           =   4215
   End
   Begin VB.TextBox Text1
      Height          =   495
      Left            =   240
      TabIndex        =   0
      Top             =   360
      Width           =   4215
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmdCreate_Click()
    Dim cnnDBase As New Connection
    Dim rstDBF As New Recordset
    cnnDBase.ConnectionString = "Driver={Microsoft Visual Foxpro Driver};UID=;PWD=;SourceDB=C:\Private\;SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;Null=Yes;Deleted=Yes;"
    cnnDBase.Open
    rstDBF.Open "CREATE TABLE " & Text1.Text & " (" & Text2.Text & ")", cnnDBase, adOpenDynamic, adLockOptimistic
    cnnDBase.Close
End Sub



0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
amannienAuthor Commented:
THANKS!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.