Difference between revisions of "Hints and Recipes for VB6"
From Free Knowledge Base- The DUCK Project: information for everyone
Line 14: | Line 14: | ||
End With | End With | ||
cboDelimiter = "TAB" | cboDelimiter = "TAB" | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== Delay without using a Timer control == | == Delay without using a Timer control == | ||
Line 60: | Line 24: | ||
Loop | Loop | ||
End Sub | End Sub | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== Quickly determine which option button is selected == | == Quickly determine which option button is selected == |
Revision as of 12:01, 2 February 2008
Contents
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"
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
Quickly determine which option button is selected
Often OptionButton controls are arranged in control arrays. To quickly find the index of the only selected OptionButton control apply this little math trick. The following example assumes there are 3 option buttons in a control array.
intSelected = Option(0).Value * 0 - Option(1).Value * 1 - Option(2).Value * 2
Note that the first operand is always zero, and you can simplify the above expression as follows:
intSelected = -Option(1).Value - Option(2).Value * 2
Credit to Ed Lampman for this VB trick.