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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB.NET Checking array values 2

Status
Not open for further replies.

WebGuyToo

Programmer
Aug 18, 2004
124
US
Hello, I'm trying to determine if an array has a value in it and come up with something that works but is there a better way? Any help would be great. Thanks WebGuyToo

Here is what I have: my array is a string array

Dim LineIn As String
Dim arrArgs() As String

LineIn = FileReader.ReadLine 'read line by line
arrArgs = Split(LineIn, "|")

******* here is the code
If CType(arrArgs(6), Boolean).TrueString = "" Then
strSpecialtyEffDates = arrArgs(6)
Else
strSpecialtyEffDates = ""
End If
 
You can use array.indexof(arrArgs, ValueToFind) if you know the value.

or you can iterate through the array if you are looking for some calculated value:
Code:
dim s as string
for each s in arrArgs
  if s = MyCalculation then
    'do something
    exit for
  end if
next

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
You should also check that you have at least 7 elements in the array with the code you are supplied otherwise it will cause an exception when you attempt to address the 7th element (index 6)

Bob Boffin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top