Visual Basic Development Bookmark and Share   
 Home > Visual Basic IDE > Returning Array Values Problem
 

Returning Array Values Problem

Hi, i have this code:

...
Dim Labels() As String
Dim Count As Integer
        
Count = 0
          
While Not rso.EOF
                                    
    ReDim Labels(0 To Count)
    rezultatXML = rezultatXML & "<Field>" & rso.Fields("FunctionName") & "</Field>" & vbCrLf        
    Labels(Count) = rso.Fields("FunctionName")
    Count = Count + 1

    rso.MoveNext
                       
Wend
          
Count = Count - 1
...

the code is good, but if i try to return the array values it's a problem:
- If i output the Labels(Count) will return me the last value, where Count = 5, and is all OK
- If i try to output Labels(5)... nothing...

so what is wrong or what i forget?
VafCat  11 hours 41 minutes ago

what is the Count = Count - 1 for?


need to use Redim Preserve

ReDim Preserve Labels(Count)
  • Edited byjwavila 10 hours 57 minutes ago
  • Edited byjwavila 10 hours 47 minutes ago
  •  
jwavila  11 hours 20 minutes ago

what is the Count = Count - 1 for?

the last loop, increment again with +1 and i needed to remove it.
VafCat  11 hours 0 minutes ago
if you re-arrange your code and start Count at -1you don't have to do Count = Count -1


        Dim Labels() As String
        Dim Count As Integer = -1
       
            While Not rso.EOF
                Count += 1
                ReDim Preserve Labels(Count)<br/>                rezultatXML = rezultatXML & "<Field>" & rso.Fields("FunctionName") & "</Field>" & vbCrLf               <br/>
                Labels(Count) = rso.Fields("FunctionName")
                rso.MoveNext<br/><br/>
<br/><br/>             End While
        
jwavila  9 hours 33 minutes ago

You can use google to search for other answers

Custom Search

More Threads

• the Visual Basic XML to Schema Wizard does not install
• Printing the line from VB editor
• Intellisense worked for 1 or 2 minutes, Beta 2
• help with viewing MS access database fields in Vb 2008 app
• multiple users
• Can not create a Release build
• Auto Versioning VB 2005 Express
• Not Allowing Certain Control Types on Windows Form
• Form Debugging problem
• Newbie question about VB Express 2005/ SQL Server Express 2005