Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code doesn't work

Status
Not open for further replies.

wmbb

Technical User
Jul 17, 2005
320
NL
Why does the code below not work...
Why is the the variable "f" not available in Public Sub SDB() ?

Code:
Public Sub ReadTxtImport()

On Error GoTo Err_ReadTxtImport

Dim fs As FileSystemObject, fd As Folder, fc As Files, f As File, ts As TextStream

Dim strFolder As String

strFolder = "C:\test\resultaten"

Set fs = CreateObject("Scripting.FileSystemObject")
Set fd = fs.GetFolder(strFolder)
Set fc = fd.Files

    For Each f In fc
                              
                If System.PrivateProfileString(f, "System", "Type") = "SDB" Then
                    SDB
                end If
    Next

Exit_ReadTxtImport:

ts.Close

Set ts = Nothing
Set fc = Nothing
Set fd = Nothing
Set fs = Nothing

Exit Sub

Err_ReadTxtImport:
Debug.Print Err.Number, Err.Description

End Sub
_______________________________________________________________________________

Public Sub SDB()
MsgBox System.PrivateProfileString(f, "System", "Type")
End Sub
 
Replace this:
Public Sub SDB()
with this:
Public Sub SDB(f As File)

and this:
SDB
with either this:
SDB f
or this:
Call SDB(f)

In the VBA help have a look at scope.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanx for your help and quick response.

This works fine.
Now I can go creating the rest of the code.
 
I hope you took PHV's suggestion to look up Scope in Help, and really try to understand it. Scope is VERY important, and truly understanding it will help you immensely. It will answer your question:

"Why is the the variable "f" not available in Public Sub SDB() ?"

There is a reason why..."f" is not in Scope.

PHV's suggestions to fix things are correct, and I am glad it works for you. Really understanding Scope will help you even more.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top