Solved

Declare a form level variable vb6

Posted on 2014-02-06
5
355 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 27

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 27

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

820 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