Jump to content

May sound rediculous... but please


glasglow
 Share

Recommended Posts

$N = 12

Dim $x[$N] = [1,2,3,4,5,6,7,8,9,10,11,12]

Dim $y[$N] = [24.91,29.65,29.40,28.90,27.80,25.74,23.76,23.83,26.12,26.86,27.01,25.36]

Right now I am using this. And I would like to instead of writing out the variables, pull the variables out of either a text file or out of a csv file and instead of hardcoding the number of records I'd like to count the number of records as they are pulled out of the text or csv file.

I've tried some csv parsers on here and they don't seem to be giving me what I need, and it seems when I try filereadtoarray it doesn't allow me to use the $x[$N] type variable. Any suggestions?

lllllllllllllllllllllllllllllllllllllllll

After a few minutes I got this:

$N = 12
Dim $x
_FileReadToArray("x.txt", $x)
;Dim $x[$N] = [1,2,3,4,5,6,7,8,9,10,11,12]
Dim $y[$N] = [24.91,29.65,29.40,28.90,27.80,25.74,23.76,23.83,26.12,26.86,27.01,25.36]

However I don't seem to be getting the same results in later calculations.

Edited by glasglow
Link to comment
Share on other sites

When you use _Filereadtoarray you just need to have a declared variable it doesn't need to already be an array.

Something like

Local $file
_filereadtoarray('yourfilegoeshere.txt',$file)

Edit: Fixed code tag

Edited by Kerros

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Link to comment
Share on other sites

It's really strange. If I use:

$N = 7
Dim $x[$N] = [0,2,4,6,8,10,12]
Dim $y[$N] = [2.1,5.0,9,12.6,17.3,21,24.7]

And if I use this:

$N = 7
Local $x
_filereadtoarray('x.txt',$x)
Local $y
_filereadtoarray('y.txt',$y)

Inside file x.txt I have:

0

2

4

6

8

10

12

And Inside file y.txt I have:

2.1

5.0

9,

12.6

17.3

21,

24.7

And I get different results. It does look like it is, or should be exactly the same... yes? Does the $x[$N] make it different or is it reading the text file in a different way? I seem to be missing something.

Edited by glasglow
Link to comment
Share on other sites

The results are slightly different because of the way that _filereadtoarray is putting the data into the array versus manually filling in the array.

From the Helpfile

Remarks

$aArray[0] will contain the number of records read into the array.

If you ignore the first element, both arrays should be the same as long as the information in the text file is correct.

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Link to comment
Share on other sites

The results are slightly different because of the way that _filereadtoarray is putting the data into the array versus manually filling in the array.

From the Helpfile

If you ignore the first element, both arrays should be the same as long as the information in the text file is correct.

I see.. very interesting. So when looping through I start with For $i = 1 to $N instead of $i = 0?

Any other way around to "ignore" the first element?

Link to comment
Share on other sites

If you really want to get rid of the first element, use _arraydelete($x[0]), but yes, I normally use For $i = 1 to ubound($x)

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Link to comment
Share on other sites

This one will error when it hits the last value for $i since the UBound($x) will exceed the array dimensions by 1.. would need to be "UBound($x) - 1"

I normally use For $i = 1 to ubound($x)

This is a better solution: You already have the correct dimension size stored in $x[0] for looping

For $i = 1 to $x[0]

Link to comment
Share on other sites

Thank you guys for the help. What worked best for me in this case was:

Local $x
_filereadtoarray('x.txt',$x)
Local $y
_filereadtoarray('y.txt',$y)

_arraydelete($x,0)
_arraydelete($y,0)

It completely cleared out the element put into the beginning by the _filereadtoarray

Link to comment
Share on other sites

This one will error when it hits the last value for $i since the UBound($x) will exceed the array dimensions by 1.. would need to be "UBound($x) - 1"

Opps, yes that would cause a problem... that's what I get for trying to get a thought out quick.

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

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