Jump to content

Arrays


Recommended Posts

Ok I have a bit of code that I would figure works, but I have no idea why it doesn't. I'm trying to Get the amount of lines in a file, split each line with a delimeter of "|" and retrieve the text to the left of that "|". Here's what I have:

$filelinesnum = _FileCountLines($sFile)
Dim $filelines
_FileReadToArray($sFile, $filelines)
Dim $leftofdelim[1][$filelinesnum]
For $i = 1 to $filelinesnum
$split = StringSplit($filelines, "|")
$leftofdelim[$i]  = $split[1]
Next

The error I get is "Array variable has incorrect number of subscripts or subscript dimension range exceeded." Can someone help please

My site for HTML Help :)[quote name='Valik' date='Oct 15 2004, 12:29 PM']Maybe nobody is an "elite uber-coder" like me because thinking is a capital offense in today's online-world?[right][snapback]36427[/snapback][/right][/quote]
Link to comment
Share on other sites

  • Developers

Ok I have a bit of code that I would figure works, but I have no idea why it doesn't. I'm trying to Get the amount of lines in a file, split each line with a delimeter of "|" and retrieve the text to the left of that "|". Here's what I have:

$filelinesnum = _FileCountLines($sFile)
Dim $filelines
_FileReadToArray($sFile, $filelines)
Dim $leftofdelim[1][$filelinesnum]
For $i = 1 to $filelinesnum
$split = StringSplit($filelines, "|")
$leftofdelim[$i]  = $split[1]
Next

The error I get is "Array variable has incorrect number of subscripts or subscript dimension range exceeded." Can someone help please

<{POST_SNAPBACK}>

didn't tst but shouldn't this:

Dim $leftofdelim[1][$filelinesnum]

be

Dim $leftofdelim[$filelinesnum]

EDIT: by the way ... why use _FileCountLines() ? $filelines(0) also contains the number of records....

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Hi..

another problem beside the false Dim statment, i see in you code..

is the usage of the StringSplit.

afaik StringSplit splits a string.. not an array..#

so the command should be:

$split = StringSplit($filelines[$i], "|") ;note the [$i]

hope i could help..

Domonoky

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...