Solved

Returning a array string in a function

Posted on 2007-03-22
8
223 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
[X]
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
  • 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 86

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 86

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

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

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

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.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

626 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