某些代码段有错误 [英] Certain section of code has errors
问题描述
我一直在努力解决这些问题,但对我来说却不能。
这就是我所拥有的:
Imports System.Windows
公共类frmMain
Private lblAns As Object
公共财产总计为对象
Private Sub frmMain_Load(sender As Object,e As EventArgs)Handles MyBase.Load
Dim input_1 As Single
Dim input_2 As Single
Dim Total As Single
结束点¥
Private Sub btnShots_Click(sender as Object,e As EventArgs)处理btnShots.Click
试用¥b $ b
txtInput1.Text = Val(txtInput1.Text)+ 1
C ex ex As Exception
MessageBox.Show(ex.Message," Error",MessageBoxButtons.OK)
结束尝试
结束点¥
Private Sub btnDings_Click(sender As Object,e As EventArgs)处理btnDings.Click
试用¥b $ b
txtinput2.Text = Val(txtinput2.Text)+ 1
C ex ex As Exception
MessageBox.Show(ex.Message," Error",MessageBoxButtons.OK)
结束尝试
结束点¥
Private Sub btnCalc_Click(sender As Object,e As EventArgs)处理btnCalc.Click
input_1 = txtInput1.Text
Input_2 = txtinput2.Text)
总计= Input_2()/ input_1()* 100
lblAns.Text = Total.ToString
结束点¥
私人功能输入_2()为字符串
抛出新的NotImplementedException()
结束功能
私人功能input_1()单身
抛出新的NotImplementedException()
结束功能
Private Sub btnClear_Click(sender As Object,e As EventArgs)处理btnClear.Click
txtInput1.Clear()
txtinput2.Clear()
lblAns.Text =""
结束点¥
Public Sub MakeOnTop()
frmMain.TopMost = True
结束分
私人功能frmMain()作为对象
抛出新的NotImplementedException
结束功能
Private Sub btnShots_KeyDown(sender As Object,e As KeyEventArgs)处理btnShots.KeyDown
选择案例e.KeyCode
Case Keys.Z
btnShots.PerformClick()
结束选择
结束点¥
Private Sub btnDings_KeyDown(sender As Object,e As KeyEventArgs)处理btnDings.KeyDown
选择案例e.KeyCode
Case Keys.X
btnShots.PerformClick()
结束选择
结束分
结束等级
这一切都正常,直到我为百分比添加了计算部分。
感谢大家给我的任何帮助。
编辑:2个错误是:
input_1 = txtInput1.Text
输入_2 = txtinput2.Text)
嗨
首先关闭 - 请将代码放入代码块进行发布。
其次,你有将input_1和input_2定义为Single类型 - 然后尝试为它们分配字符串。您必须将类型更改为String OR,将textinput1和2转换为Single数据类型。你很可能想要这个。它调用一个函数来返回
a单值(如果字符串不是有效数字则为0)]input_1 = getsingle(txtInput1 .Text)
input_2 = getsingle(txtInput2.Text)
函数GetSingle(s As String)As Single
Dim v As Single = 0
如果Single.TryParse(s,v)则返回v
返回0
结束函数
I have been trying to fix them but just cannot for the life of me.
Here is what I have:
Imports System.Windows
Public Class frmMain
Private lblAns As Object
Public Property Total As Object
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim input_1 As Single
Dim input_2 As Single
Dim Total As Single
End Sub
Private Sub btnShots_Click(sender As Object, e As EventArgs) Handles btnShots.Click
Try
txtInput1.Text = Val(txtInput1.Text) + 1
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK)
End Try
End Sub
Private Sub btnDings_Click(sender As Object, e As EventArgs) Handles btnDings.Click
Try
txtinput2.Text = Val(txtinput2.Text) + 1
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK)
End Try
End Sub
Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
input_1 = txtInput1.Text
Input_2 = txtinput2.Text)
Total = Input_2() / input_1() * 100
lblAns.Text = Total.ToString
End Sub
Private Function Input_2() As String
Throw New NotImplementedException()
End Function
Private Function input_1() As Single
Throw New NotImplementedException()
End Function
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
txtInput1.Clear()
txtinput2.Clear()
lblAns.Text = ""
End Sub
Public Sub MakeOnTop()
frmMain.TopMost = True
End Sub
Private Function frmMain() As Object
Throw New NotImplementedException
End Function
Private Sub btnShots_KeyDown(sender As Object, e As KeyEventArgs) Handles btnShots.KeyDown
Select Case e.KeyCode
Case Keys.Z
btnShots.PerformClick()
End Select
End Sub
Private Sub btnDings_KeyDown(sender As Object, e As KeyEventArgs) Handles btnDings.KeyDown
Select Case e.KeyCode
Case Keys.X
btnShots.PerformClick()
End Select
End Sub
End Class
It all was working fine until I added the Calculation part for percentages.
Thanks for any Help you folks can give me.
Edit: The 2 errors are:
input_1 = txtInput1.Text
Input_2 = txtinput2.Text)
Hi
First off - please put code into a code block for posting.
Secondly, you have defined both input_1 and input_2 as type Single - then you try to assign strings to them. You must either change the types to String OR, cast the textinput1 and 2 to Single data type. Most likely you want this. It calls a function to return a Single value (which is 0 if the string is not a valid number)]
input_1 = getsingle(txtInput1.Text) input_2 = getsingle(txtInput2.Text) Function GetSingle(s As String) As Single Dim v As Single = 0 If Single.TryParse(s, v) Then Return v Return 0 End Function
这篇关于某些代码段有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!