1 Replies - 1327 Views - Last Post: 15 December 2012 - 06:52 PM Rate Topic: -----

#1 codespook  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 201
  • Joined: 31-October 12

Data type conversion

Posted 15 December 2012 - 05:02 PM

Hello everyone
I'm always having a problem wtih data types, mostly converting them. I have the math in there, but usually when i try to calculate something, it will go to a zero. I know that's not right:( In this particular code though, it is giving me an error that I cannot convert from a double. (because of the decTax.

Here's the code.

Public Class Form1

Dim intHoursworked As Integer
Dim intPay As Integer
Dim strOvertime As String
Dim decTax As Decimal
Dim strGross

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

End Sub

Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click

intHoursworked = Convert.ToInt32(txtHours.Text)
intPay = Convert.ToString(txtPay.Text)

If radSingle.Checked = True Then
decTax = 0.18
End If

If radFamily.Checked = True Then
decTax = 0.15
End If

lblGrossPay.Text = "Gross Pay $" & intPay * intHoursworked
strGross = lblGrossPay.Text

'Calculate tax lblTaxrate.Text = strGross * decTax

End Sub
End Class

What am I overlooking? THanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Data type conversion

#2 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6528
  • View blog
  • Posts: 14,438
  • Joined: 02-June 10

Re: Data type conversion

Posted 15 December 2012 - 06:52 PM


Your assignment is to do this in VB6? You're deliberately going to school to learn a language that's been dead for a decade? Should this be moved to VB.NET?

Please read: This is not the VB.NET forum
Please read: Is learning VB6 now a complete waste of time?

codespook: What this shows us is that you aren't familiar with breakpoints and how to debug your own code.

tlhIn`toq's FAQ list

Learning to debug one's own code is an essential skill. Sadly, one that apparently few college courses teach. Silly if you ask me.

Placing breakpoints and walking through the code line by line allows you to actually WATCH it execute.

Visualizing what your code does will let you see why it behaves the way it does.

It would be well worth your time to do the tutorials on FAQ 2. A couple hours learning this skill will save you hundreds of hours of confusion in one project alone.

TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Class1/Form1 talk to Class2/Form2

FAQ (Frequently Asked Questions - Updated DEC 2012

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1