Question:
In Visual Basics, how do I call a function's variable to use in another function?
anonymous
2009-05-10 20:00:09 UTC
Although there are easier ways to do this, it purposely has to be done this way.

My code is kind of awkward to read so the jist of it is:
I solve the variables in a custom made public function and then call them when I click the "Display" button.
For example I check to see if someone ordered Coffee, Coke, or Nothing.
That function results in Coffee.

Tax kicks in the next function
tax=(CoffeePrice)*0.05


Now it is my main function when I click Display
The tax should be 0.05, but when I Call the DrinkTax function it's not allowing me to use the "Tax" I just solved for. (lbl_tax.caption=Tax)

I also tried doing it the way I think you do it in java, lbl_tax.caption=DrinkTax.Tax
Three answers:
?
2009-05-10 20:20:33 UTC
How do i reference it....

You can't reference it outside of the CoffeeCost function (which btw should be a Sub as it does not return a value) as its scope is local to the function.



use a global variable instead.

Been a long time since I did anything in VB, so I hope globals are still in the language.
anonymous
2009-05-10 20:08:55 UTC
Your description is a bit vague, but bear in mind that what's in a label's caption is a string, not a number. ("5" isn't the same as 5.) You might need to take the value of the caption. (Tax is a numeric variable, lbl_tax.Caption is a string. In some cases, VB will "coerce" the type for you, in some cases it won't - which is why it's always a good idea to do the conversion yourself.)



You can only do DrinkTax.Tax if you defined DrinkTax as having a Tax property.
?
2016-10-20 13:51:49 UTC
If the variable is in an identical classification, you ought to use the interior maximum member quickly given which you are attempting to handle the press journey, you will choose an accessor functionality to retrieve the interior maximum variable on your classification. something like GetResult which returns the effect


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...