Private Sub btnConfirmInfantry_Click(sender As Object, e As EventArgs) Handles btnConfirmInfantry.Click
Dim input = InputBox("How many do you want to attack with?", "Choose how many Infantry:")
Dim infantry As Integer
If (input > frmMainGame.lblInfantryNumberPlayer.Text) Then
MessageBox.Show("Error: The inputted number has to be <= current number of infantry.")
Else
If Integer.TryParse(input, infantry) Then
Dim hpai = Integer.Parse(frmMainGame.lblHPAI.Text, Globalization.NumberStyles.AllowThousands, Globalization.CultureInfo.InvariantCulture)
frmMainGame.lblHPAI.Text = String.Format("{0:n0}", hpai - infantry * 2)
Dim numPlayer = frmMainGame.lblInfantryNumberPlayer.Text 'Integer.Parse(frmMainGame.lblInfantryNumberPlayer.Text)
frmMainGame.lblInfantryNumberPlayer.Text = (numPlayer - input).ToString("N0")
End If
End If
End Sub
Я пытаюсь получить If (вход> frmMainGame.lblInfantryNumberPlayer.Text) Тогда Пропустите оставшуюся часть строки кода. Но проблема в том, что номера lblInfantry указаны в миллионах, и это только чтение первого числа, которое равно 2. Поэтому, если я ввещу 3, произойдет ошибка msgbox. Я пробовал Globilization.NumberStyles.AllowThousands, положив его после frm .... но это не сработало. Какие-либо предложения? Благодаря!Система ввода Box Значение
Примечание: Я хочу ввести входное значение как 30 дюймов, а если lblInfantry равно 100 000, тогда msgbox НЕ будет появляться, и код будет читаться после Else.
Update:
Private Sub btnConfirmInfantry_Click(sender As Object, e As EventArgs) Handles btnConfirmInfantry.Click
Dim input = InputBox("How many do you want to attack with?", "Choose how many Infantry:")
Dim infantry As Integer
Dim intInfanty As Integer = 0
Dim intInput As Integer = 0
Dim txt As String = frmMainGame.lblInfantryNumberPlayer.Text, intInfantry
If Integer.TryParse(input, intInput) AndAlso Integer.TryParse(txt, intInfantry) AndAlso (intInput > intInfantry) Then
If (IsNumeric(input) AndAlso IsNumeric(frmMainGame.lblInfantryNumberPlayer.Text) AndAlso CInt(input) > CInt(frmMainGame.lblInfantryNumberPlayer.Text)) Then
MessageBox.Show("The value can not be a letter.")
Else
If Integer.TryParse(input, infantry) Then
Dim hpai = Integer.Parse(frmMainGame.lblHPAI.Text, Globalization.NumberStyles.AllowThousands, Globalization.CultureInfo.InvariantCulture)
frmMainGame.lblHPAI.Text = String.Format("{0:n0}", hpai - infantry * 2)
Dim numPlayer = frmMainGame.lblInfantryNumberPlayer.Text 'Integer.Parse(frmMainGame.lblInfantryNumberPlayer.Text)
frmMainGame.lblInfantryNumberPlayer.Text = (numPlayer - input).ToString("N0")
End If
End If
Else
MessageBox.Show("Error: The inputted number has to be <= current number of infantry.")
End If
End Sub
Результаты InputBox и свойства текста являются строками. Перед тем, как оценивать их, вы должны попробовать их запрудить. – LarsTech