View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
GS[_6_] GS[_6_] is offline
external usenet poster
 
Posts: 1,182
Default Problem with class variable and Personal.xlsb

It sounds like you want to use your class as a separate object rather than
include it in each VBA Project you want to use it in. Not a good idea! Just
insert the class into each project you want to use it in so it is exclusive to
that project and NOT USED BY ANY OTHER PROJECTS!

Then you should create a variable local to each routine that uses it,
instantiate it, then destroy it when done with it after each use.

Not sure why you are going to this extent when Debug.Print works for most
developers during design time, but most will log to a text file via a central
logger component, which, in most cases is part of their error handling system.
Ideally, though, the process to write to the log file should be a stand-alone
reusable routine that accepts a FileOut, TextOut, and output mode as args. For
example:


Sub FSO_WriteTextFile(FileOut, TextOut, ioMode)
' Reusable procedure that Writes or Appends
' large amounts of data to a Text file in one single step.
' **Does not create a blank line at the end of the file**

Dim oFSO, oFile

On Error GoTo ErrHandler
Set oFSO = CreateObject("Scripting.FileSystemObject")
If ioMode = lOpenA Then '//add to file contents
Set oFile = oFSO.OpenTextFile(FileOut, lOpenA)
oFile.Write (vbCrLf & TextOut)
Else '//overwrite file
Set oFile = oFSO.CreateTextFile(FileOut, lOpenW)
oFile.Write (TextOut)
End If

'ErrHandler:
oFile.Close: Set oFSO = Nothing: Set oFile = Nothing
End Sub

-OR-

Sub WriteTextFile(ByVal TextOut$, Filename$, _
Optional AppendMode As Boolean = False)
' Reusable procedure that Writes/Overwrites or Appends
' large amounts of data to a Text file in one single step.
' **Does not create a blank line at the end of the file**
Const sSrc$ = "WriteTextFile"

Dim iNum%
On Error GoTo ErrHandler
iNum = FreeFile()
If AppendMode Then '//start a new line
Open Filename For Append As #iNum: Print #iNum, vbCrLf & TextOut;
Else '//overwrite existing file
Open Filename For Output As #iNum: Print #iNum, TextOut;
End If

ErrHandler:
Close #iNum: If Err Then Err.Raise Err.Number, sSrc, Err.Description
End Sub 'WriteTextFile()

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion