What do you mean for "the variable "tip" doesn't transfer over to the next sub"?
–
AngeloBadFeb 13 '12 at 15:47

1

Did you debug to make sure the tip is correctly assigned inside btnDisplay_Click?
–
Meta-KnightFeb 13 '12 at 15:48

2

Just an fyi, but .1 is a repeating decimal when converted to binary, which could cause you to see some unexpected results here. Since these are monetary calculations, try having your tip variable be a Decimal instead of a Double.
–
Joel CoehoornFeb 13 '12 at 15:55

1

Two important notes: 1) Select Case True is considered bad programming practise you could use If Then ElseIf End If in this scenario, 2) You should switch Option Strict On - this would alert you to an error in the code you posted
–
Matt WilkoFeb 13 '12 at 16:07

Thanks Matt. I'm kinda knew to VB so any tips would be helpful
–
Kentaro51Feb 14 '12 at 14:47

3 Answers
3

Try not to use Val (It works in this situation, but it may not in all)

As for why you are getting only 0, I was able to replicate that behavior using your existing code, by one of the threefollowing...

Don't click btnDisplay first. In this case, you do not assign a
value to tip, so it defaults to 0. Multiply 0 by any amount and you
get... 0.

Not having a value in TxtBill. Same reason as #1.

Not have a default value for the radio buttons set, and trying to
calculate.

Assuming I put a value in txtBill, choose a tip option and pressed btnDisplay, I get a value.

I would put breaks in and trying to track the values in your variables to see what is going on. You could also probably make btnDisplay and btnCalc do all the work at once (verify that a tip amount has been chosen, and do calc and display results). No point in clicking two buttons.

Using Val() is usually not recommended (especially in i18n code). It's a carry over from Visual Basic (pre .Net) and it creates all types of funky data when parsing values. It's recommended to clean the string first then parse it, i.e. stripping dollar signs, then parse the value as a single/double.

OP says that his problem is that "lblTip.text keeps coming up as 0". This wouldn't fix the problem.
–
Meta-KnightFeb 13 '12 at 17:01

It would if there is an issue parsing the integer as a string. lblTip.Text stores a string value not an integer value. The problem also may reside in Val(txtBill.Text)
–
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzFeb 13 '12 at 17:11

My point is: If CDbl(txtBill.Text) * tip returns 0, then wrapping this code with CStr will still return 0!
–
Meta-KnightFeb 13 '12 at 17:20