Sign in to follow this  
Followers 0
the_lord_mephy

Arrays

3 posts in this topic

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]

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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

Share this post


Link to post
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
Sign in to follow this  
Followers 0