I have searched for a simple way to search a string array. MS gives a clean simple solution for a one dimesion string.
Dim StrArray() As String = {"ABCDEFG", "HIJKLMNOP"}
Dim FindThisString As String = "JKL"
For Each Str As String In StrArray
If Str.Contains(FindThisString) Then
MsgBox("Found " & FindThisString & " at index " & _
Str.IndexOf(FindThisString))
End If
Next
Just one of my two problems with array, but this one in more pressing. I need to search a multi-dimensional string array. I never dreamed it would be so hard, and while my textbook did cover arrays it did not do the job, their sample code did not even work. So trying the code above I tried the following.
Dim StrArray() As String = Public SparkPlugsString(,) As String = {{"VBAutoPart", "Brand A", "Brand C", "Brand X"}, _
{"PR214", "MR43T", "RBL8", "14K22"}, _
{"PR223", "R43", "RJ6", "14K24"}}
'At this point I am using RBL8 as a test
Dim FindThisString As String = "RBL8"
For Each Str As String In StrArray()
If Str.Contains(FindThisString) Then
MsgBox("Found " & FindThisString & " at index " & _
Str.IndexOf(FindThisString))
End If
Next
I thought it was simply a matter of adding a (,) to the declaration but nope. VB has the returns 2 errors, after I add my array:
Error 1: Expression expected.
Error 2:'StrArray' is not declared. It may be inaccessible due to its protection level.
Please note, I am looking to understand the problem, not just an answer.
Thank you,
diek

New Topic/Question
Reply



MultiQuote

(an image to help my brain) So R43N, index (3,0)entered into the EnterPartNumberTextBox by the user. This corresponds to PR246, index (3,4)and loads "PR246" into VBPartTextBox.




|