Solved

Declare a form level variable vb6

Posted on 2014-02-06
5
350 Views
Last Modified: 2014-02-07
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
Comment
Question by:isnoend2001
  • 2
  • 2
5 Comments
 
LVL 26

Expert Comment

by:MacroShadow
ID: 39841127
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
 

Author Comment

by:isnoend2001
ID: 39841138
.Net frameworks ?
this is vb6
0
 
LVL 26

Accepted Solution

by:
MacroShadow earned 500 total points
ID: 39841173
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
 

Author Closing Comment

by:isnoend2001
ID: 39841184
Guess i will use string
for calculations
CCur(mlblCreditBeforeRun) if currency
Val(mlblCreditBeforeRun) if not
0
 
LVL 5

Expert Comment

by:advfinance
ID: 39841441
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now