Changes

Hints and Recipes for VB6

1,899 bytes removed, 17:01, 2 February 2008
The following lines were added (+) and removed (-):
== Write/Create a new file using FileSystemObject ==*must add 'reference' to "Microsoft Scripting Runtime"  Dim fso As New FileSystemObject, fsoStream As TextStream  Dim rec1, strLine, strFileSpec  Dim cnt0 As Integer, tag1 As Integer  strFileSpec = Environ("HOMEPATH") & "\My Documents\kaching.log"  strLine = "kaching incident " & Date & " " & Format(time, "HH:mm:ss") & vbCrLf  Set fsoStream = fso.CreateTextFile(strFileSpec, True)  fsoStream.Write strLine  fsoStream.Close  Set fsoStream = Nothing: Set fso = Nothing== Write if exists, create if doesn't exist using FileSystemObject ==  If fso.FileExists(strFileSpec) Then    Set fsoStream = fso.OpenTextFile(strFileSpec, 2)  Else    Set fsoStream = fso.CreateTextFile(strFileSpec, True)  End If    fsoStream.Write strLine  fsoStream.Close  Set fsoStream = Nothing: Set fso = Nothing  ' strFileSpec, 1 : ForReading 2 : ForWriting  8 : ForAppending  == Write to control on another form and display ==  Dim lblCaught As Label  Set lblCaught = frmKaching.lblCaught  frmKaching.WindowState = vbNormal  lblCaught = "You've Been Naughty!"  frmKaching.Show== Determine is a form has been loaded ==The wrong way:  if form1.visible = true thenThe reason:Due to the way an intrinsic variable instance works in VB, the line above will actually cause form1 to load.  Forms are loaded automatically whenever referenced in code, whether loaded visibly or not.Special thanks to a gentleman named Steve Gerrard who posted a correct sample script on another forum.  His example works by going through a list of loaded forms and matching by the form name you are looking for.  Public Function FormIsLoaded(FormName As String) As Boolean    Dim oFrm As Form    For Each oFrm In Forms      If oFrm.Name = FormName Then        FormIsLoaded = True        Exit For      End If    Next oFrm  End Functionlovely!
Bureaucrat, administrator
16,192
edits