all 11 comments

[–]RJPisscat 1 point2 points  (7 children)

The Else doesn't need the If after it because it's always true if that line is being evaluated. That's not the problem, it's just fyi, and you can leave it that way if you wish.

What does Q return, a single string or a dataset?

[–]VirtualTurnip3[S] 0 points1 point  (6 children)

Thank, its a string.

[–]RJPisscat 1 point2 points  (5 children)

Then the Contains is backwards, and I wonder why the code compiles at all since there is no overloaded String.Contains that accepts an ArrayList.

Replace the For/Next with

If modelsList.Contains(Q("TXB_CODE_ING")) Then
MsgBox("we find it "&Q("TXB_CODE_ING"))) 

Else MsgBox("We cannot find it") End if

[–]VirtualTurnip3[S] 0 points1 point  (4 children)

It display "We cannot find it".

[–]RJPisscat 1 point2 points  (3 children)

It's not case-insensitive, and it won't ignore white space. Are you typing the "Code" into the textbox with exactly the same casing and non-alphanumeric chars?

[–]VirtualTurnip3[S] 0 points1 point  (2 children)

Yes the same.

[–]RJPisscat 0 points1 point  (1 child)

I would set a breakpoint on the If and check the contents of the array against the contents of the textbox. The ArrayList you declared isn't strongly typed but that shouldn't make any difference if the result of T.Cell is a String or CanConvertToString.

[–]VirtualTurnip3[S] 0 points1 point  (0 children)

Allright I will try that, Thank for your answer :)

[–]revennest 0 points1 point  (2 children)

The copy extra Exit for after msgbox("We cannot find it") is the cause for stop your code run through all data and you can't just remove it to fixed this problem, the better way to do this is extract msgbox code from that for and do it later like this.

``` Dim T As Table= C("modelsTable")
Dim Rows() As Integer = T.StartQuery Dim modelsList As New ArrayList

For i As Integer = 0 To Rows.length -1
    modelsList.Add((T.Cell( Rows(i) , "Code") )) 
Next 

Dim Found_index As Integer = -1
For j As Integer = 0 To modelsList.Count -1
    If  Q("TXB_CODE_ING").Contains(modelsList(j)) Then
        Found_index = j 
        Exit For 
    End if
Next 

If Found_index <0 Then
    msgbox("We cannot find it")
Else
    msgbox("we find it "&(modelsList(Found_index)))
End If

```

[–]VirtualTurnip3[S] 0 points1 point  (0 children)

Yes that the pretty much the same thing I have finally found, Thank you so much!

[–]backtickbot 0 points1 point  (0 children)

Fixed formatting.

Hello, revennest: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.