У меня есть математическая программа, которая запрашивает случайные числа умножения, поэтому я хотел сделать это со случайными операторами, проблема состоит в том, что выбор оператора дает мне ноль, а деление дает мне дробные числа.
То, что я пробовал, было частью кода, который я обнаружил в сети, затем я попытался сделать это с метками, но сумма не считала бы текст метки как оператор, даже если я попробовал строковое значение и CInt, я попробовал это с текстовыми полями, надеясь, что это будет читать из этого. Не сработало Смотрел кучу видео на YouTube. Это не сработало. Случайный выбор оператора работает сам по себе, но дает некоторые ответы на некоторые вопросы в части деления
Вот весь мой код, который я пытаюсь работать со случайным оператором и делением, чтобы дать правильные ответы без дроби.
Я не очень хорош в этом, но пытаюсь улучшить. Спасибо за ваше терпение.
Открытый класс frm_mathstables
Dim num1 As Integer
Dim num2 As Integer
Dim ans As Integer
Dim counter1 As Integer
Тусклый правильный как целое число
Дим неправильно как целое
Dim timeout As Integer
Тусклый как целое
Dim spec1 As Integer
Dim spec2 As Integer
Dim blank As Integer
Тусклый как целое число
Тусклый как целое число
Dim pertimeout As Integer
Дим пербланк как целое число
Dim red1 As Integer
Dim green1 As Integer
Dim blue1 As Integer
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Not Char.IsDigit(e.KeyChar) Then e.Handled = True
If (e.KeyChar = Chr(13)) Then
e.Handled = True
Call checkanswer()
End If
End Sub
Private Sub checkanswer()
On Error Resume Next
If TextBox1.Text = "" Then
My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Asterisk)
ListBox1.Items.Add(counter1 & " : " & num1 & " X " & num2 & " = " & ans & " No Response : " & TextBox1.Text & Label12.Text)
Label1.Text = "No Response From User"
MsgBox("You Cannot Leave The Answer Blank", MessageBoxIcon.Exclamation)
TextBox1.Clear()
blank = blank + 1
Label11.Text = "Blank " & blank
If frmsettings.RadioButton1.Checked Then
Call randomnumbers()
End If
If frmsettings.RadioButton2.Checked Then
Call spesify()
End If
TextBox1.Focus()
Exit Sub
End If
If TextBox1.Text = ans Then
correct = correct + 1
Label1.Text = "Correct"
Label8.Text = "Correct : " & correct
'ListBox1.Items.Add(counter1 & " : " & num1 & " X " & num2 & " = " & ans & " | Answer Entered : " & TextBox1.Text & " " & Label1.Text & " " & Label12.Text)
ProgressBar1.Value = 0
End If
If TextBox1.Text <> ans Then
My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Beep)
wrong = wrong + 1
Label1.Text = "Wrong"
Label9.Text = "Wrong : " & wrong
ListBox1.Items.Add(counter1 & " : " & num1 & " X " & num2 & " = " & ans & " | Answer Entered : " & TextBox1.Text & " " & Label1.Text & " " & Label12.Text)
ProgressBar1.Value = 0
End If
TextBox1.Clear()
If frmsettings.RadioButton1.Checked Then
Call randomnumbers()
End If
If frmsettings.RadioButton2.Checked Then
Call spesify()
End If
TextBox1.Focus()
red1 = 1 + Int(Rnd() * 255)
green1 = 1 + Int(Rnd() * 255)
blue1 = 1 + Int(Rnd() * 255)
ProgressBar1.ForeColor = Color.FromArgb(red1, green1, blue1)
End Sub
Private Sub randomnumbers()
counter1 = counter1 + 1
Label7.Text = "Question Number " & counter1
num1 = 1 + Int(Rnd() * 12)
num2 = 1 + Int(Rnd() * 12)
ans = num1 & Val(Label22.Text) & num2
lblsum.Text = "What Is... " & num1 & Label22.Text & num2 & " = "
red1 = 1 + Int(Rnd() * 255)
green1 = 1 + Int(Rnd() * 255)
blue1 = 1 + Int(Rnd() * 255)
ProgressBar1.ForeColor = Color.FromArgb(red1, green1, blue1)
End Sub
Private Sub spesify()
counter1 = counter1 + 1
Label7.Text = "Question Number " & counter1
num1 = 1 + Int(Rnd() * 12)
num2 = Val(frmsettings.ComboBox1.Text)
ans = num1 * num2
lblsum.Text = "What Is... " & num1 & " X " & num2 & " = "
red1 = 1 + Int(Rnd() * 255)
green1 = 1 + Int(Rnd() * 255)
blue1 = 1 + Int(Rnd() * 255)
ProgressBar1.ForeColor = Color.FromArgb(red1, green1, blue1)
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
On Error Resume Next
Label6.Text = "Progressbar Count = " & ProgressBar1.Value
If CInt(frmsettings.txtnrofsums.Text) = counter1 - 1 Then
Call pauseporg()
End If
ListBox1.SelectedItem = ListBox1.Items.Item(ListBox1.Items.Count - 1)
Label5.Text = Val(Label5.Text) + 1
ProgressBar1.Maximum = frmsettings.TrackBar1.Value
ProgressBar1.Value = ProgressBar1.Value + 1
If ProgressBar1.Value = frmsettings.TrackBar1.Value Then
ProgressBar1.Value = 0
ListBox1.Items.Add(counter1 & " : " & num1 & " X " & num2 & " = " & ans & " Timed Out : " & Label12.Text)
Label1.Text = " Previous Question Timed Out"
timeout = timeout + 1
Label10.Text = "Timed Out " & timeout
If frmsettings.RadioButton1.Checked Then
Call randomnumbers()
End If
If frmsettings.RadioButton2.Checked Then
Call spesify()
End If
End If
On Error Resume Next
'the percentages calculaions
Dim countper As Integer
countper = counter1 - 1
percorrect = correct * 100 / countper
perwrong = wrong * 100 / countper
pertimeout = timeout * 100 / countper
perblank = blank * 100 / countper
Label15.Text = percorrect & " %"
Label16.Text = perwrong & " %"
Label17.Text = pertimeout & " %"
Label18.Text = perblank & " %"
Dim pertot As Integer
pertot = perblank + percorrect + perwrong + pertimeout
Label19.Text = pertot & " %"
End Sub
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs)
frmsettings.Label4.Text = "Timer Interval " & frmsettings.TrackBar1.Value
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Add("Program Started " & Label12.Text)
If frmsettings.RadioButton1.Checked Then
Call randomnumbers()
End If
If frmsettings.RadioButton2.Checked Then
Call spesify()
End If
TextBox1.Focus()
GroupBox1.Visible = True
TextBox1.Focus()
Timer1.Start()
Timer1.Enabled = True
ProgressBar1.Enabled = True
Button1.Enabled = False 'start button
Button2.Enabled = True 'stop button
Button3.Enabled = False 'listbox clear item button
Button4.Enabled = False 'the reset button
Button5.Enabled = False 'exit button
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
ListBox1.Items.Add("Program Stopped " & Label12.Text)
Timer1.Enabled = False
Timer1.Stop()
Button1.Enabled = True 'start button
Button2.Enabled = True 'stop button
Button3.Enabled = True 'listbox clear item button
Button4.Enabled = True 'the reset button
Button5.Enabled = True 'exit button
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
ListBox1.Items.Clear()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
ProgressBar1.Value = 0
ListBox1.Items.Clear()
ListBox1.Items.Add("Counters Reset By User " & Label12.Text)
Label7.Text = String.Empty
Label8.Text = String.Empty
Label9.Text = String.Empty
Label10.Text = String.Empty
Label11.Text = String.Empty
lblsum.Text = String.Empty
Label15.Text = String.Empty
Label16.Text = String.Empty
Label17.Text = String.Empty
Label18.Text = String.Empty
Label19.Text = String.Empty
frmsettings.ComboBox1.Text = String.Empty
frmsettings.RadioButton1.Checked = True
Label1.Text = String.Empty
Button1.Enabled = True 'start button
Button2.Enabled = True 'stop button
Button3.Enabled = True 'listbox clear item button
Button4.Enabled = True 'the reset button
Button5.Enabled = True 'exit button
GroupBox1.Visible = True
frmsettings.txtnrofsums.Text = "20"
Label6.Text = "Progressbar Count = 0 "
num1 = 0
num2 = 0
ans = 0
counter1 = 0
correct = 0
wrong = 0
timeout = 0
blank = 0
frmsettings.TrackBar1.Value = 100
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Me.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
frmsettings.TrackBar1.Value = 100
frmsettings.RadioButton1.Checked = True
Timer2.Start()
Timer2.Enabled = True
ListBox1.Items.Add("Maths TimesTable Application Started ")
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Label12.Text = TimeOfDay
Label13.Text = "Timer Interval " & (frmsettings.TrackBar1.Value)
Label14.Text = "Nr Of Sum " & (frmsettings.txtnrofsums.Text)
Me.Chart1.Series(0).Points.Clear()
Me.Chart1.Series("counters").Points.AddXY("Correct", correct)
Me.Chart1.Series("counters").Points.AddXY("Wrong", wrong)
Me.Chart1.Series("counters").Points.AddXY("Timeout", timeout)
Me.Chart1.Series("counters").Points.AddXY("Blank", blank)
Chart1.ChartAreas(0).BackColor = Color.FromArgb(240, 240, 240)
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
frmsettings.RadioButton2.Checked = True
End Sub
Private Sub ComboBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs)
frmsettings.RadioButton2.Checked = True
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub pauseporg()
GroupBox1.Visible = False
ListBox1.Items.Add("Program Stopped " & Label12.Text)
Timer1.Enabled = False
Timer1.Stop()
Button1.Enabled = True 'start button
Button2.Enabled = True 'stop button
Button3.Enabled = True 'listbox clear item button
Button4.Enabled = True 'the reset button
Button5.Enabled = True 'exit button
MessageBox.Show(" Welldone!. You Completed All " & frmsettings.txtnrofsums.Text & " Sums", "Target Sums Reached")
ProgressBar1.Value = 0
Button1.Enabled = False 'start button
Button2.Enabled = False 'stop button
Button3.Enabled = False 'listbox clear item button
Button4.Enabled = True 'the reset button
Button5.Enabled = False 'exit button
End Sub
Private Sub Label8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label8.Click
End Sub
Private Sub Label6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label6.Click
End Sub
Private Sub txtnrofsums_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
If frmsettings.txtnrofsums.Text = "" Then
MessageBox.Show("Minimum Nr Of Sums Cannot be less than 1")
frmsettings.txtnrofsums.Text = 20
End If
If frmsettings.txtnrofsums.Text > 500 Then
MessageBox.Show("Maximum Nr Of Sums Cannot Exceed 500")
frmsettings.txtnrofsums.Text = 20
End If
End Sub
Private Sub Label14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub ComboBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
frmsettings.RadioButton2.Checked = True
End Sub
Private Sub Chart1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Chart1.Series("counters").Points.AddXY("correct", 33)
End Sub
Private Sub percentages()
percorrect = counter1 * 100 / correct
Label15.Text = percorrect
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
ListBox1.Items.Add("Program Stopped " & Label12.Text)
Timer1.Enabled = False
Timer1.Stop()
Button1.Enabled = True 'start button
Button2.Enabled = True 'stop button
Button3.Enabled = True 'listbox clear item button
Button4.Enabled = True 'the reset button
Button5.Enabled = True 'exit button
frmsettings.ShowDialog()
End Sub
Private Sub Label21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label21.Click
End Sub
Конечный класс