Solved

Returning a array string in a function

Posted on 2007-03-22
8
213 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
 
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
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…

758 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

21 Experts available now in Live!

Get 1:1 Help Now