How to search an array in VB and get result if in the array using an "if statement"

Usaskater

New Member
Joined
May 7, 2010
Messages
34
I am trying to get a result if a particular model is in one text file and another if in another text file do something else.

My text files are located on c:\test\full.txt and c:\test\part.txt

full.txt has
model 1
model 2
model 3

Part.txt has
Model 4
Model 5
Model 6

I tried using an array and got it to work but I have to "hard code" the array number for it to work. I would also like it to "pull" from the text files. I only tried with the "full" array first.I would like for it to scroll through the list and if it is in there then "do this" if not "do that.

Here is what I have partially:
Dim MyFull (2)
myfull (0)= "model 1"
myfull (1)= "model 2"
myfull (2)= "model 3"

strComputer = "."
Set objWMIService = GetObject("winmgts:\\" & strComputer & "\root\CIMV2)
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystems")
For Each objItem In colItems
strRawModelNumber = objItem.model

If strRawModelNumber = myfull(1) Then
spanModelNumber.innerhtml = strRawModelNumber

Else spanModelNumber2.innerhtml=strRawModelNumber

End if

Next


Note:Spanmodelnumber prints green font to the screen
Spanmodelnumber2 prints red font to screen.
On the "If strRawModelNumber = myfull(1) line I have to put a number between the () in order for it to work. I would like it to automatically scroll through list and if it is in there print to screen the appropriate color. I didn't finish then else code either.

Any help would greatly be appreciated. Thanks
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Forum statistics

Threads
1,203,071
Messages
6,053,373
Members
444,658
Latest member
lhollingsworth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top