Reputation: 1559
I have the below code in my app... Nothing is declared as a integer so I dont understand or see where the problem could be... It is saying:
Conversion from string "9838 Co Rd 47" to type 'Integer' is not valid.
The address is flowing through the entire function as a string the only place I think it could be getting changed somehow is in a function call... Below is the function that throws the exception. Followed by the function that returns the address... The error comes from the _holder = item.bill_to.remove(address) line
For Each item In _QuickImport
Dim BusinessName As String = Nothing
Dim CustomerName As String = " "
_Id = item.id
If Not String.IsNullOrEmpty(item.Customer) Then
Dim _holder As String = String.Empty
Dim _contact_ As String = item.Contact
Dim _address_ As String = String.Empty
If item.Bill_to.Contains(_contact_) Then
_holder = item.Bill_to.Replace(_contact_, " ")
End If
If Not String.IsNullOrEmpty(_holder) Then
If item.Bill_to.Contains("Co Rd") Then
_address_ = ExtractAddressWithCoRd(_holder)
End If
Else
If item.Bill_to.Contains("Co Rd") Then
_address_ = ExtractAddressWithCoRd(item.Bill_to)
End If
End If
If Not String.IsNullOrWhiteSpace(item.Customer) Then
If item.Customer.Contains(":") Then
BusinessName = item.Customer.Split(":")(0)
CustomerName = item.Customer.Split(":")(1)
Else
CustomerName = item.Customer
End If
End If
If Not String.IsNullOrEmpty(BusinessName) Then
If item.Bill_to.Contains(BusinessName) Then
_holder = item.Bill_to.Replace(BusinessName, " ")
End If
End If
Dim _Id_ As Integer = _Id
If Not String.IsNullOrWhiteSpace(_holder) Then
Dim _check As Boolean = True
_check = ValidZip(_holder)
If _check = True Then
If Not String.IsNullOrEmpty(_address_) Then
_holder = Convert.ToString(_holder)
_address_ = Convert.ToString(_address_)
_holder = item.Bill_to.Remove(_address_)
End If
parseAddress(_holder, _Id)
The other function is:
Private Function ExtractAddressWithCoRd(ByVal input As String) As String
Dim add1 As String = String.Empty
Dim add2 As String = String.Empty
Dim parts() As String = input.Split(" "c)
For i As Integer = 0 To parts.Length - 1
If parts(i) = "Co" AndAlso i > 0 Then
add1 = parts(i - 1)
ElseIf parts(i) = "Rd" AndAlso i < parts.Length - 1 Then
add2 = parts(i + 1)
End If
Next
Return add1 + " Co Rd " + add2
End Function
This is where I think something is getting changed to a integer value... but this is all declared as string as well...
Any ideas????
Upvotes: 0
Views: 9142
Reputation: 17875
This is where I think something is getting changed to a integer value...
No, that's not it. Read the error message again:
Conversion from string "9838 Co Rd 47" to type 'Integer' is not valid.
"Conversion from string" means that your _address_
variable really IS a string, and it's value is even displayed ("9838 Co Rd 47").
It tries to convert this string to an integer because item.Bill_to
is a String
and String.Remove
expects an integer argument (the position from which to remove characters), but you pass a string instead. What you're looking for is String.Replace
, which you already use elsewhere:
_holder = item.Bill_to.Replace(_address_, "")
Upvotes: 6
Reputation: 154
Are you using options strict? Perhaps in your return you should use
Return add1 & " Co Rd " & add2
Since add1 appears to be 9838?
Upvotes: 0