Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare string against array

Status
Not open for further replies.

blckngldhwk

Technical User
Feb 14, 2008
46
US
Okay, I've never messed around with arrays so I'm pretty ignorant to what can or can't be done with them.

I have a list of over 150 different 'values' and I want to check and see if a certain string is any of those values. So I want to compare a string against these other 150 set values. Is this possible?
 


hi,
Code:
dim a(2) as string, i as integer, mat as string
'load array
a(0) = "red"
a(1) = "green"
a(2) = "yellow"

'match s string
mat = "green"
for i = 0 to ubound(a)
  if a(i) = mat then
    msgbox "match on element " & i
  end if
next


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
That worked great!

Okay, follow-up...


Can you define the number of items in an array with a variable?

Example...

Code:
Items = MyScreen.Getstring(01,02,02)

Dim Array(Items) as string

The issue, I won't know how many items exist in a set until a pull a value from the screen.

Thoughts?
 


So how do you define the number of "items" in the string?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
The numbers of items in the array is based on the number of lines present on the object being looked at. If there are 9 lines I need 9 items. The number of lines always changes.
 


Your example
Code:
Items = MyScreen.Getstring(01,02,02)
ONE row???

So
Items = MyScreen.Getstring(01,02,02)
you would have ONE element in your array and could youe the ReDim statement to resize your array.


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
The information at location (01,02,02) tells me how many lines there are and thus how many times I need to loop and thus how many items I need in my array.
 


well there's your answer!

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
I think I got it, but I'll have to see if it works the way I'm wanting it to.

Dim Array() as string

ReDim Array(Items) as string


Will let you know if this works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top