Hints and Recipes for VB6

From Free Knowledge Base- The DUCK Project: information for everyone
Revision as of 09:27, 3 June 2007 by Admin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Date and Time examples with formatting options

 strTimeStamp = Date & " " & Format(Time, "HH:mm:ss")
 strMsg = strMsg & "date/time of request: " & Date & " " & Time & vbCrLf
 strSQLdate = Format(Date, "M/d/yyyy")

Combobox

 With cboDelimiter
   .AddItem "TAB"
   .AddItem "PIPE"
   .AddItem "SPACE"
   .AddItem "fancy!"
 End With
 cboDelimiter = "TAB"

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

Delay without using a Timer control

 Public Sub LongDelay(intSeconds As Long)
   Dim cnt As Double
   cnt = Timer + intSeconds
   Do While Timer < cnt
     DoEvents
   Loop
 End Sub