开发者

substring and the indexOf function [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

substring and the indexOf method

I have this problem that I'm going in circles on. The error message is "no accessible IndexOf can be called with these arguments."

My professor said that "to search for the string Los Angeles and substring will return it from the textbox, but it needs to know what position to start returning a word at, and that is where the IndexOf comes in." Does that mean substring and IndexOf are used together? That's what I did and may be the problem. Here's the code:

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

Any suggestions?


Documentation is your friend

You call

Str(txtAddress.IndexOf(11, 0))

Which is invalid syntax. The correct syntax is

string.IndexOf(searchString)

This returns the index position of the found string

-1 if it is not found.

0 if empty

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜