_The VsData Database Engine_ by Michiel de Bruijn Example 1: VsData1.CreateDatabase _ "MIDIfiles", "$$$%FWD$" Example 2: For Fld% = 1 To 7 VsData1.Field(Fld%) = _ txtField(Fld% - 1) Next VsData1.Update Example 3: VsData1.SearchString = Chr(34) & _ Search$ & Chr(34) & " IN Field(1)" VsData1.FindFirst If Not VsData1.EOF Then UpdateFields Else MsgBox "Not found!" VsData1.MoveFirst End If Listing One Public fIsNew As Integer Private Sub cmdFind_Click() Search$ = InputBox$("Enter song title to find", "vsData sample") VsData1.SearchString = Chr(34) & Search$ & Chr(34) & " IN Field(1)" VsData1.FindFirst If Not VsData1.EOF Then UpdateFields Else MsgBox "Not found!" VsData1.MoveFirst End If End Sub Private Sub cmdGoWeb_Click() VsData1.MediaPlay "WebSite" End Sub Private Sub cmdNew_Click() On Error Resume Next '//Initialize state to 'entering new record' fIsNew = True For fld% = 1 To 7 txtField(fld% - 1) = "" Next cmbField.ListIndex = -1 End Sub Private Sub cmdNext_Click() VsData1.MoveNext cmdPrevious.Enabled = True If VsData1.EOF Then cmdNext.Enabled = False End Sub Private Sub cmdPlayMIDI_Click() '//Extract the file from the database to its original '// source, then launch the Media Player to play it VsData1.ExtractFile "MIDIFile", VsData1.Field(8) Shell "MPlay32 " & VsData1.Field(8), vbNormalNoFocus End Sub Private Sub cmdPrevious_Click() VsData1.MovePrevious cmdNext.Enabled = True If VsData1.BOF Then cmdPrevious.Enabled = False End Sub Private Sub cmdUpdate_Click() If fIsNew = True Then VsData1.AddNew End If On Error Resume Next For fld% = 1 To 6 Err = 0 VsData1.Field(fld%) = txtField(fld% - 1) '//Did we hit the hole in our control array? If Err Then '//Yup -- this is the combo box VsData1.Field(fld%) = cmbField.ListIndex End If Next On Error GoTo 0 '//Store date... VsData1.Field(7) = CVDate(txtField(6)) '//Store extra copy of MIDI file name, as vsData will '// replace it with 'FILE'... VsData1.Field(8) = txtField(4) VsData1.Update End Sub Private Sub Command2_Click() End Sub Private Sub Form_Load() '//Init our Category combo box cmbField.AddItem "Popular/Dance" cmbField.AddItem "Ballad" cmbField.AddItem "Rock" '//If no database file is present, create one If Dir$("midifiles.isd") = "" Then CreateSampleDatabase End If OpenSampleDatabase VsData1.MoveFirst If VsData1.EOF = True Then '//Empty database, so set state to 'entering new record' fIsNew = True Else UpdateFields End If End Sub Private Sub OpenSampleDatabase() VsData1.OpenDataBase "MIDIfiles" VsData1.FieldName(1) = "Title" VsData1.FieldName(2) = "Composer" VsData1.FieldName(3) = "Made Famous By" VsData1.FieldName(4) = "Category" VsData1.FieldName(5) = "MIDIfile" VsData1.FieldName(6) = "WebSite" VsData1.FieldName(7) = "EntryDate" VsData1.FieldName(8) = "MIDIfileName" End Sub Private Sub CreateSampleDatabase() '//Make sure there is no existing database '// (only a sample, not to be used when actual data persistence is desired...) VsData1.KillDataBase VsData1.CreateDataBase "MIDIfiles", "$$$%FWD$" VsData1.CloseDataBase End Sub Private Sub VsData1_Error() '//Simple error handler (make it the user's problem...) MsgBox VsData1.ErrorMessage, vbCritical + vbOKOnly, "vsData reported an error!" End Sub Private Sub UpdateFields() On Error Resume Next For fld% = 1 To 6 Err = 0 txtField(fld% - 1) = VsData1.Field(fld%) '//Did we hit the hole in the control array? If Err Then '//Hmm, this must be our combo box! cmbField.ListIndex = Val(VsData1.Field(fld%)) End If Next On Error GoTo 0 '//Put date back where it belongs, properly formatted... txtField(6) = Format(VsData1.Field(7), "general date") '//Kludge to get real filename back in MIDI file field: txtField(4) = VsData1.Field(8) End Sub VERSION 5.00 Object = "{66A3FDC8-EF71-11CF-881F-00001B4D5DFB}#1.0#0"; "VSDATA.OCX" Begin VB.Form MainForm BorderStyle = 3 'Fixed Dialog Caption = "My vsData MIDI Database" ClientHeight = 3195 ClientLeft = 45 ClientTop = 330 ClientWidth = 4740 ClipControls = 0 'False Icon = "MainForm.frx":0000 LinkTopic = "Form1" MaxButton = 0 'False MinButton = 0 'False ScaleHeight = 3195 ScaleWidth = 4740 ShowInTaskbar = 0 'False StartUpPosition = 3 'Windows Default Begin VB.CommandButton cmdFind Caption = "&Find" Height = 375 Left = 1920 TabIndex = 11 Top = 2760 Width = 975 End Begin VB.CommandButton cmdNext Caption = ">>" Height = 375 Left = 3000 TabIndex = 10 Top = 2760 Width = 615 End Begin VB.CommandButton cmdPrevious Caption = "<<" Height = 375 Left = 1200 TabIndex = 12 Top = 2760 Width = 615 End Begin VB.ComboBox cmbField Height = 315 Left = 2040 Style = 2 'Dropdown List TabIndex = 3 Top = 1200 Width = 2535 End Begin VB.CommandButton cmdNew Caption = "&New" Height = 375 Left = 120 TabIndex = 13 Top = 2760 Width = 975 End Begin VB.CommandButton cmdUpdate Caption = "&Update" Height = 375 Left = 3720 TabIndex = 9 Top = 2760 Width = 975 End Begin VB.CommandButton cmdGoWeb Caption = "&Go" Height = 255 Left = 3960 TabIndex = 7 Top = 1920 Width = 615 End Begin VB.CommandButton cmdPlayMIDI Caption = "&Play" Height = 255 Left = 3960 TabIndex = 5 Top = 1560 Width = 615 End Begin VB.TextBox txtField DataSource = "vsData1" Height = 285 Index = 6 Left = 2040 TabIndex = 8 Top = 2280 Width = 2535 End Begin VB.TextBox txtField DataSource = "vsData1" Height = 285 Index = 5 Left = 2040 TabIndex = 6 Top = 1920 Width = 1815 End Begin VB.TextBox txtField DataSource = "vsData1" Height = 285 Index = 4 Left = 2040 TabIndex = 4 Top = 1560 Width = 1815 End Begin VB.TextBox txtField DataSource = "vsData1" Height = 285 Index = 2 Left = 2040 TabIndex = 2 Top = 840 Width = 2535 End Begin VB.TextBox txtField DataSource = "vsData1" Height = 285 Index = 1 Left = 2040 TabIndex = 1 Top = 480 Width = 2535 End Begin VB.TextBox txtField DataSource = "vsData1" Height = 285 Index = 0 Left = 2040 TabIndex = 0 Top = 120 Width = 2535 End Begin VB.Label Label7 Caption = "Date Entered" Height = 255 Left = 120 TabIndex = 20 Top = 2280 Width = 1695 End Begin VB.Label Label6 Caption = "Web site" Height = 255 Left = 120 TabIndex = 19 Top = 1920 Width = 1695 End Begin VB.Label Label5 Caption = "MIDI file" Height = 255 Left = 120 TabIndex = 18 Top = 1560 Width = 1695 End Begin VB.Label Label4 Caption = "Category" Height = 255 Left = 120 TabIndex = 17 Top = 1200 Width = 1695 End Begin VB.Label Label3 Caption = "Made famous by" Height = 255 Left = 120 TabIndex = 16 Top = 840 Width = 1695 End Begin VB.Label Label2 Caption = "Composer" Height = 255 Left = 120 TabIndex = 15 Top = 480 Width = 1695 End Begin VB.Label Label1 Caption = "Title" Height = 255 Left = 120 TabIndex = 14 Top = 120 Width = 1695 End Begin VSDATALib.VsData VsData1 Left = 0 Top = 2640 _Version = 65536 _ExtentX = 847 _ExtentY = 847 _StockProps = 0 End End Attribute VB_Name = "MainForm" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False