Results 1 to 15 of 15

Thread: [RESOLVED] Type mismatch error

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    New Romney, Kent, UK
    Posts
    232

    Resolved [RESOLVED] Type mismatch error

    Hi peeps.

    Ca anyone see what I'm doing wrong here

    vbCode Code:
    1. Dim Extra As String
    2. Dim oFS As FileSystemObject
    3. Dim oFolder As Folder
    4. Dim oFile As File
    5. Extra = DwgsPath & "\"
    6. DWFileCount = 0
    7.  
    8. Set oFS = New FileSystemObject
    9. Set oFolder = oFS.GetFolder(Extra)
    10. For Each oFile In oFolder.Files
    11.    List1.AddItem oFile.Name
    12.  Label1.Visible = True
    13.  DWFileCount = DWFileCount + 1  'COUNT NUMBER OF FILES
    14. Next oFile
    15. Set oFolder = Nothing
    16. Set oFS = Nothing
    17. Text2.Text = Text2.Text & "Identifying Dwg files.........Completed" & vbNewLine & DWFileCount & vbNewLine

    "For Each oFile In oFolder.Files" is the bit that is highlighted as being he error.

    your comments would be appreciated.


  2. #2
    Hyperactive Member Capp's Avatar
    Join Date
    May 2005
    Location
    Texas
    Posts
    409

    Re: Type mismatch error

    Where do you have what "DwgsPath" is set to?

    I see you have it set like this:

    Code:
    Extra = DwgsPath & "\"
    but what is DwgsPath set to?
    AmazingAntivirus.com
    Remote Data Backups


    Please Mark your Thread "Resolved", if the query is solved...

    If a post has helped you then Please Rate it!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    New Romney, Kent, UK
    Posts
    232

    Re: Type mismatch error

    It's a global var holding the path to a folder without a trailing '\'

  4. #4
    Hyperactive Member Capp's Avatar
    Join Date
    May 2005
    Location
    Texas
    Posts
    409

    Re: Type mismatch error

    Quote Originally Posted by GettinBetter
    It's a global var holding the path to a folder without a trailing '\'
    Ok.

    When you run it and it breaks at that specific line, have you moved the mouse over the items in the lines above it?

    MouseOver oFile and oFolder.Files and see what value it shows you.
    AmazingAntivirus.com
    Remote Data Backups


    Please Mark your Thread "Resolved", if the query is solved...

    If a post has helped you then Please Rate it!

  5. #5
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Type mismatch error

    try changing the declarations to:
    Code:
        Dim oFolder As Scripting.Folder
        Dim oFile As Scripting.File
    (but if you just want to populate a listbox with files from a folder then there are faster ways)

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    New Romney, Kent, UK
    Posts
    232

    Re: Type mismatch error

    Quote Originally Posted by Capp
    Ok.

    When you run it and it breaks at that specific line, have you moved the mouse over the items in the lines above it?

    MouseOver oFile and oFolder.Files and see what value it shows you.
    yup, oFile is 'Nothing' and oFolder.Files doesn't show anything..

    .... And
    bushmobile
    prefixing with "Scripting." worked.

    Very much appreciate your replies. thx again.


    PS. Faster ways?? (I'm quite green at this really)

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Type mismatch error

    Are you just after a list of all the files in a specific folder?

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    New Romney, Kent, UK
    Posts
    232

    Re: Type mismatch error

    My program is constantly evolving but at the moment the answer is yes.

  9. #9
    Hyperactive Member Capp's Avatar
    Join Date
    May 2005
    Location
    Texas
    Posts
    409

    Re: Type mismatch error

    Quote Originally Posted by GettinBetter
    yup, oFile is 'Nothing' and oFolder.Files doesn't show anything..

    .... And
    bushmobile
    prefixing with "Scripting." worked.

    Very much appreciate your replies. thx again.


    PS. Faster ways?? (I'm quite green at this really)

    Well, glad you got it working one way or another. It sounds like there was a problem with it finding the correct file path.
    AmazingAntivirus.com
    Remote Data Backups


    Please Mark your Thread "Resolved", if the query is solved...

    If a post has helped you then Please Rate it!

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Type mismatch error

    Quote Originally Posted by GettinBetter
    My program is constantly evolving but at the moment the answer is yes.
    Here are two ways without using the FSO
    vb Code:
    1. 'in a listview with date/time stamp and size
    2. Private Sub Command1_Click()
    3. Dim lngSize As Long
    4. Dim strStamp As String
    5. Dim strLoad As String
    6. Dim lvwItem As ListItem
    7. ListView1.ListItems.Clear
    8. strLoad = Dir("d:\*.*")
    9. Do While strLoad > vbNullString
    10.    strStamp = FileDateTime("d:\" & strLoad)
    11.    lngSize = FileLen("d:\" & strLoad)
    12.    Set lvwItem = ListView1.ListItems.Add(, , strLoad)
    13.     lvwItem.SubItems(1) = lngSize
    14.     lvwItem.SubItems(2) = strStamp
    15.    strLoad = Dir
    16. Loop
    17. End Sub
    18.  
    19. 'in a listbox with just the file name
    20. Private Sub Command1_Click()
    21. Dim strLoad As String
    22. List1.Clear
    23. strLoad = Dir("d\*.*")
    24. Do While strLoad > vbNullString
    25.    List1.AddItem strLoad
    26.    strLoad = Dir
    27. Loop
    28. End Sub

  11. #11
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Type mismatch error

    another way
    Code:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
        ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
        
    Private Const LB_DIR = &H18D
    Private Const DDL_ARCHIVE = &H20
    Private Const DDL_EXCLUSIVE = &H8000
    
    Private Sub Command1_Click()
        List1.Clear
        SendMessage List1.hwnd, LB_DIR, DDL_EXCLUSIVE Or DDL_ARCHIVE, ByVal "C:\Windows\*.*"
    End Sub

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    New Romney, Kent, UK
    Posts
    232

    Re: Type mismatch error

    Hey, thx guys, the are great examples (not just for me I think), but I have to ask.....

    What are the advantages, of the methods posted.

    I'm just beginning to use APIs and would love a bit of a heads up on the different methods.

    All the best

  13. #13
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Type mismatch error

    I distinctly don't like using the FSO, so I always code around it.

    One of the beauties of using APIs is that, as you can see, the code is much smaller.

    To me, it becomes a matter of individual style and taste. When I first started learning about APIs, I used them for EVERYTHING.

    Now, I use them when I need to.

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    New Romney, Kent, UK
    Posts
    232

    Re: [RESOLVED] Type mismatch error

    Mmm.... yes it certainly is, and I've put it in and it works a treat..
    Cant thank you peeps enough...

    All the best see you soon (no doubt) lol

  15. #15
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: Type mismatch error

    Quote Originally Posted by bushmobile
    another way
    vb Code:
    1. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    2.     ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    3.    
    4. Private Const LB_DIR = &H18D
    5. Private Const DDL_ARCHIVE = &H20
    6. Private Const DDL_EXCLUSIVE = &H8000
    7.  
    8. Private Sub Command1_Click()
    9.     List1.Clear
    10.     SendMessage List1.hwnd, LB_DIR, DDL_EXCLUSIVE Or DDL_ARCHIVE, ByVal "C:\Windows\*.*"
    11. End Sub
    Ha Ha. Nice code.
    I knew filelistbox is an extended listbox. But never thought it would be so easy.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


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