简体   繁体   English

无法获得基本的视觉效果百分比

[英]Having trouble getting a percentage in visual basic

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

The exception that is thrown when an arithmetic, casting, or conversion operation in a checked context results in an overflow. 在检查的上下文中进行算术,强制转换或转换操作导致溢出时引发的异常。 Source of msdn 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.. 我认为您应该将所有变量都转换为十进制或整数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Visual Basic中遇到TimeSpan的麻烦 - Having trouble with TimeSpan in Visual Basic 我在Visual Basic中遇到了课堂成绩计算器的问题 - I'm having trouble in Visual Basic with a grade calculator for class 我在 Visual Basic 中使用随机方程生成器遇到的麻烦比我想象的要多 - I'm having more trouble than I thought with a random equation generator in Visual basic 使用pretest编写应用程序代码时遇到麻烦...在Visual Basic中循环显示数字列表 - Having trouble coding an application using a pretest do…loop in visual basic that displays a list of numbers OnLoad Sub的问题(Visual Basic) - Trouble with OnLoad Sub (Visual Basic) Visual Basic和SQL中的数据读取器出现问题 - Trouble with a datareader in visual basic and SQL Visual Basic控制台应用程序下载百分比? - Visual Basic Console Application Download Percentage? 如何在Visual Basic中计算赢/输百分比 - How to compute win/loss percentage in Visual Basic Visual Basic控制台应用程序复制百分比? - Visual Basic Console Application Copy Percentage? Visual Basic 2012,如何编写DBNull遇到麻烦。 “从类型&#39;DBNull&#39;到类型&#39;String&#39;的转换无效。” - Visual Basic 2012, having trouble with how to write DBNull. “Conversion from type 'DBNull' to type 'String' is not valid.”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM