Solved

VB.Net - Find String in Array

Posted on 2016-10-12
3
25 Views
Last Modified: 2016-10-12
Good Day Experts!

I think what I want to do is possible but I am struggling how to get started and I hope you can point me in the right direction.

I have a Case statement that I would like to use a search of  arrayLists to determine which block of Case statement to run.
I have 3 different ArrayLists pre-populated.  I have a DataReader of Accounts  that I need to loop through and determine which block of code to run.  So if the Account is in ArrayList1 run this code, if Account is in ArrayList2 run this code etc...
The Account won't be in multiple ArrayLists.

Case "Account in ArrayList1 = yes"
     ....................

Case "Account in ArrayList2 = yes"
     ...................

Case "Account in ArrayList3 = yes"
     ...................


I have been searching the net for some time and am having a bit of trouble getting started.  Can you help?

Thanks,
jimbo99999
0
Comment
Question by:Jimbo99999
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
Dustin Saunders earned 500 total points
ID: 41840200
You can use the .Contains() method to determine if a string is in an array.  Here's an example:

        Dim array1() = New String() {"yes", "no", "yes", "yes"}
        Dim array2() = New String() {"yes", "yes", "yes", "yes"}

        If array1.Contains("no") Then
            Console.WriteLine("array1")
        End If

        If array2.Contains("no") Then
            Console.WriteLine("array2")
        End If

        Console.ReadLine()

Open in new window


In this example, the console will read "array1" only.
0
 

Author Comment

by:Jimbo99999
ID: 41840237
Thank you. I have integrated .Contains and running the code now.
0
 

Author Closing Comment

by:Jimbo99999
ID: 41840286
Exactly what I was looking for. It works great!

Thanks,
jimbo99999
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now