Solved

Returning a array string in a function

Posted on 2007-03-22
8
215 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

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)…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
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…

911 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

16 Experts available now in Live!

Get 1:1 Help Now