Results 1 to 3 of 3

Thread: Form will not show until sub has completed. [SOLVED]

  1. #1

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

    Form will not show until sub has completed. [SOLVED]

    Ok, got rid of all the headaches in the search algorithm I used, it shows the startup form, but I have another form with a progress bar on it, and that won't show until the algorithm has completed its routine.

    VB Code:
    1. 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 lstItem As ListItem
    7.     Set fso = New FileSystemObject
    8.     If Not FolderSpec = "D" 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.lvwVolumes.ListItems.Add(, , thisFile.Name)
    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 rs = Nothing
    29.     Set fso = Nothing
    30.     Exit Sub
    31. End Sub

    And here's where I call the form.

    VB Code:
    1. Sub ProcessDeviceChange(wParam As Long, lParam As Long)
    2.     Dim DBHdr As DEV_BROADCAST_HDR
    3.     Dim DBVol As DEV_BROADCAST_VOLUME
    4.     CopyMemory DBHdr, ByVal lParam, LenB(DBHdr)
    5.     If wParam = DBT_DEVICEARRIVAL Then
    6.         If DBHdr.dbch_devicetype = DBT_DEVTYP_VOLUME Then
    7.             CopyMemory DBVol, ByVal lParam, LenB(DBVol)
    8.             If (DBVol.dbcv_flags And DBTF_MEDIA) = DBTF_MEDIA Then
    9.                 frmSetup.Show
    10.             End If
    11.         End If
    12.     End If
    13. End Sub
    Last edited by hothead; Apr 30th, 2004 at 06:23 PM.

  2. #2
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    Uhm... I don't see where you call ScanFolder... nor the progress bar code. If you call this from fom_load, that may be the problem. Try form_activate instead.

  3. #3

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    Thanks, that worked.

    Yes, I was calling it from Form_Load

    VB Code:
    1. Private Sub Form_Load()
    2.     Dim drv As Drive
    3.     CenterForm Me
    4.     Set fso = New FileSystemObject
    5.     For Each drv In fso.Drives
    6.         If drv.DriveType = CDRom Then
    7.             If drv.IsReady = True Then
    8.                 ScanFolder drv.DriveLetter
    9.             Else
    10.                 Exit Sub
    11.             End If
    12.         End If
    13.     Next
    14.     For i = 1 To frmMain.lvwVolumes.ListItems.Count
    15.         TotalCDSize = TotalCDSize + frmMain.lvwVolumes.ListItems(i).SubItems(1)
    16.     Next i
    17.     For i = 1 To frmMain.lvwVolumes.ListItems.Count
    18.        
    19.         BytesProcessed = BytesProcessed + frmMain.lvwVolumes.ListItems(i).SubItems(1)
    20.         pbrProgress.Value = BytesProcessed / TotalCDSize
    21.     Next i
    22.     Set fso = Nothing
    23. End Sub

    Moving it to Form_Activate worked.

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