Declare a form level variable vb6

Posted on 2014-02-06
Medium Priority
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.
Dim mlblCreditBeforeRun as ?? string,
what would be the best way to declare it, string probably
Question by:isnoend2001
  • 2
  • 2
LVL 28

Expert Comment

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.

Author Comment

ID: 39841138
.Net frameworks ?
this is vb6
LVL 28

Accepted Solution

MacroShadow earned 2000 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.

Author Closing Comment

ID: 39841184
Guess i will use string
for calculations
CCur(mlblCreditBeforeRun) if currency
Val(mlblCreditBeforeRun) if not

Expert Comment

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.


Option Explicit

Private Sub Form_Load()
    Dim Value As Variant
    Value = CCur(1)
    GoSub PrintValueAndType
    Value = CLng(1)
    GoSub PrintValueAndType
    Exit Sub
    Debug.Print "Value = " & Value & _
                ", VarType = " & VarType(Value) & _
                ", TypeName = " & TypeName(Value)

End Sub

Open in new window


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

Open in new window


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

621 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