Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASCII Stupid Question... return array from frunction 2

Status
Not open for further replies.

acent

Technical User
Feb 17, 2006
247
US
Greetings y'all...

After a break from Access development, I'm back in the saddle, and I think it is time to stop beating my head against the proverbial wall. This is a simple thing to do, and I can do it in a few different languages, unfortunately, VBA isn't one of them.

What I'm trying to do is open a text file, read a line, parse out data and return the data values in an array. So...
Code:
Private Sub readFile()
...
    inFile = FreeFile
    Open "C:\test.txt" For Input As inFile
...
    While Not EOF(inFile)
      Line Input #inFile, txtLineIn
      Dim test() = processStaticLine(txtLineIn) '<--- error caused here
      ...
end sub

Private Function processStaticLine(stringIn As String) As String
...
  sArrayOut(rst2("rank")) = fld
...
  processStaticLine = sArrayOut
End Function
This is the start of a relatively big project so this code will change, but the concept will not - run readFile, get the array and do something with it.

I have fumbled through many different ways to tackle this, coming short with type mismatch, and other compile errors, but Murphy keeps making an appearance.

Any help is appreciated.

"If it's stupid but works, it isn't stupid."
-Murphy's Military Laws
 
Try:

Code:
Private Function processStaticLine(stringIn As String) As String[!]()[/!]

The open/close parenthesis on the end indicates you are returning an array of strings from the function.


-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
You also need to dimension the array separately from actually using it.

Code:
Private Sub readFile()
...    
    [!]Dim test() As string[/!]

    inFile = FreeFile
    Open "C:\test.txt" For Input As inFile
...    
    While Not EOF(inFile)      
      Line Input #inFile, txtLineIn
      [!]test() = [/!]processStaticLine(txtLineIn) '<--- error caused here      
...
end sub

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Awesome! Thank you gmmastros.

I knew it was some really stupid edits that needed to be done.

"If it's stupid but works, it isn't stupid."
-Murphy's Military Laws
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top