home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vidlibp / vidcopy.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-07  |  14.5 KB  |  479 lines

  1. VERSION 2.00
  2. Begin Form VidCopy 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Copy Video Data"
  6.    ClientHeight    =   3195
  7.    ClientLeft      =   2205
  8.    ClientTop       =   1800
  9.    ClientWidth     =   4755
  10.    Height          =   3600
  11.    HelpContextID   =   130
  12.    Left            =   2145
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    MinButton       =   0   'False
  16.    ScaleHeight     =   3195
  17.    ScaleWidth      =   4755
  18.    Top             =   1455
  19.    Width           =   4875
  20.    Begin PictureBox dlgFromTo 
  21.       Height          =   480
  22.       Left            =   0
  23.       ScaleHeight     =   450
  24.       ScaleWidth      =   1170
  25.       TabIndex        =   10
  26.       Top             =   0
  27.       Width           =   1200
  28.    End
  29.    Begin CommandButton cmdTo 
  30.       Caption         =   "&To"
  31.       Height          =   540
  32.       HelpContextID   =   130
  33.       Left            =   3240
  34.       TabIndex        =   3
  35.       Top             =   1125
  36.       Width           =   1230
  37.    End
  38.    Begin CommandButton cmdFrom 
  39.       Caption         =   "&From"
  40.       Height          =   540
  41.       HelpContextID   =   130
  42.       Left            =   3240
  43.       TabIndex        =   2
  44.       Top             =   150
  45.       Width           =   1230
  46.    End
  47.    Begin CommandButton cmdDone 
  48.       Cancel          =   -1  'True
  49.       Caption         =   "&Done"
  50.       Height          =   540
  51.       HelpContextID   =   130
  52.       Left            =   3240
  53.       TabIndex        =   4
  54.       Top             =   2100
  55.       Width           =   1230
  56.    End
  57.    Begin CommandButton cmdCopy 
  58.       Caption         =   "&Copy"
  59.       Default         =   -1  'True
  60.       Height          =   540
  61.       HelpContextID   =   130
  62.       Left            =   1755
  63.       TabIndex        =   0
  64.       Top             =   2100
  65.       Width           =   1230
  66.    End
  67.    Begin CommandButton cmdOptions 
  68.       Caption         =   "&Options"
  69.       Height          =   540
  70.       HelpContextID   =   130
  71.       Left            =   270
  72.       TabIndex        =   1
  73.       Top             =   2100
  74.       Width           =   1230
  75.    End
  76.    Begin Label lblMessage 
  77.       BackColor       =   &H00FFFF00&
  78.       BorderStyle     =   1  'Fixed Single
  79.       Height          =   240
  80.       Left            =   270
  81.       TabIndex        =   9
  82.       Top             =   2775
  83.       Width           =   4200
  84.    End
  85.    Begin Label lblToPath 
  86.       BackColor       =   &H00FFFF00&
  87.       BorderStyle     =   1  'Fixed Single
  88.       Height          =   240
  89.       Left            =   270
  90.       TabIndex        =   8
  91.       Top             =   1725
  92.       Width           =   4200
  93.    End
  94.    Begin Label lblFromPath 
  95.       BackColor       =   &H00FFFF00&
  96.       BorderStyle     =   1  'Fixed Single
  97.       Height          =   240
  98.       Left            =   270
  99.       TabIndex        =   6
  100.       Top             =   750
  101.       Width           =   4200
  102.    End
  103.    Begin Label lblTo 
  104.       AutoSize        =   -1  'True
  105.       BackColor       =   &H00C0C0C0&
  106.       Caption         =   "To Path\Name:"
  107.       Height          =   195
  108.       Left            =   270
  109.       TabIndex        =   7
  110.       Top             =   1500
  111.       Width           =   1320
  112.    End
  113.    Begin Label lblFrom 
  114.       AutoSize        =   -1  'True
  115.       BackColor       =   &H00C0C0C0&
  116.       Caption         =   "From Path\Name:"
  117.       Height          =   195
  118.       Left            =   270
  119.       TabIndex        =   5
  120.       Top             =   525
  121.       Width           =   1500
  122.    End
  123. ' Subsystem: Copy
  124. ' Module:    VidCopy.Frm
  125. ' Date:      01/01/94
  126. ' Author:    Richard Stauch
  127. ' Notes:
  128. ' This form allows the user to copy one or more database table
  129. ' to another. If the file doesn't exist in the "Copy To" string,
  130. ' it is automatically created. Only whole tables can be copied;
  131. ' the user cannot select a subset of data.
  132. Option Explicit
  133. DefInt A-Z
  134. ' Constants
  135. Const FROM_DIRECTION = 1 ' Flags for path setting functions.
  136. Const TO_DIRECTION = 2
  137. Const GENRE_DATA = 1  ' Flags to set tables-to-copy.
  138. Const RATING_DATA = 2
  139. Const VIDEO_DATA = 3
  140. ' Module-Level Variables
  141. Dim FromDOSPath As String ' Path string to copy from.
  142. Dim ToDOSPath As String   ' Path string to copy to.
  143. Sub ClearData (RecordInt As Integer)
  144. ' The user wants to Replace, so clear the table.
  145. Dim DB As Database ' Reference the database object.
  146. Dim T As Table     ' Reference the table object.
  147. ' If there is no database, create it.
  148.   On Error GoTo NoClearDB
  149. ' Set the database object (Exclusive = True, Read-Only = False).
  150.   Set DB = OpenDatabase(CopyName$, True, False)
  151. ' If there is a problem after this, just exit.
  152.   On Error GoTo ClearError
  153. ' Open the table to clear.
  154.   Select Case RecordInt%
  155.     Case GENRE_DATA
  156.       Set T = DB.OpenTable("Genre")
  157.     Case RATING_DATA
  158.       Set T = DB.OpenTable("Rating")
  159.     Case VIDEO_DATA
  160.       Set T = DB.OpenTable("Video")
  161.   End Select ' RecordInt%
  162.   Do While Not T.EOF
  163.   ' Delete all records.
  164.     T.Delete
  165.   ' Make sure Windows has an opportunity to update itself.
  166.     DoEvents
  167.   Loop
  168. ' The table is empty now, so close it and exit.
  169.   T.Close
  170.   DB.Close
  171.   Exit Sub
  172. NoClearDB:
  173.   If CheckFile(CopyName$) Then
  174.   ' If the file exists there's some problem with it.
  175.     GenericMsgBox (MBC_BADFILE)
  176.     Exit Sub
  177.   Else
  178.   ' If it doesn't exist, create it.
  179.     If CreateDataFile(CopyName$) Then
  180.     ' We've created the file, so continue.
  181.       Resume 0
  182.     Else
  183.     ' We had some problem creating the file.
  184.       Exit Sub
  185.     End If
  186.   End If
  187. ClearError:
  188. ' There is some problem with the database file.
  189.   GenericMsgBox (MBC_BADFILE)
  190.   Exit Sub
  191. End Sub
  192. Sub cmdCopy_Click ()
  193. ' Perform the copy operation according to the options set.
  194. Dim T As String ' Temp to hold current message string.
  195.   T$ = lblMessage.Caption
  196.   lblMessage.Caption = "Copying data."
  197.   If Not (GenreCopy% Or RatingCopy% Or VideoCopy%) Then
  198.   ' The user must indicate some table to copy.
  199.     GenericMsgBox (MBC_NOTABLES)
  200.     lblMessage.Caption = T$
  201.     Exit Sub
  202.   End If
  203.   If PathName$ = CopyName$ Then
  204.   ' You cannot copy a file onto itself.
  205.     GenericMsgBox (MBC_COPYPROBLEM)
  206.     lblMessage.Caption = T$
  207.     Exit Sub
  208.   End If
  209.   If ReplaceData% = True Then
  210.   ' Replace option = True; ask user if they're sure.
  211.     If GenericCancelBox(MBC_REPLACEDATA) = True Then
  212.     ' User pressed the Cancel button.
  213.       lblMessage.Caption = T$
  214.       Exit Sub
  215.     End If
  216.   End If
  217. ' Indicate "Wait".
  218.   Screen.MousePointer = HOURGLASS
  219. ' Go [Clear]/Append data.
  220.   CopyControl
  221. ' Indicate "Continue".
  222.   Screen.MousePointer = DEFAULT
  223. ' Display original message text.
  224.   lblMessage.Caption = T$
  225. End Sub
  226. Sub cmdDone_Click ()
  227. ' Remove the Copy form from the screen.
  228.   Unload VidCopy
  229. End Sub
  230. Sub cmdFrom_Click ()
  231. ' Set the "From" file name.
  232. Dim T As String ' Save the original message.
  233. Dim X As String ' Check for null return string.
  234.   T$ = lblMessage.Caption
  235.   lblMessage.Caption = "Setting 'From' path\name."
  236. ' Get the path and file name.
  237.   X$ = SetPath(FROM_DIRECTION)
  238.   If Len(X$) = 0 Then ' Check for empty string!
  239.     lblMessage.Caption = T$
  240.     Exit Sub
  241.   End If
  242. ' Show the selected fully qualified file name.
  243.   lblFromPath.Caption = X$
  244.   PathName$ = X$
  245. ' Get the path portion of the file name.
  246.   X$ = SeperatePath(PathName$)
  247.   If Len(X$) = 0 Then ' Check for empty string!
  248.     lblMessage.Caption = T$
  249.     Exit Sub
  250.   End If
  251. ' Show the path name.
  252.   FromDOSPath$ = X$
  253.   lblMessage.Caption = T$
  254. End Sub
  255. Sub cmdOptions_Click ()
  256. ' Let the user select file copy options.
  257. Dim T As String ' Save original message text.
  258.   T$ = lblMessage.Caption
  259. ' Inform the user what we're doing.
  260.   lblMessage.Caption = "Set copy options."
  261. ' Display the Copy Options form.
  262.   VidOpt.Show MODAL
  263. ' Restore the original message text.
  264.   lblMessage.Caption = T$
  265. End Sub
  266. Sub cmdTo_Click ()
  267. ' Set the "To" file name.
  268. Dim T As String ' Save the original message.
  269. Dim X As String ' Check for null return string.
  270.   T$ = lblMessage.Caption
  271.   lblMessage.Caption = "Setting 'To' path\name."
  272. ' Get the path and file name.
  273.   X$ = SetPath(TO_DIRECTION)
  274.   If Len(X$) = 0 Then ' Check for empty string!
  275.     lblMessage.Caption = T$
  276.     Exit Sub
  277.   End If
  278. ' Show the selected fully qualified file name.
  279.   lblToPath.Caption = X$
  280.   CopyName$ = X$
  281. ' Get the path portion of the file name.
  282.   X$ = SeperatePath(CopyName$)
  283.   If Len(X$) = 0 Then ' Check for empty string!
  284.     lblMessage.Caption = T$
  285.     Exit Sub
  286.   End If
  287. ' Show the path name.
  288.   ToDOSPath$ = X$
  289.   lblMessage.Caption = T$
  290. End Sub
  291. Sub CopyControl ()
  292. ' Control Replace and Copy functions.
  293.   If GenreCopy% = True Then
  294.   ' Copy the Genre table.
  295.     If ReplaceData% = True Then
  296.     ' Clear it first.
  297.       ClearData (GENRE_DATA)
  298.     End If
  299.     CopyData (GENRE_DATA)
  300.   End If
  301.   If RatingCopy% = True Then
  302.   ' Copy the Rating table.
  303.     If ReplaceData% = True Then
  304.     ' Clear it first.
  305.       ClearData (RATING_DATA)
  306.     End If
  307.     CopyData (RATING_DATA)
  308.   End If
  309.   If VideoCopy% = True Then
  310.   ' Copy the Video table.
  311.     If ReplaceData% = True Then
  312.     ' Clear it first.
  313.       ClearData (VIDEO_DATA)
  314.     End If
  315.     CopyData (VIDEO_DATA)
  316.   End If
  317. End Sub
  318. Sub CopyData (RecordInt As Integer)
  319. ' Copy the selected table.
  320. Dim DB1 As Database   ' Reference the "From" database object.
  321. Dim T1 As Table       ' Reference the "From" table object.
  322. Dim DB2 As Database   ' Reference the "To" database object.
  323. Dim T2 As Table       ' Reference the "To" table object.
  324. Dim FCount As Integer ' Number of fields in the table.
  325. Dim I As Integer      ' Fields counter/pointer.
  326. ' If there is no database, create it.
  327.   On Error GoTo NoCopyDB
  328. ' Set the "To" database object (Exclusive = True, Read-Only = False).
  329.   Set DB2 = OpenDatabase(CopyName$, True, False)
  330. ' If there is a problem after this, just exit.
  331.   On Error GoTo CopyError
  332. ' Set the "From" database object (Exclusive = False, Read-Only = True).
  333.   Set DB1 = OpenDatabase(PathName$, False, True)
  334. ' Open the tables to copy "From" and "To".
  335.   Select Case RecordInt%
  336.     Case GENRE_DATA
  337.     ' Copy the Genre table.
  338.       Set T1 = DB1.OpenTable("Genre")
  339.       Set T2 = DB2.OpenTable("Genre")
  340.     Case RATING_DATA
  341.     ' Copy the Rating table.
  342.       Set T1 = DB1.OpenTable("Rating")
  343.       Set T2 = DB2.OpenTable("Rating")
  344.     Case VIDEO_DATA
  345.     ' Copy the Video table.
  346.       Set T1 = DB1.OpenTable("Video")
  347.       Set T2 = DB2.OpenTable("Video")
  348.   End Select ' RecordInt%
  349. ' Find the count of fields in this table.
  350.   FCount% = T1.Fields.Count
  351.   Do While Not T1.EOF
  352.   ' Add a new record and copy each field.
  353.     T2.AddNew
  354.     For I% = 0 To FCount% - 1
  355.     ' Table "Fields" index starts at zero.
  356.       T2(I%) = T1(I%)
  357.     Next I%
  358.   ' Update the new "To" record, and move to the next "From" record.
  359.     T2.Update
  360.     T1.MoveNext
  361.   ' Make sure Windows has an opportunity to update itself.
  362.     DoEvents
  363.   Loop ' Not T1.EOF
  364. ' We're finished copying, so close the files and exit.
  365.   T1.Close : DB1.Close ' Close the "From" file.
  366.   T2.Close : DB2.Close ' Close the "To" file.
  367.   Exit Sub
  368. NoCopyDB:
  369.   If CheckFile(CopyName$) Then
  370.   ' If the file exists there's some problem with it.
  371.     GenericMsgBox (MBC_BADFILE)
  372.     Exit Sub
  373.   Else
  374.   ' If it doesn't exist, create it.
  375.     If CreateDataFile(CopyName$) Then
  376.       Resume 0
  377.     Else
  378.       Exit Sub
  379.     End If
  380.   End If
  381. CopyError:
  382. ' There is some problem with the database file.
  383.   GenericMsgBox (MBC_BADFILE)
  384.   Exit Sub
  385. End Sub
  386. Sub Form_Load ()
  387. ' Load the Copy form.
  388. Dim X As String ' Check for null return string.
  389. ' Inform the user what we're doing.
  390.   lblMessage.Caption = "Select 'From' and 'To' path\file names."
  391.   lblFromPath.Caption = PathName$
  392.   lblToPath.Caption = CopyName$
  393. ' Set the 'From' and 'To' DOS path names.
  394.   X$ = SeperatePath(PathName$)
  395.   FromDOSPath$ = X$
  396.   X$ = SeperatePath(CopyName$)
  397.   ToDOSPath$ = X$
  398. ' Set the Help file name for the dialog box.
  399.   dlgFromTo.HelpFile = HelpName$
  400. End Sub
  401. Sub lblFrom_Click ()
  402. ' Call the Click event of the associated command button.
  403.   cmdFrom_Click
  404. End Sub
  405. Sub lblFromPath_Click ()
  406. ' Call the Click event of the associated command button.
  407.   cmdFrom_Click
  408. End Sub
  409. Sub lblTo_Click ()
  410. ' Call the Click event of the associated command button.
  411.   cmdTo_Click
  412. End Sub
  413. Sub lblToPath_Click ()
  414. ' Call the Click event of the associated command button.
  415.   cmdTo_Click
  416. End Sub
  417. Function SeperatePath (FileStr As String) As String
  418. ' Find the "Path" portion of a fully qualified file name.
  419. Dim I As Integer ' Counter; pointer to the last "\" in the string.
  420.   If Len(FileStr$) = 0 Then
  421.   ' The FileStr$ variable is empty.
  422.     GenericMsgBox (MBC_BADFILE)
  423.   ' Calling procedures must check for empty string.
  424.     SeperatePath$ = ""
  425.     Exit Function
  426.   End If
  427.   For I% = Len(FileStr$) To 1 Step -1
  428.   ' Find the last "\" in the string.
  429.     If Mid$(FileStr$, I%, 1) = "\" Then Exit For
  430.   Next I%
  431.   If I% > 3 Then
  432.   ' This is a subdirectory, not a root directory.
  433.     I% = I% - 1 ' Remove the trialing "\".
  434.   ElseIf I% < 3 Then
  435.   ' There is no "\" in the FileStr$ variable.
  436.     GenericMsgBox (MBC_BADFILE)
  437.   ' Calling procedures must check for empty string.
  438.     SeperatePath$ = ""
  439.   End If
  440. ' The result is a useable "Drive:\[Path]" string.
  441.   SeperatePath$ = Left$(FileStr$, I%)
  442. End Function
  443. Function SetPath (Direction As Integer) As String
  444. ' Use the common dialog control to set a fully qualified file name.
  445.   Select Case Direction
  446.   ' Set up the dialog box.
  447.     Case FROM_DIRECTION
  448.     ' Indicate the "From" direction.
  449.       dlgFromTo.DialogTitle = "Select 'From' Path\Name"
  450.       dlgFromTo.Filename = PathName$
  451.       dlgFromTo.InitDir = FromDOSPath$
  452.       dlgFromTo.Flags = OFN_FILEMUSTEXIST Or OFN_SHOWHELP
  453.     Case TO_DIRECTION
  454.     ' Indicate the "To" direction.
  455.       dlgFromTo.DialogTitle = "Select 'To' Path\Name"
  456.       dlgFromTo.Filename = CopyName$
  457.       dlgFromTo.InitDir = ToDOSPath$
  458.       dlgFromTo.Flags = OFN_CREATEPROMPT Or OFN_SHOWHELP
  459.   End Select
  460. ' Check for Open dialog Cancel button (CancelError property = True).
  461.   On Error GoTo SetCancel
  462.   dlgFromTo.Action = DLG_FILE_OPEN
  463. ' Deactivate the error handler.
  464.   On Error GoTo 0
  465. ' Set the result from the dialog box and exit.
  466.   If dlgFromTo.Flags And OFN_EXTENSIONDIFFERENT Then
  467.   ' Calling procedure must check for empty string.
  468.     GenericMsgBox (MBC_BADFILE)
  469.     SetPath$ = ""
  470.   Else
  471.     SetPath$ = dlgFromTo.Filename
  472.   End If
  473.   Exit Function
  474. SetCancel:
  475. ' User pressed the cancel button.
  476.   SetPath$ = ""
  477.   Exit Function
  478. End Function
  479.