You are here:

Visual Basic/Visual Basic (Programming)

Advertisement


Question
QUESTION: Hello! Im seem to be having trouble with this Exercise. Would you mind helping me please?

Instructions say: Fix the following code:

Dim dblRegularPay As Double
Dim dblOvertimePay As Double

intRegularPay = 783.87
intOvertimePay = 105.92
lbl .TotalPay = (dblRegularPay + dblOvertimePay) .ToString ('C')

ANSWER: Dear Derek,

In those 2 lines of code you are defining 2 variables as Double:


Dim dblRegularPay As Double
Dim dblOvertimePay As Double

But you are not initializing it, i.e. no values are assigned to them. Instead, 2 other variables initialized:


intRegularPay = 783.87
intOvertimePay = 105.92

Then code is trying to use first variables defined as Double:


lbl .TotalPay = (dblRegularPay + dblOvertimePay) .ToString ('C')

This will bring run time error.

To fix the code you need to initialize your Double variables:


dblRegularPay = 783.87
dblOvertimePay = 105.92

This should fix the code.

Fixed code listing:


Dim dblRegularPay As Double
Dim dblOvertimePay As Double

dblRegularPay = 783.87
dblOvertimePay = 105.92

lbl .TotalPay = (dblRegularPay + dblOvertimePay) .ToString ('C')

Regards,

Vitaly

---------- FOLLOW-UP ----------

QUESTION: Which one is the answer?

Answer
Dear Derek,

You asked me to fix your code which I did.

To get the answer you put this code in code window of your Button1_Click event:



Dim dblRegularPay As Double
Dim dblOvertimePay As Double

dblRegularPay = 783.87
dblOvertimePay = 105.92

lblTotalPay.Text = (dblRegularPay + dblOvertimePay) .ToString ('C')


and run your project, which, I assume, have at least 2 controls on the form: button Button1 and label lblTotalPay. When you click the button, result will be shown in label.

Regards,

Vitaly

Visual Basic

All Answers


Answers by Expert:


Ask Experts

Volunteer


VITALY

Expertise

Area of expertise is Visual Basic .NET (VS 2008 and Framework 3.5) design and development for Windows applications. You can ask me any Visual Basic questions and some questions about .NET Framework. You can also ask me how to use Component One controls in Visual Basic. Do not ask me questions about Web design and development in Visual Basic.

Experience

I'm working as VB programmer from 1997, so I have a lot of experience with Visual Basic .NET as well as Visual Basic 6. Area of expertise is Visual Basic .NET (VS 2008 and Framework 3.5) design and development for Windows applications; Component One controls for Visual Basic; User controls; Moving VB6 applications to .NET.

Education/Credentials
B.S. in Computer Science

©2016 About.com. All rights reserved.