尝试创建一个程序,该程序接受用户输入并将其乘以组合框中的值1到9.组合框必须自动递增1.结果显示在列表框中。我得到了所有这些,我的问题是,当组合框到达最后一个值时,它会抛出一个错误。我如何修复它,以便当它达到最后一个值时它不会抛出错误? 表单加载
上填充了组合框cat myfile | awk '
{
split($0, chars, "")
nbQuotes=0
nbColumns=1
for (i=1 ; i <= length($0); i++)
{
if (chars[i] == "\"")
{
nbQuotes++
} else
{
if (nbQuotes%2 == 0)
{
if (chars[i] == " ")
{
nbColumns++
}
}
}
if (nbColumns > 3)
{
break
}
printf chars[i]
}
print ""
}
'
col1 col2 col3
3 5 "Hello World"
20 NA "Alice"
1 1 "A B C"
答案 0 :(得分:1)
它向您抛出错误,因为您尝试添加组合框的最后一项的索引。因此,您需要确保不添加过去的值。以下代码应对此问题进行排序,但我认为您需要更多,特别是检查文本框是否为数字(请查看Integer.Tryparse):
Dim intUserInput As Integer
Dim outPut As Integer
intUserInput = CInt(TextBox1.Text)
Try
If intUserInput >= 1 Then
outPut = intUserInput * CInt(ComboBox1.SelectedItem)
ListBox1.Items.Add(outPut)
TextBox1.Clear()
If ComboBox1.SelectedIndex < ComboBox1.Items.Count - 1 Then
ComboBox1.SelectedIndex += 1
End If
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
MessageBox.Show("Error")
End Try