home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Basic / Samples / VB_SMPL / VB_SMPL.ZIP / DB-XL.EXE / DB-XL.FRM (.txt) next >
Encoding:
Visual Basic Form  |  1994-04-07  |  13.7 KB  |  431 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Form1"
  6.    ClientHeight    =   5460
  7.    ClientLeft      =   750
  8.    ClientTop       =   1530
  9.    ClientWidth     =   6735
  10.    Height          =   5865
  11.    Left            =   690
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   5460
  14.    ScaleWidth      =   6735
  15.    Top             =   1185
  16.    Width           =   6855
  17.    Begin FileListBox File2 
  18.       Height          =   1200
  19.       Left            =   4080
  20.       TabIndex        =   24
  21.       Top             =   720
  22.       Visible         =   0   'False
  23.       Width           =   975
  24.    End
  25.    Begin PictureBox Picture2 
  26.       Align           =   2  'Align Bottom
  27.       BackColor       =   &H00C0C0C0&
  28.       Height          =   255
  29.       Left            =   0
  30.       ScaleHeight     =   225
  31.       ScaleWidth      =   6705
  32.       TabIndex        =   22
  33.       Top             =   5205
  34.       Width           =   6735
  35.       Begin Label Label7 
  36.          AutoSize        =   -1  'True
  37.          BackStyle       =   0  'Transparent
  38.          Caption         =   "Label7"
  39.          Height          =   192
  40.          Left            =   120
  41.          TabIndex        =   23
  42.          Top             =   0
  43.          Width           =   576
  44.       End
  45.    End
  46.    Begin PictureBox Picture1 
  47.       AutoSize        =   -1  'True
  48.       Height          =   1635
  49.       Left            =   4320
  50.       Picture         =   DB-XL.FRX:0000
  51.       ScaleHeight     =   1605
  52.       ScaleWidth      =   2370
  53.       TabIndex        =   21
  54.       Top             =   240
  55.       Width           =   2400
  56.    End
  57.    Begin TextBox Text1 
  58.       Height          =   372
  59.       Left            =   1920
  60.       TabIndex        =   20
  61.       Text            =   "Text1"
  62.       Top             =   1200
  63.       Width           =   2052
  64.    End
  65.    Begin CommandButton Command3 
  66.       Cancel          =   -1  'True
  67.       Caption         =   "Exit"
  68.       Height          =   492
  69.       Left            =   4320
  70.       TabIndex        =   18
  71.       Top             =   4320
  72.       Width           =   1932
  73.    End
  74.    Begin FileListBox File1 
  75.       Height          =   1200
  76.       Left            =   4320
  77.       TabIndex        =   9
  78.       Top             =   2280
  79.       Width           =   1935
  80.    End
  81.    Begin DirListBox Dir1 
  82.       Height          =   1752
  83.       Left            =   2040
  84.       TabIndex        =   8
  85.       Top             =   2280
  86.       Width           =   1932
  87.    End
  88.    Begin DriveListBox Drive1 
  89.       Height          =   288
  90.       Left            =   4320
  91.       TabIndex        =   12
  92.       Top             =   3720
  93.       Width           =   1932
  94.    End
  95.    Begin Frame Frame1 
  96.       BackColor       =   &H00C0C0C0&
  97.       Caption         =   "Database"
  98.       Height          =   2892
  99.       Left            =   240
  100.       TabIndex        =   0
  101.       Top             =   1920
  102.       Width           =   1452
  103.       Begin OptionButton Option1 
  104.          BackColor       =   &H00C0C0C0&
  105.          Caption         =   "Paradox 3.x"
  106.          Height          =   252
  107.          Index           =   6
  108.          Left            =   120
  109.          TabIndex        =   7
  110.          Top             =   2520
  111.          Width           =   1212
  112.       End
  113.       Begin OptionButton Option1 
  114.          BackColor       =   &H00C0C0C0&
  115.          Caption         =   "Btrieve"
  116.          Height          =   252
  117.          Index           =   5
  118.          Left            =   120
  119.          TabIndex        =   6
  120.          Top             =   2160
  121.          Width           =   1212
  122.       End
  123.       Begin OptionButton Option1 
  124.          BackColor       =   &H00C0C0C0&
  125.          Caption         =   "FoxPro 2.5"
  126.          Height          =   252
  127.          Index           =   4
  128.          Left            =   120
  129.          TabIndex        =   5
  130.          Top             =   1800
  131.          Width           =   1212
  132.       End
  133.       Begin OptionButton Option1 
  134.          BackColor       =   &H00C0C0C0&
  135.          Caption         =   "FoxPro 2.0"
  136.          Height          =   252
  137.          Index           =   3
  138.          Left            =   120
  139.          TabIndex        =   4
  140.          Top             =   1440
  141.          Width           =   1212
  142.       End
  143.       Begin OptionButton Option1 
  144.          BackColor       =   &H00C0C0C0&
  145.          Caption         =   "dBase IV"
  146.          Height          =   252
  147.          Index           =   2
  148.          Left            =   120
  149.          TabIndex        =   3
  150.          Top             =   1080
  151.          Width           =   1212
  152.       End
  153.       Begin OptionButton Option1 
  154.          BackColor       =   &H00C0C0C0&
  155.          Caption         =   "dBase III"
  156.          Height          =   252
  157.          Index           =   1
  158.          Left            =   120
  159.          TabIndex        =   2
  160.          Top             =   720
  161.          Width           =   1212
  162.       End
  163.       Begin OptionButton Option1 
  164.          BackColor       =   &H00C0C0C0&
  165.          Caption         =   "Access 1.x"
  166.          Height          =   252
  167.          Index           =   0
  168.          Left            =   120
  169.          TabIndex        =   1
  170.          Top             =   360
  171.          Width           =   1212
  172.       End
  173.    End
  174.    Begin ComboBox Combo1 
  175.       Height          =   288
  176.       Left            =   1920
  177.       Style           =   2  'Dropdown List
  178.       TabIndex        =   10
  179.       Top             =   240
  180.       Width           =   2052
  181.    End
  182.    Begin CommandButton Command1 
  183.       Caption         =   "Convert"
  184.       Default         =   -1  'True
  185.       Height          =   492
  186.       Left            =   2040
  187.       TabIndex        =   11
  188.       Top             =   4320
  189.       Width           =   1932
  190.    End
  191.    Begin Label Label6 
  192.       BackStyle       =   0  'Transparent
  193.       Caption         =   "To Spreadsheet:"
  194.       Height          =   252
  195.       Left            =   360
  196.       TabIndex        =   19
  197.       Top             =   1200
  198.       Width           =   1452
  199.    End
  200.    Begin Label Label5 
  201.       BackStyle       =   0  'Transparent
  202.       Caption         =   "Label5"
  203.       Height          =   252
  204.       Left            =   1920
  205.       TabIndex        =   17
  206.       Top             =   720
  207.       Width           =   2292
  208.    End
  209.    Begin Label Label4 
  210.       BackStyle       =   0  'Transparent
  211.       Caption         =   "From Database:"
  212.       Height          =   252
  213.       Left            =   360
  214.       TabIndex        =   16
  215.       Top             =   720
  216.       Width           =   1452
  217.    End
  218.    Begin Label Label3 
  219.       BackStyle       =   0  'Transparent
  220.       Caption         =   "Convert Table:"
  221.       Height          =   252
  222.       Left            =   480
  223.       TabIndex        =   15
  224.       Top             =   240
  225.       Width           =   1332
  226.    End
  227.    Begin Label Label2 
  228.       BackStyle       =   0  'Transparent
  229.       Caption         =   "Database or Table:"
  230.       Height          =   252
  231.       Left            =   4320
  232.       TabIndex        =   14
  233.       Top             =   1920
  234.       Width           =   1932
  235.    End
  236.    Begin Label Label1 
  237.       BackStyle       =   0  'Transparent
  238.       Caption         =   "Path of Database:"
  239.       Height          =   252
  240.       Left            =   2040
  241.       TabIndex        =   13
  242.       Top             =   1920
  243.       Width           =   1932
  244.    End
  245. 'This sample program shows you how to combine programming
  246. 'with database objects and ole automation objects.
  247. 'This program will convert a table in a database that
  248. 'the user selects, and then places it into an excel
  249. 'spreadsheet using OLE automation.
  250. 'This program assumes that you have registered Excel version
  251. '5.0 in your registration database (REG.DAT) and that
  252. 'you installed the database component for Visual Basic 3.0
  253. 'Professional.
  254. Dim db As database     'form level database object
  255. Dim Connect$           'Hold connect arguments
  256. Sub CheckEnableConvert ()
  257. 'check if table is selected and filename specified
  258. If (combo1.Text <> "") And (Text1 <> "") Then
  259.     command1.Enabled = True
  260.     command1.Enabled = False
  261. End If
  262. End Sub
  263. Sub Combo1_Click ()
  264. Call CheckEnableConvert
  265. End Sub
  266. Sub Command1_Click ()
  267. Static flag As Integer  'flag for avoiding multiple occurances
  268. Dim i As Integer        'loop counters
  269. Dim j As Integer
  270. Dim xl As object        'ole automation object
  271. Dim Sn As Snapshot      'snapshot to hold records
  272. If flag = 1 Then Exit Sub  'avoid multiple clicks
  273. flag = 1
  274. screen.MousePointer = 11   'change mousepointer
  275. 'This code performs a check for valid path and filenames
  276. 'The hidden File2 listbox has the sole purpose of validating that the
  277. 'user has entered a valid path and filename
  278. CheckPath:
  279.   label7.Caption = "Checking Valid Filename for Spreadsheet"
  280.   label7.Refresh
  281.   Text1.Tag = True            'flag if invalid filename in textbox
  282.   Do While Text1.Tag
  283.     On Error Resume Next
  284.     File2.FileName = Text1.Text
  285.     File2.Refresh
  286.     If Err = 0 Then                 'no errors
  287.         If InStr(Text1.Text, File2.List(0)) > 0 Then 'kill file if it exists
  288.             Kill Text1.Text
  289.             Text1.Tag = False
  290.         Else                        'just a directory entry, get filename
  291.             Text1.Text = InputBox("You Entered an Invalid Path or Filename, please enter a correct one: ", "DB to Excel Converter", Text1)
  292.         End If
  293.     Else
  294.         If Err <> 53 Then           'if not "file not found", get valid path/filename
  295.             Text1.Text = InputBox("You Entered an Invalid Path or Filename, please enter a correct one: ", "DB to Excel Converter", Text1)
  296.         Else
  297.             Text1.Tag = False       'valid new filename
  298.         End If
  299.     End If
  300.     On Error GoTo 0
  301.   Loop
  302. 'create our spreadsheet object
  303. label7.Caption = "Creating Excel Object"
  304. label7.Refresh
  305. Set xl = CreateObject("Excel.Sheet.5")
  306. 'set up Field names as Column names
  307. Set Sn = db.CreateSnapshot(combo1.Text)
  308. If Sn.RecordCount > 0 Then
  309.     Sn.MoveFirst
  310.     'place the fields across the top of the spreadsheet
  311.     label7.Caption = "Adding fieldnames to Spreadsheet"
  312.     label7.Refresh
  313.     For i = 0 To Sn.Fields.Count - 1
  314.         xl.cells(1, i + 1).value = Sn(i).Name
  315.     Next
  316.     'get an accurate recordcount before we start our loop
  317.     Sn.MoveLast
  318.     Sn.MoveFirst
  319.     'loop through each record
  320.     For i = 0 To Sn.RecordCount - 1
  321.         label7.Caption = "Looping through record " & CStr(i + 1) & " of " & CStr(Sn.RecordCount)
  322.         label7.Refresh
  323.         For j = 0 To Sn.Fields.Count - 1
  324.             'add each field to the spreadsheet
  325.             If Sn(j).Type < 11 Then
  326.                 xl.cells(i + 2, j + 1).value = Sn(j)
  327.             Else
  328.                 xl.cells(i + 2, j + 1).value = "binary data"
  329.             End If
  330.         Next j
  331.         Print
  332.         Sn.MoveNext
  333.     Next i
  334.     'save the spreadsheet
  335.     label7.Caption = "Saving Spreadsheet"
  336.     label7.Refresh
  337.     xl.SaveAs Text1.Text
  338.     'quit the excel object
  339.     xl.Application.Quit
  340.     'no records in recordset
  341.     label7.Caption = "No Records"
  342.     label7.Refresh
  343.     'Pause for fraction of a second to display message
  344.     x = Timer
  345.     While x + .3 > Timer
  346.     Wend
  347. End If
  348. 'clean up
  349. label7.Caption = "Cleaning Up"
  350. label7.Refresh
  351. Set xl = Nothing         'remove object variable
  352. Set Sn = Nothing         'remove snapshot object
  353. screen.MousePointer = 0  'restore mouse pointer
  354. flag = 0                 'allow user to click again
  355. label7.Caption = "Ready"
  356. label7.Refresh
  357. End Sub
  358. Sub Command3_Click ()
  359. End   'end the program
  360. End Sub
  361. Sub Dir1_Change ()
  362. File1.Path = Dir1.Path
  363. End Sub
  364. Sub Drive1_Change ()
  365. Dir1.Path = Drive1.Drive
  366. End Sub
  367. Sub File1_Click ()
  368. 'This subroutine loads the Table combo box from the selected database
  369. Const DB_SYSTEMOBJECT = &H80000002  'constant to check for system variables
  370. Dim i As Integer
  371. Dim DBName$
  372. 'set up database object
  373. If (Connect$ = "") Or (Connect$ = "Btrieve") Then
  374.     DBName$ = File1.Path & "\" & File1.FileName
  375.     DBName$ = File1.Path
  376. '    Set db = OpenDatabase(File1.Path, False, False, Connect$)
  377. '    label5.Caption = File1.Path
  378. End If
  379. Set db = OpenDatabase(DBName$, False, False, Connect$)
  380. label5.Caption = DBName$
  381. label5.Refresh
  382. 'clear the tables combo box
  383. combo1.Clear
  384. 'add new tables except system tables to the combo box
  385. For i = 0 To db.TableDefs.Count - 1
  386.     If (db.TableDefs(i).Attributes And DB_SYSTEMOBJECT) = 0 Then
  387.         combo1.AddItem db.TableDefs(i)
  388.     End If
  389. Next i
  390. 'set the combo box to point to the first table in the list
  391. combo1.ListIndex = 0
  392. End Sub
  393. Sub File1_PathChange ()
  394. 'if no items in file list box, clear the combobox
  395. If File1.ListCount = 0 Then
  396.     combo1.ListIndex = -1
  397.     combo1.Clear
  398. End If
  399. End Sub
  400. Sub Form_Load ()
  401. 'initialize some properties
  402. form1.Caption = "DB to Excel Converter"
  403. combo1.ListIndex = -1
  404. command1.Enabled = False
  405. Text1.Text = CurDir & "\tmp.xls"   'init the text box
  406. label5.Caption = ""                   'clear the caption
  407. label7.Caption = "Ready"              'init status bar
  408. End Sub
  409. Sub Form_QueryUnload (Cancel As Integer, UnloadMode As Integer)
  410. Set db = Nothing    'destroy our global database
  411. End Sub
  412. Sub Option1_Click (index As Integer)
  413. 'setup the connect property for Opendatabase
  414. Connect$ = Option1(index).Caption
  415. 'set the pattern to look for in the filelist box
  416. Select Case index
  417.     Case 0
  418.         File1.Pattern = "*.mdb"
  419.         Connect$ = ""
  420.     Case 1, 2, 3, 4
  421.         File1.Pattern = "*.dbf"
  422.     Case 5
  423.         File1.Pattern = "field.ddf"
  424.     Case 6
  425.         File1.Pattern = "*.db"
  426. End Select
  427. End Sub
  428. Sub Text1_Change ()
  429. Call CheckEnableConvert
  430. End Sub
  431.