我正在制作一个数学游戏atm,在分区部分我需要确保计算机要求的问题是可分的,而不是给出2个随机数,这将导致小数。即13/5之类的问题不会出现。我怎么做。对不起,如果我的缩进不正确我对这个界面是新的。
Public Class Division
Dim Rnd1 As New Random
Dim Rnd2 As New Random
Dim Result0 = Rnd1.Next(20, 40)
Dim Result1 = Rnd1.Next(1, 10)
Dim Total = Result0 / Result1
Dim Score As Integer = 0
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.KeyPreview = True
TextBox1.Text = Result0
TextBox2.Text = Result1
Label3.Text = Total
Label4.Text = Score
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Rnd1 As New Random
Dim Rnd2 As New Random
Dim Result0 = Rnd1.Next(20, 40)
Dim Result1 = Rnd1.Next(1, 10)
Dim Total = Result0 / Result1
If TextBox3.Text = Label3.Text Then
Score += 1
TextBox3.Text = ""
Else
MessageBox.Show("Incorrect")
TextBox3.Text = ""
End If
TextBox1.Text = Result0
TextBox2.Text = Result1
Label3.Text = Total
Label4.Text = Score
End Sub
Private Sub Form1_Click(sender As Object, e As EventArgs) Handles Me.Click
End Sub
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Enter Then
e.SuppressKeyPress = True
Button1.PerformClick()
End If
End Sub
答案 0 :(得分:0)
您可以使用cint
实施例
Dim ans as integer = cint(ans1 / ans2)
尝试检查一下。