Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Returning a array string in a function

Posted on 2007-03-22
8
218 Views
Last Modified: 2010-05-18
I am having problem returning a array string in a function.

Say I have the following function:

Function LookUpList() As String
        Dim SiteList(10) As String
        Dim Count = 0

        For Each sLine In arrText
            SiteList(Count) = "testing123"
            Count = Count + 1
        Next

       Return SiteList
End Function


Now when I call it, I just want to save it into another array:

Sub UpdateChargeAccount()
        Dim SiteList2 As String
        SiteList2 = LookUpList()
End Sub

What is wrong with the above code? New in VB .NET...
0
Comment
Question by:bri_stc
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 20 total points
ID: 18774810
Had you tried...

Dim SiteList2() As String
SiteList2() = LookUpList()
0
 
LVL 1

Author Comment

by:bri_stc
ID: 18774861
After changing it to your suggestion, i am getting this error for SiteList2()... "Number of indice is less than the number of dimensions of the indexed array."

The code now looks like:

Function LookUpList() As String
        Dim SiteList(10) As String
        Dim Count = 0

        For Each sLine In arrText
            SiteList(Count) = "testing123"
            Count = Count + 1
        Next

       Return SiteList()  ' <-----  error saying "Number of indice is less than the number of dimensions of                      the indexed array."
End Function


Now when I call it, I just want to save it into another array:

Sub UpdateChargeAccount()
        Dim SiteList2() As String
        SiteList2() = LookUpList() ' <-----  error saying "Number of indice is less than the number of dimensions of                      the indexed array."
End Sub
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 115 total points
ID: 18774944
It should look like this:

    ' *** Note the () AFTER String
    Function LookUpList() As String()
        Dim SiteList(10) As String
        Dim Count = 0

        For Each sLine In arrText
            SiteList(Count) = "testing123"
            Count = Count + 1
        Next

        Return SiteList
    End Function

    ' *** Note the () AFTER SiteList2
    Sub UpdateChargeAccount()
        Dim SiteList2() As String
        SiteList2 = LookUpList()
    End Sub
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 6

Expert Comment

by:riyazthad
ID: 18774946
Function LookUpList() As String ===>>> It should be

Function LookUpList() As String()

since you are returning array of string

0
 
LVL 6

Assisted Solution

by:riyazthad
riyazthad earned 115 total points
ID: 18774977
one more ...

 Return SiteList()  ' <-----  error saying "Number of indice is less than the number of dimensions of                      the indexed array."

it should be

Return SiteList
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18774993
You mean just like in my example above?...   =)
0
 
LVL 6

Expert Comment

by:riyazthad
ID: 18775022
I am sorry, Idle_Mind:, yes same solution.

you posted before me. I didnt notice that.....
0
 
LVL 1

Author Comment

by:bri_stc
ID: 18775047
It works fine now! thanks!

handing out pts :)
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 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