Jump to content
Sign in to follow this  
Shibuya

Need help writing an expression

Recommended Posts

Shibuya

Hi peeps,

I need help with writing an expression.

I've got a file which is read into an array.

Changes have been made to the array and I'm writing the array into a new file.

What I wrote until now was:

$i = 1

For [exp[b][/b]ression]

Filewriteline("test.txt", $array[$i])
$i = $i + 1

Next

where what I want in the expression is:

until the end of the array or something like the array returns null

thanx in advance!!

;)

Edited by Shibuya

The speed of sound is defined by the distance from door to computer divided by the time interval needed to close the media player and pull up your pants when your mom shouts "OH MY GOD WHAT ARE YOU DOING!!!"

Share this post


Link to post
Share on other sites
Valuater

Hi peeps,

I need help with writing an expression.

I've got a file which is read into an array.

Changes have been made to the array and I'm writing the array into a new file.

What I wrote until now was:

$i = 1

For [exp[b][/b]ression]

Filewriteline("test.txt", $array[$i])
$i = $i + 1

Next

where what I want in the expression is:

until the end of the array or something like the array returns null

thanx in advance!!

;)

maybe like this

For $i = 1 to $array[0]

Filewriteline("test.txt", $array[$i])

Next

hope that helps

8)

sometimes this works with 1 number less than $array[0]

For $i = 1 to $array[0] -1

Filewriteline("test.txt", $array[$i])

Next

it depends....

hope that helps too

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
Shibuya

maybe like this

For $i = 1 to $array[0]

Filewriteline("test.txt", $array[$i])

Next

hope that helps

8)

hi Valuater,

I've tried that before I posted up this thread.

The file it wrote to is empty.

The sample test code is as follows:

Dim $array[6]

$array[1] = "abc"
$array[2] = "def"
$array[3] = "ghi"
$i = 1

FileOpen("test.txt", 2)

For $i = 1 to $array[0]
    FileWriteLine("test.txt", $array[$i])
    $i = $i + 1
Next

FileClose("test.txt")

The speed of sound is defined by the distance from door to computer divided by the time interval needed to close the media player and pull up your pants when your mom shouts "OH MY GOD WHAT ARE YOU DOING!!!"

Share this post


Link to post
Share on other sites
Valuater

because YOU are creating the array... you need to set the limit

Dim $array[6]

$array[0] = 6
$array[1] = "abc"
$array[2] = "def"
$array[3] = "ghi"


FileOpen("test.txt", 2)

For $i = 1 to $array[0] -1
FileWriteLine("test.txt", $array[$i])
Next

FileClose("test.txt")


run( "notepad.exe test.txt")

this works

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
Shibuya

because YOU are creating the array... you need to set the limit

Dim $array[6]

$array[0] = 6
$array[1] = "abc"
$array[2] = "def"
$array[3] = "ghi"
FileOpen("test.txt", 2)

For $i = 1 to $array[0] -1
FileWriteLine("test.txt", $array[$i])
Next

FileClose("test.txt")
run( "notepad.exe test.txt")

this works

8)

oh yea it works great~!!

but can you explain why is there a "-1" at the end of the expression?

shouldn't it be "+1"? I don't really get it.....


The speed of sound is defined by the distance from door to computer divided by the time interval needed to close the media player and pull up your pants when your mom shouts "OH MY GOD WHAT ARE YOU DOING!!!"

Share this post


Link to post
Share on other sites
Valuater

well.... from a hobbyist's point of view

for... next

does a count for you

for $x = 1 to 100
; do something
Next

will do this 100 times

if you use while... you need to do the count

while $t <= 100
;do something
    $t = $t + 1
WEnd

this will do 100 times also...

$But, with arrays

there are times that the array[0] includes the [0]

as part of the count, thus array[0] -1

what was different with yours was YOU created the array...

thus YOU need to set the [0] = (number)

hope that helps

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
Shibuya

Thanks for the detailed explaination!! :P

It was really helpful

;)


The speed of sound is defined by the distance from door to computer divided by the time interval needed to close the media player and pull up your pants when your mom shouts "OH MY GOD WHAT ARE YOU DOING!!!"

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  

×