Solved

Declare a form level variable vb6

Posted on 2014-02-06
5
356 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

737 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