Varible Not Defined

coolcatkelso

Registered User.
Local time
Today, 17:20
Joined
Jan 5, 2009
Messages
279
Getting Variable Not Defined Error

Code:
Option Compare Database
Option Explicit
Dim fs As New FileSystemObject

Private Sub Command1_Click()
Set fs = CreateObject("Scripting.FileSystemObject")
 fs.CreateTextFile "C:\Demo\TEST.txt" 'Create a file - change this to any directory you wangt to hide the text file
'Write to file
 Set f = fs.getfile("C:\Demo\TEST.txt")
 Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)
ts.writeline "Thanks for using this Software" 'change this to what you want
ts.Close
End Sub

This is the line of the error
Set f = fs.getfile("C:\Demo\TEST.txt")
________
JUSTIN BIEBER FANS
 
Last edited:
Getting Variable Not Defined Error

Code:
Option Compare Database
Option Explicit
Dim fs As New FileSystemObject

Private Sub Command1_Click()
Set fs = CreateObject("Scripting.FileSystemObject")
 fs.CreateTextFile "C:\Demo\TEST.txt" 'Create a file - change this to any directory you wangt to hide the text file
'Write to file
 Set f = fs.getfile("C:\Demo\TEST.txt")
 Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)
ts.writeline "Thanks for using this Software" 'change this to what you want
ts.Close
End Sub

This is the line of the error
Set f = fs.getfile("C:\Demo\TEST.txt")

you have dimmed the fs variable outside of your subroutine. if this code is behind an object instead of in a module, which it obviously is, dim it INSIDE the routine, OR dim it OUTSIDE of the routines in a DEC section like so:
PHP:
private fs as WHATEVER
 
Should have a

Dim f As Object

somewhere in there.
 

Users who are viewing this thread

Back
Top Bottom