0

I keep getting an error when it come to getting a percentage as a part of a program.

The code is below as well as an image of the error pop up.

Also yes yes I know I can some up some code line and less variables but at this point I was desperate so I tried anything. Also sorry for my spelling.

I posted the code below. I hope you can see that I am using a service base database.

Public Class record
    Dim total As Integer
    Dim grade As Integer
    Dim letter As String
    Dim message As String
    Dim porcentaje As Decimal
    Dim budget As Integer
    Dim divider As Integer
    Private Sub AccountTableBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles AccountTableBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.AccountTableBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.Database1DataSet)

    End Sub

    Private Sub record_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Database1DataSet.report' table. You can move, or remove it, as needed.
        Me.ReportTableAdapter.Fill(Me.Database1DataSet.report)
        'TODO: This line of code loads data into the 'Database1DataSet.budgetTable' table. You can move, or remove it, as needed.
        Me.BudgetTableTableAdapter.Fill(Me.Database1DataSet.budgetTable)
        'TODO: This line of code loads data into the 'Database1DataSet.accountTable' table. You can move, or remove it, as needed.
        Me.AccountTableTableAdapter.Fill(Me.Database1DataSet.accountTable)

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        budget = BudgetNumericUpDown.Value
        divider = budget
        total = TotalNumericUpDown.Value
        porcentaje = total / divider
        grade = porcentaje * 100



        If grade < 59 Then
            letter = "F"
            message = "You have fail completly your budget goal please rethink your expenses"
            ReportTableAdapter.InsertQueryreport(grade, letter, message)
            Dim form1 As report
            form1 = New report
            form1.Show()
            Me.Hide()
        ElseIf grade >= 59 And grade < 69 Then
            letter = "D"
            message = "You have fail part of your budget goal please rethink your expenses a little more"
            ReportTableAdapter.InsertQueryreport(grade, letter, message)
            Dim form1 As report
            form1 = New report
            form1.Show()
            Me.Hide()
        ElseIf grade >= 69 And grade < 79 Then
            letter = "C"
            message = "You have achive the minimun of your budget goal you can do better"
            ReportTableAdapter.InsertQueryreport(grade, letter, message)
            Dim form1 As report
            form1 = New report
            form1.Show()
            Me.Hide()
        ElseIf grade >= 79 And grade < 89 Then
            letter = "B"
            message = "You completed more then enough of your budget goal "
            ReportTableAdapter.InsertQueryreport(grade, letter, message)
            Dim form1 As report
            form1 = New report
            form1.Show()
            Me.Hide()
        ElseIf grade >= 89 Then
            letter = "A"
            message = "You completed you budget goal perfectly congratulation please tell me your secret"
            ReportTableAdapter.InsertQueryreport(grade, letter, message)
            Dim form1 As report
            form1 = New report
            form1.Show()
            Me.Hide()
        End If
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim form1 As deposit
        form1 = New deposit
        form1.Show()
        Me.Hide()
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Me.Close()
    End Sub
End Class

1

Bugs
  • 4,491
  • 9
  • 32
  • 41
  • sorry my mistake I thought I tagged visual basic my bad and I did post code there are 2 images there – Colondor 0319 May 14 '17 at 19:47
  • ok I understand thanks for being patient I am goin crazy this a project for collage and its driving me crazy everything else works except when it goes to this part I tried like mentioned in one of the answers switching the variables all to string but still nothing – Colondor 0319 May 14 '17 at 19:57
  • I added a [vb.net] tag. If it **isn't** VB.Net (it's a while since I used it, so I might be mistaken), edit the question again and change the tag I added to be something more appropriate. – YowE3K May 14 '17 at 20:01
  • Make sure you are not dividing by zero. It says so in the tips in the error popup. – Andrew Morton May 14 '17 at 20:05
  • yeah already made sure of that that was the first thing I did – Colondor 0319 May 14 '17 at 20:16
  • alright I figured it out there was a problem with my data source and it was not giving me the value for the divider as Andrew said, I was not looking correctly. at first I though its not suppose to be zero so that when I saw it was not giving me the value, thank you all for the help – Colondor 0319 May 14 '17 at 20:24
  • Please don't add _RESOLVED_ to your title. Instead consider adding an answer explaining what it was that fixed the problem. This will help any future visitors that may be experiencing the same problem. – Bugs May 14 '17 at 21:09

1 Answers1

0

The exception that is thrown when an arithmetic, casting, or conversion operation in a checked context results in an overflow. Source of msdn

you have declared your divider and total as integer and percentage as decimal. I think you should convert all your variables to decimal or integer..

Muhammad Iqbal
  • 1,394
  • 1
  • 14
  • 34