isnoend2001
asked on
Declare a form level variable vb6
I have a label(lblCredit) that depending on the mode could be formated as Currency eg; $2.64 or long:264. I want to store the value in a form level variable before a run but after the run the value is updated.
eg
Dim mlblCreditBeforeRun as ?? string,
what would be the best way to declare it, string probably
eg
Dim mlblCreditBeforeRun as ?? string,
what would be the best way to declare it, string probably
I don't think it matters, you could use any of the .Net frameworks native conversion methods to convert from long to currency and vice verse.
ASKER
.Net frameworks ?
this is vb6
this is vb6
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Guess i will use string
for calculations
CCur(mlblCreditBeforeRun) if currency
Val(mlblCreditBeforeRun) if not
for calculations
CCur(mlblCreditBeforeRun) if currency
Val(mlblCreditBeforeRun) if not
You could declare the variable as Variant. Then, when setting the value, use an appropriate type conversion function (CCur, CLng, etc). Later, when reading the value, you could use the VarType function to determine the current type if you need to take different action dependant upon the type.
Example:
Output:
--
Chris
Example:
Option Explicit
Private Sub Form_Load()
Dim Value As Variant
Value = CCur(1)
GoSub PrintValueAndType
Value = CLng(1)
GoSub PrintValueAndType
Exit Sub
PrintValueAndType:
Debug.Print "Value = " & Value & _
", VarType = " & VarType(Value) & _
", TypeName = " & TypeName(Value)
Return
End Sub
Output:
Value = 1, VarType = 6, TypeName = Currency
Value = 1, VarType = 3, TypeName = Long
--
Chris