Answered by:
index was outside the bounds of the array in vb.net

Question
-
User1878568433 posted
This is my code
My segment is like that :- EB*D*IND*AD~
If arrMessage(i).Split("*").GetValue(0) = "EB" Then
If arrMessage(i).Split("*").GetValue(1) = "D" ThenIf arrMessage(i).Split("*").GetValue(3).Contains("AD")
it is fine in this case.
But if my segment is like :- EB*D*IND~
If arrMessage(i).Split("*").GetValue(0) = "EB" Then
If arrMessage(i).Split("*").GetValue(1) = "D" ThenIf arrMessage(i).Split("*").GetValue(3).Contains("AD") I am getting error here
How to handle this error.
Please help me
Monday, June 11, 2018 8:38 AM
Answers
-
User-369506445 posted
hi
this error is about your array length, you want to access to 3 element of an array that does not exist here
you can check it before call below likes:
first get your array length
Dim arrCount = arrMessage(i).Split("*")
and check before IF
If (arrCount > 3) Then If arrMessage(i).Split("*").GetValue(3).Contains("AD") Then
and complete code
For i = 1 To 10 Dim arrCount = arrMessage(i).Split("*") If arrMessage(i).Split("*").GetValue(0) = "EB" Then If arrMessage(i).Split("*").GetValue(1) = "D" Then If (arrCount > 3) Then If arrMessage(i).Split("*").GetValue(3).Contains("AD") Then End If End If End If End If Next
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, June 11, 2018 9:03 AM -
User1878568433 posted
Now I am getting this Error.
Operator '>' is not defined for type 'String()' and type 'Integer'.
Please help me. It is urgent
My for loop started like this :- For i = 0 To arrMessage.Length - 1
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, June 11, 2018 9:26 AM -
User-369506445 posted
you have to change <g class="gr_ gr_19 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar replaceWithoutSep" id="19" data-gr-id="19">below</g> line
Dim arryCount = arrMessage(i).Split("*")
to
Dim arryCount As String() = arrMessage(i).Split("*")
and this line
If (arryCount > 3) Then
to
If (arryCount.Length > 3) Then
and your <g class="gr_ gr_20 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="20" data-gr-id="20">compelet</g> code
For i = 1 To 10 Dim arryCount As String() = arrMessage(i).Split("*") If arrMessage(i).Split("*").GetValue(0) = "EB" Then If arrMessage(i).Split("*").GetValue(1) = "D" Then If (arryCount.Length > 3) Then If arrMessage(i).Split("*").GetValue(3).Contains("AE") Then Try If Not arrMessage(i).Split("*").GetValue(7) Is Nothing Then PhyTherCAPAmt = arrMessage(i).Split("*").GetValue(7).ToString().ToUpper() lblPhyTherCAP.Text = lblPhyTherCAPAmt.Text PhyTherCAPAmt = PhyTherCAPAmt.ToString("#0.00") lblPhyTherCAP.Text = PhyTherCAPAmt PhyTherCAPAmt = Session("PhyTherCAP") 'PhyTherCAPAmt = PhyTherCAPAmt.Replace("$", String.Empty) End If Catch ex As Exception PhyTherCAPAmt = 0.0 End Try End If End If End If End If Next
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, June 11, 2018 10:48 AM
All replies
-
User-369506445 posted
hi
this error is about your array length, you want to access to 3 element of an array that does not exist here
you can check it before call below likes:
first get your array length
Dim arrCount = arrMessage(i).Split("*")
and check before IF
If (arrCount > 3) Then If arrMessage(i).Split("*").GetValue(3).Contains("AD") Then
and complete code
For i = 1 To 10 Dim arrCount = arrMessage(i).Split("*") If arrMessage(i).Split("*").GetValue(0) = "EB" Then If arrMessage(i).Split("*").GetValue(1) = "D" Then If (arrCount > 3) Then If arrMessage(i).Split("*").GetValue(3).Contains("AD") Then End If End If End If End If Next
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, June 11, 2018 9:03 AM -
User1878568433 posted
Now I am getting this Error.
Operator '>' is not defined for type 'String()' and type 'Integer'.
Please help me. It is urgent
My for loop started like this :- For i = 0 To arrMessage.Length - 1
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, June 11, 2018 9:26 AM -
User-369506445 posted
please put here your complete code and define you get an error in which line
Monday, June 11, 2018 9:48 AM -
User1878568433 posted
Dim PhyTherCAPAmt As Decimal = 0.0
lblPhyTherCAPAmt.Text = "0.00"Dim arryCount = arrMessage(i).Split("*")
If arrMessage(i).Split("*").GetValue(0) = "EB" Then
If arrMessage(i).Split("*").GetValue(1) = "D" Then
If (arryCount > 3) Then Here only coming Operator '>' is not defined for type 'String()' and type 'Integer' error
If arrMessage(i).Split("*").GetValue(3).Contains("AE") Then
Try
If Not arrMessage(i).Split("*").GetValue(7) Is Nothing Then
PhyTherCAPAmt = arrMessage(i).Split("*").GetValue(7).ToString().ToUpper()
lblPhyTherCAP.Text = lblPhyTherCAPAmt.Text
PhyTherCAPAmt = PhyTherCAPAmt.ToString("#0.00")
lblPhyTherCAP.Text = PhyTherCAPAmt
PhyTherCAPAmt = Session("PhyTherCAP")
'PhyTherCAPAmt = PhyTherCAPAmt.Replace("$", String.Empty)
End If
Catch ex As Exception
PhyTherCAPAmt = 0.0
End Try
End If
End If
End If
End IfPlease help soon
Monday, June 11, 2018 10:32 AM -
User-369506445 posted
you have to change <g class="gr_ gr_19 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar replaceWithoutSep" id="19" data-gr-id="19">below</g> line
Dim arryCount = arrMessage(i).Split("*")
to
Dim arryCount As String() = arrMessage(i).Split("*")
and this line
If (arryCount > 3) Then
to
If (arryCount.Length > 3) Then
and your <g class="gr_ gr_20 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="20" data-gr-id="20">compelet</g> code
For i = 1 To 10 Dim arryCount As String() = arrMessage(i).Split("*") If arrMessage(i).Split("*").GetValue(0) = "EB" Then If arrMessage(i).Split("*").GetValue(1) = "D" Then If (arryCount.Length > 3) Then If arrMessage(i).Split("*").GetValue(3).Contains("AE") Then Try If Not arrMessage(i).Split("*").GetValue(7) Is Nothing Then PhyTherCAPAmt = arrMessage(i).Split("*").GetValue(7).ToString().ToUpper() lblPhyTherCAP.Text = lblPhyTherCAPAmt.Text PhyTherCAPAmt = PhyTherCAPAmt.ToString("#0.00") lblPhyTherCAP.Text = PhyTherCAPAmt PhyTherCAPAmt = Session("PhyTherCAP") 'PhyTherCAPAmt = PhyTherCAPAmt.Replace("$", String.Empty) End If Catch ex As Exception PhyTherCAPAmt = 0.0 End Try End If End If End If End If Next
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, June 11, 2018 10:48 AM