Possible Duplicate:
substring and the indexOf method
我有这个问题,我将继续讨论。错误消息是“无法使用这些参数调用IndexOf。”
我的教授说:“搜索字符串Los Angeles和substring将从文本框中返回它,但是它需要知道从哪个位置开始返回单词,这就是IndexOf的所在。”这是否意味着子字符串和IndexOf一起使用?那就是我所做的,可能就是问题所在。这是代码:
Private Sub btnOrder_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnOrder.Click
'Declare variables
Dim Price As Decimal
Dim txtAddress As String = "Los Angeles"
Dim DialogResults As String
'Begin If Statements to determine whether value is a number
If IsNumeric(txtPrice.Text) Then
MessageBox.Show("Please enter a nummeric value.", "Error Message")
End If
If IsNumeric(txtQuantity.Text) Then
MessageBox.Show("Please enter a numeric value.", "Error Message")
End If
Try
'Condition for Pickup days
If radPickUp.Checked = True Then
Price = CDec(txtPrice.Text)
ElseIf radNextDay.Checked = True Then
Price = CDec(CDbl(txtPrice.Text) * 0.01)
ElseIf radDays.Checked = True Then
Price = CDec(CDbl(txtPrice.Text) * 0.05)
End If
'Condition for Weekdays or Weekends pickup
If CDbl(Str(cboDays.Text)) = -1 Then
Price = CDec(CDbl(txtPrice.Text) * 0.0925)
End If
If CBool(Int(txtAddress.Substring(0, 10))) Then
Str(txtAddress.IndexOf(11, 0))
DialogResults = CStr(MessageBox.Show("Your order is $ " & CDbl(txtPrice.Text) - 0.05))
Else : DialogResults = CStr(MessageBox.Show("You order is $ " & CDbl(txtPrice.Text)))
End If
Catch ex As InvalidCastException
MessageBox.Show("Please enter a valid numeric value to continue.")
End Try
End Sub
Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
'Reset controls
txtPrice.Clear()
txtQuantity.Clear()
txtName.Clear()
txtAddress.Clear()
cboDays.Text = String.Empty
txtPrice.Focus()
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
'Quit the application
Me.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MessageBox.Show("Hello", "A greeting.")
End Sub
最佳答案
Documentation是你的 friend
你打电话
Str(txtAddress.IndexOf(11, 0))
string.IndexOf(searchString)
关于.net - 子字符串和indexOf函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7701709/