ToddHawley4984
asked on
Assigning a value to a variable in another procedure
I have been using excel vba to develop some forms...I have been using text box values as values in my comutations...However since in some cases i need to format the text to a given decimal place i am loosing precision. So my solution is to assign the values to variables and format during the transision from variable to text box....for instance In the example below i am assigning a value to a text box in another form...along these lines how would i assign a value to a variable in a private sub linked to a different form..
'rad is a double variable
Time_of_Concentration_Form.tb_hydro_rad_CHF5 = rad
'this works fine
Time_of_concentration_form.private sub main (local Variable) = rad
'this i can't do
ASKER
I've only been programming in VBA for about a week...I understand that its a module level variable but I don't quite understand how to manipulate it
ASKER
If i'm gonna use a given value in different form should i use a public variable delared in my module? Is there any real reason not to use public variables other than memory consumption? I realize if i have a public variable i have to be careful about changing in from different procedures
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In your user form:
Private mRad As Double
Private Sub Main()
mRad = 5 'Set however you set this variable.
End Sub
Public Property Get Rad() As Double
Rad = mRad
End Property
Public Property Let Rad(Value As Double)
mRad = Value
End Property
Now you can assign the value using the public property from other code:
Time_of_Concentration_Form