|
-
Nov 5th, 2003, 10:31 PM
#1
Thread Starter
New Member
General VB question
I am very new to the VB.Net thing so, I apologize up front for being a newbie. I am currently taking VB.Net this semester & have a test tomorrow. One of the questions that I am having some difficulty with is this:
Write a function procedure that will search an array of strings for a specific string and return an index or -1 for the case where the string is not found. The first parameter should contain the input array. The second parameter should contain the text string to be located.
Any help on this would be greatly appreciated.
-the phat wonder
-
Nov 5th, 2003, 11:33 PM
#2
Welcome to the vbforums. A few friendly suggestions...
First of all this is the vb6 forum.
Second, most forum members do not like to assist with school projects.
Third, try doing a search of the forums and I'm sure you can find
answers to your questions, especially if you are fairly new to
programming.
Try searching on Arrays, returning values from functions, and the
Instr function.
BTW, Good luck on your test tomorrow.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 6th, 2003, 06:26 AM
#3
Frenzied Member
Originally posted by RobDog888
Second, most forum members do not like to assist with school projects.
I would say it's more a case of members not wanted to actually do the project for the person. Which is what a lot of students ask for.
Good luck phatZo
-
Nov 6th, 2003, 07:56 AM
#4
Regardless of whether it's VB6 or .NET this function should still be the same code...or is it? Am not sure...hmmmmm.
What code have you got already?
I, or we, could write something like that in a few minutes...but that would mean we have done the "project" for you 
Although it is a tricky one as it's a small small amount of code...
Woka
-
Nov 6th, 2003, 03:03 PM
#5
-
Nov 6th, 2003, 03:31 PM
#6
If the array of strings have 1 word on each string (like dim hi() as string={"hi", "die", "***"}) then a very simple loop and comparing the array to a string would be very easy.
Otherwise, if it could be sentences, then you can use RegEx
All the help I'm giving you, you should be alright if you actually pay attention
-
Nov 6th, 2003, 03:53 PM
#7
this code is limited; it just finds the first string in the array with strSearchFor and then quits. you could set it up to return an array of Index's but I am to lazy.
Note: dont just copy and paste this code and modify the name, make sure you understand how it does what it does because you will fall behind in class 
VB Code:
Public Function SearchArray(ByRef strArray() As String, ByVal strSearchFor As String) As Integer
Dim I As Integer
For I = 0 To UBound(strArray) ' count from 0 to the last string in the array
If InStr(strArray(I), strSearchFor, CompareMethod.Text) <> 0 Then
'InStr returns 0 if the string is not found in it
Return I ' return the Index of the string in the array
End If
Next
'If were still here then that mean that there is no strSearchFor in any of the strings
'In the array
Return -1
End Function
Tips:
- Google is your friend! Search before posting!
- Name your thread appropriately... "I Need Help" doesn't cut it!
- Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
- Allways Include the Name and Line of the Exception (if one is occuring!)
- If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)
If you think I was helpful, rate my post  IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|