Я пытаюсь создать программу, которая позволяет пользователю вводить начальное и конечное значения и выбирать тип данных. Если входной сигнал соответствует диапазону типов данных, программа будет считать от начального значения до конечного значения, и по истечении этого времени, когда программа будет завершена, программа отобразит затраченное время.
У меня возникли трудности с попыткой разрешить ввод только числового, десятичного и отрицательных значений. В настоящее время у меня есть:
Private Sub txtInputStart_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtInputStart.KeyPress
If Not IsNumeric(e.KeyChar) AndAlso System.Convert.ToByte(e.KeyChar) <> 8 AndAlso Convert.ToByte(e.KeyChar) <> 45 AndAlso System.Convert.ToByte(e.KeyChar) <> 46 Then
textError.Text = "Please enter numbers, decimals or negative values only"
e.Handled = True
End If
End Sub
Private Sub txtInputFinish_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtInputFinish.KeyPress
If Not IsNumeric(e.KeyChar) AndAlso System.Convert.ToByte(e.KeyChar) <> 8 AndAlso Convert.ToByte(e.KeyChar) <> 45 AndAlso System.Convert.ToByte(e.KeyChar) <> 46 Then
textError.Text = "Please enter numbers, decimals or negative values only"
e.Handled = True
End If
End Sub
У меня также есть некоторые проблемы с реализацией двойного типа данных и десятичного типа данных, я не уверен, как проверить, соответствует ли ввод этим типам данных. В настоящее время у меня есть для тестирования типа данных это:
Select Case (cbDataType.SelectedIndex)
Case 0 'Byte'
If (lcValueStart < 0 Or lcValueFinish > 255) Then
textError.Text = "The selected data type Byte can only hold values from 0 through to 255, please reset the form and than try again"
Else
Do Until lcValueStart = lcValueFinish
lcValueStart = lcValueStart + 1
Loop
myTimer.Stop()
timeValue = (myTimer.Elapsed.ToString)
lblTimer.Text = timeValue
MessageBox.Show("Counting success")
textInfo.Text = "The data type Byte holds values from 0 up to 255 and can be assigned by: Dim varName As Byte = x"
End If
Case 1 'UShort'
If (lcValueStart < 0 Or lcValueFinish > 65535) Then
textError.Text = "The selected data type UShort can only hold values from 0 through to 65535, please reset the form and than try again"
Else
myTimer.Stop()
timeValue = (myTimer.Elapsed.ToString)
lblTimer.Text = timeValue
MessageBox.Show("Counting success")
textInfo.Text = "The data type UShort holds values from 0 up to 65535 and can be assigned by: Dim varName As UShort = x"
End If
Для этих типов данных легко, потому что они не принимают десятичные дроби. Может ли кто-нибудь помочь здесь?