?
Solved

Returning a array string in a function

Posted on 2007-03-22
8
Medium Priority
?
225 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 80 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 460 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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 460 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

719 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