Results 1 to 7 of 7

Thread: General VB question

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2003
    Posts
    1

    Question 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

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    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

  4. #4
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    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

  5. #5

  6. #6
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    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

  7. #7
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    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:
    1. Public Function SearchArray(ByRef strArray() As String, ByVal strSearchFor As String) As Integer
    2.         Dim I As Integer
    3.  
    4.         For I = 0 To UBound(strArray) ' count from 0 to the last string in the array
    5.             If InStr(strArray(I), strSearchFor, CompareMethod.Text) <> 0 Then
    6.                 'InStr returns 0 if the string is not found in it
    7.                 Return I ' return the Index of the string in the array
    8.             End If
    9.         Next
    10.         'If were still here then that mean that there is no strSearchFor in any of the strings
    11.         'In the array
    12.         Return -1
    13.     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
  •  



Click Here to Expand Forum to Full Width