Vb.net 如何在Visual basic中执行此操作?

Vb.net 如何在Visual basic中执行此操作?,vb.net,winforms,Vb.net,Winforms,如何在visualbasic中实现“a++”和“b++”? Vb中的其他代码是什么 这里的名字只是一个例子。 像这样: a += 1 b += 1 (...) 后缀和前缀++均未在Visual Basic中定义 您唯一现实的选择是使用a=a+1(或者在后面的基础知识中使用a+=1)(请注意,语句终止符缺少;)。但是请注意,这将不会对以前的值“ A >进行评估,整个结构不是C/C++的表达式。您可以构建一个函数来模拟a++,但这样做太模糊了。 DIM a as integer = 0 DI

如何在visualbasic中实现“a++”和“b++”? Vb中的其他代码是什么

这里的名字只是一个例子。

像这样:

a += 1
b += 1
(...)

后缀和前缀
++
均未在Visual Basic中定义

您唯一现实的选择是使用
a=a+1
(或者在后面的基础知识中使用
a+=1
)(请注意,语句终止符缺少
)。但是请注意,这将不会对以前的值“<代码> A<代码> >进行评估,整个结构不是C/C++的表达式。您可以构建一个函数来模拟
a++
,但这样做太模糊了。

DIM a as integer = 0
DIM b as integer = 0

If ans1.Text = "James" Then
    a += 1
Else
    b += 1
End If
If ans2.Text = "Ryan" Then
    a += 1
Else
    b += 1
End If
If ans3.Text = "Mac" Then
    a += 1
Else
    b += 1
End If
t1.Text = a.ToString()
t2.Text = b.ToString()

您的问题已经得到了回答,但我认为看看如何简化代码会很有用:

Dim correctAnswers As Integer = 0
Dim totalQuestions As Integer = 3'you need to modify this is you add more questions

'increment the number of correct answers for each one we find
correctAnswers += If(ans1.text = "James", 1, 0)
correctAnswers += If(ans2.text = "Ryan", 1, 0)
correctAnswers += If(ans3.text = "Mac", 1, 0)

'show the number of correct and incorrect answers
t1.Text = correctAnswers.ToString()
t2.Text = (totalQuestions - correctAnswers).ToString() 'show the number of incorrect questions

您问题中的代码是C#,您是否希望转换为VB.net?没有真正理解这个问题。
If(ans2.text,“Ryan”,1,0)
Dim correctAnswers As Integer = 0
Dim totalQuestions As Integer = 3'you need to modify this is you add more questions

'increment the number of correct answers for each one we find
correctAnswers += If(ans1.text = "James", 1, 0)
correctAnswers += If(ans2.text = "Ryan", 1, 0)
correctAnswers += If(ans3.text = "Mac", 1, 0)

'show the number of correct and incorrect answers
t1.Text = correctAnswers.ToString()
t2.Text = (totalQuestions - correctAnswers).ToString() 'show the number of incorrect questions