Results 1 to 3 of 3

Thread: Serious bug, need help fixing. [SOLVED]

  1. #1

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692

    Serious bug, need help fixing. [SOLVED]

    Take a look at the following code snippets.

    VB Code:
    1. Private Sub ScanFolder(FolderSpec)
    2.     Dim ThisFolder As Folder
    3.     Dim AllFolders As Folders
    4.     Dim ThisFile As File
    5.     Dim AllFiles As Files
    6.     Dim i As Integer
    7.     Set fso = New FileSystemObject
    8.     If Not Len(FolderSpec) = 1 Then
    9.         Set ThisFolder = fso.GetFolder(FolderSpec & "\")
    10.     Else
    11.         Set ThisFolder = fso.GetFolder(FolderSpec & ":")
    12.     End If
    13.     Set AllFolders = ThisFolder.SubFolders
    14.     For Each ThisFolder In AllFolders
    15.         Set AllFiles = ThisFolder.Files
    16.         If AllFiles.Count > 0 Then
    17.             For Each ThisFile In AllFiles
    18.                 Set lstItem = frmMain.lvwFileList.ListItems.Add(, , ThisFile.Path)
    19.                 lstItem.SubItems(1) = ThisFile.Size
    20.             Next
    21.         End If
    22.         Set AllFiles = Nothing
    23.         ScanFolder ThisFolder.Path
    24.         DoEvents
    25.     Next
    26.     Set ThisFolder = Nothing
    27.     Set AllFolders = Nothing
    28.     Set fso = Nothing
    29.     Set lstItem = Nothing
    30.     Unload Me
    31. End Sub
    32.  
    33. Private Sub Form_Activate()
    34.     Dim drv As Drive
    35.     Dim rs As ADODB.Recordset
    36.     Set rs = New ADODB.Recordset
    37.     KeepOnTop Me
    38.     CenterForm Me
    39.     Response = InputBox("Enter a label for this volume.", "Enter volume label")
    40.     rs.Open dtaVolumes.RecordSource, dtaVolumes.ConnectionString, adOpenKeyset, adLockOptimistic
    41.     Set fso = New FileSystemObject
    42.     For Each drv In fso.Drives
    43.         If drv.DriveType = CDRom Then
    44.             If drv.IsReady = True Then
    45.                 ScanFolder drv.DriveLetter
    46.             Else
    47.                 Exit Sub
    48.             End If
    49.         End If
    50.     Next
    51.     For i = 1 To frmMain.lvwFileList.ListItems.Count
    52.         TotalCDSize = TotalCDSize + frmMain.lvwFileList.ListItems(i).SubItems(1)
    53.         rs.AddNew
    54.         rs!Name = Response
    55.         rs!Date_Created = Date
    56.         rs!Files = frmMain.lvwFileList.ListItems(i)
    57.     Next i
    58.     For i = 1 To frmMain.lvwFileList.ListItems.Count
    59.         BytesProcessed = BytesProcessed + frmMain.lvwFileList.ListItems(i).SubItems(1)
    60.         pbrProgress.Value = BytesProcessed / TotalCDSize
    61.     Next i
    62.     Set lstItem = frmMain.lvwVolumes.ListItems.Add(, , Response)
    63.     lstItem.SubItems(1) = Date
    64.     lstItem.SubItems(2) = frmMain.lvwFileList.ListItems.Count
    65.     frmMain.lvwFileList.ListItems.Clear
    66.     Set fso = Nothing
    67.     Set rs = Nothing
    68.     Set lstItem = Nothing
    69. End Sub

    My problem is this: When the code is as it stands right now, the program works fine, but of course the progress bar won't run because of the Unload Me in the ScanFolder sub. However, if I put the Unload Me in the Form_Activate event, the code runs multiple times, and eventually errors out with an unspecified error when it executes the rs.Open procedure.

    When I step through the code one line at a time, the code works like it's supposed to with Unload Me in the Form_Activate event.

    I can't put it in the Form_Load event either, else frmSetup doesn't show until the entire procedure is finished.
    Last edited by hothead; May 6th, 2004 at 08:29 PM.

  2. #2
    Member
    Join Date
    Mar 2004
    Location
    Canada
    Posts
    47
    I can't put it in the Form_Load event either, else frmSetup doesn't show until the entire procedure is finished
    I ran into a little problem like this and I don't know exactly how i fixed it . Try a frmSetup.refresh at the start of the form load then a few doevents, or frmSetup.visible = true. (Hope it works)
    Dave

  3. #3

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692

    Post

    It's fixed, thanks a lot.
    Last edited by hothead; May 6th, 2004 at 08:28 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width