Wrox Programmer Forums
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 8th, 2007, 07:00 PM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
Default ByRef Argument!

What is a ByRef Argument Type Mismatch?? Any ideas, this is the code im using also if its any help im using the microsoft scripting runtime reference!

Code:
Dim FSO As Scripting.FileSystemObject
Dim Folder As String
Folder = "C:\Files"
Set FSO = New Scripting.FileSystemObject
If FSO.FolderExists(Folder) Then
FindFiles (Folder)
Else
MsgBox "Folder Doesn't exist :S"
End If
Now the FindFiles is a function which in the brackets requires this
Code:
FindFiles(dirDirectory As Scripting.Folder)
Any ideas?

Cheers


------------------------------------------------
Apocolypse2005
Always ready and waiting to be helped!
__________________
Apocolypse2005, I'm a programmer - of sorts.
 
Old August 8th, 2007, 11:32 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

FindFiles(dirDirectory As Scripting.Folder) Function expects the reference type as Scripting.Folder

whereas you are passing a string named 'Folder'

FindFiles (Folder)

That is the cause for the error

Regards
Shasur

http://www.dotnetdud.blogspot.com
 
Old August 9th, 2007, 06:36 AM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
Default

Im using this new code, but now im getting a type mismatch the cmdSearch is getting highlighted in yellow d the statement FindFiles (Folder) is highlight in blue(normal text highlight)
Code:
Private Sub cmdSearch_Click()
Dim FSO As Scripting.FileSystemObject
Dim Folder As Scripting.Folder

Set FSO = New Scripting.FileSystemObject
Set Folder = FSO.GetFolder("C:\Files")

If FSO.FolderExists(Folder) Then
FindFiles (Folder) 'This is highlighted!
Else
MsgBox "Folder Doesn't exist :S"
End If

End Sub
Any ideas?!

Cheers

------------------------------------------------
Apocolypse2005
Always ready and waiting to be helped!
 
Old August 9th, 2007, 08:14 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there.. maybe an error inside findfiles????

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old August 9th, 2007, 11:57 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

What is this "FindFiles()?" It appears to be something you (the generic you) have written. I find no such routine in the Scripting library, or in the VB libraries.

Putting the argument in parens indicates that it is a function, and will return something, yet you have nothing set to do that receiving. So it should be
Code:
    <Something> = FindFiles(Folder)
    Set <Something> = FindFiles(Folder)
    ' Or
    FindFiles Folder
    What does FindFiles() do?

Could you use better-formed text in your posts? [u]You</u> know what you mean, but [u]we</u> have to rely on what you type. For instance, “. . . , but now im getting a type mismatch the cmdSearch is getting highlighted in yellow . . . ” doesn't actually mean anything. (Plus, it is standard to capitalize “I.” Plus, contractions—‘im’ should be ‘I’m’—require apostrpophes. Sometimes making haste slows things down...) It appears to mean, “. . . , but now im getting a type mismatch. The statement ‘cmdSearch’ is getting highlighted in yellow . . . ” (You did say “Always ready and waiting to be helped!” Just trying to help...)

If that’s right, that’s the behavior when a routine (cmdSearch() in this case) won’t compile. (When the routine compiles but hits an error while trying to execute a given line, then that individual line is highlighted.) The highlight indicates the progress of the running. Everything up to the highlight has run, but it is stopped trying to execute at that which is highlit. So knowing more about FindFiles() would help resolve where the problem lies.
 
Old August 9th, 2007, 01:39 PM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
Default

Just for you mr wren!
the findfiles is a function created by me the (generic me), here is the code!
Code:
Sub FindFiles(dirDirectory As Scripting.Folder)
Dim FSFile As Scripting.File

For Each FSFile In dirDirectory.Files
If LCase(Right(.Name, 4)) = ".txt" Then
AddFiles FSFile.Name
End If
Next FSFile

Set FSFile = Nothing

End Sub
Have a browse on that!


------------------------------------------------
Apocolypse2005
Always ready and waiting to be helped!
 
Old August 9th, 2007, 01:54 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

if you trace this code it's get goes ok?? what if a file name is "a" (just a letter, only one, the right will fail)

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old August 9th, 2007, 01:57 PM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
Default

Well i've tried to F8 it (step by step on each line) but as soon as i click on the button it just straight to an error, i dont know how to go through the findfiles step by step.
 
Old August 9th, 2007, 02:07 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

ok.. try the functions on my vb..

it fails because of this:
Code:
FindFiles Folder
(remove this () )

and it will work.. but take in mind what I tell you about filenames...

and also this line is wrong:
Code:
If LCase(Right(.Name, 4)) = ".txt" Then
should be:
Code:
If LCase(Right(FSFile.Name, 4)) = ".txt" Then
HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old August 9th, 2007, 02:12 PM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
Default

Hmmm, well my comp crashed last night when i was sorting all that out and of course it wasnt saved so i'll have to go back and change that again. Thanks alot for the help, it was actually helpful, lol!





Similar Threads
Thread Thread Starter Forum Replies Last Post
ByRef property rolandatem VB.NET 2002/2003 Basics 1 October 8th, 2005 08:42 AM
byRef ? g2000 Classic ASP Basics 0 August 18th, 2005 09:37 AM
ByRef and ByVal kgs51 Beginning VB 6 2 November 2nd, 2004 08:09 PM
byref Argument type mismatch in vb Vijay_VB VB How-To 1 August 16th, 2004 08:53 AM
Arrays seem to be passed byRef always srbeckle VB.NET 2002/2003 Basics 0 July 25th, 2003 10:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.