|
-
Mar 5th, 2007, 10:53 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Type mismatch error
Hi peeps.
Ca anyone see what I'm doing wrong here
vbCode Code:
Dim Extra As String
Dim oFS As FileSystemObject
Dim oFolder As Folder
Dim oFile As File
Extra = DwgsPath & "\"
DWFileCount = 0
Set oFS = New FileSystemObject
Set oFolder = oFS.GetFolder(Extra)
For Each oFile In oFolder.Files
List1.AddItem oFile.Name
Label1.Visible = True
DWFileCount = DWFileCount + 1 'COUNT NUMBER OF FILES
Next oFile
Set oFolder = Nothing
Set oFS = Nothing
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. 
-
Mar 5th, 2007, 10:59 AM
#2
Hyperactive Member
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?
-
Mar 5th, 2007, 11:08 AM
#3
Thread Starter
Addicted Member
Re: Type mismatch error
It's a global var holding the path to a folder without a trailing '\'
-
Mar 5th, 2007, 11:16 AM
#4
Hyperactive Member
Re: Type mismatch error
 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.
-
Mar 5th, 2007, 11:17 AM
#5
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)
-
Mar 5th, 2007, 11:25 AM
#6
Thread Starter
Addicted Member
Re: Type mismatch error
 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)
-
Mar 5th, 2007, 11:37 AM
#7
Re: Type mismatch error
Are you just after a list of all the files in a specific folder?
-
Mar 5th, 2007, 11:41 AM
#8
Thread Starter
Addicted Member
Re: Type mismatch error
My program is constantly evolving but at the moment the answer is yes.
-
Mar 5th, 2007, 11:42 AM
#9
Hyperactive Member
Re: Type mismatch error
 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.
-
Mar 5th, 2007, 11:43 AM
#10
Re: Type mismatch error
 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:
'in a listview with date/time stamp and size
Private Sub Command1_Click()
Dim lngSize As Long
Dim strStamp As String
Dim strLoad As String
Dim lvwItem As ListItem
ListView1.ListItems.Clear
strLoad = Dir("d:\*.*")
Do While strLoad > vbNullString
strStamp = FileDateTime("d:\" & strLoad)
lngSize = FileLen("d:\" & strLoad)
Set lvwItem = ListView1.ListItems.Add(, , strLoad)
lvwItem.SubItems(1) = lngSize
lvwItem.SubItems(2) = strStamp
strLoad = Dir
Loop
End Sub
'in a listbox with just the file name
Private Sub Command1_Click()
Dim strLoad As String
List1.Clear
strLoad = Dir("d\*.*")
Do While strLoad > vbNullString
List1.AddItem strLoad
strLoad = Dir
Loop
End Sub
-
Mar 5th, 2007, 11:55 AM
#11
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
-
Mar 5th, 2007, 01:27 PM
#12
Thread Starter
Addicted Member
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
-
Mar 5th, 2007, 01:49 PM
#13
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.
-
Mar 6th, 2007, 03:19 AM
#14
Thread Starter
Addicted Member
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
-
Mar 6th, 2007, 03:35 AM
#15
Re: Type mismatch error
 Originally Posted by bushmobile
another way
vb 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
Ha Ha. Nice code. 
I knew filelistbox is an extended listbox. But never thought it would be so easy.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|