• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 368
  • Last Modified:

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
0
isnoend2001
Asked:
isnoend2001
  • 2
  • 2
1 Solution
 
MacroShadowCommented:
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.
0
 
isnoend2001Author Commented:
.Net frameworks ?
this is vb6
0
 
MacroShadowCommented:
Oops sorry didn't realize that.

Anyway the same applies for vb6. You could use CCur(mlblCreditBeforeRun) to convert long (or any other data type) to currency and CLng(mlblCreditBeforeRun) to convert currency (or any other data type) to long.
0
 
isnoend2001Author Commented:
Guess i will use string
for calculations
CCur(mlblCreditBeforeRun) if currency
Val(mlblCreditBeforeRun) if not
0
 
advfinanceCommented:
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:

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

Open in new window


Output:

Value = 1, VarType = 6, TypeName = Currency
Value = 1, VarType = 3, TypeName = Long

Open in new window


--
Chris
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now