Shibuya Posted September 21, 2005 Share Posted September 21, 2005 (edited) 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 Nextwhere what I want in the expression is:until the end of the array or something like the array returns nullthanx in advance!! Edited September 21, 2005 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!!!" Link to comment Share on other sites More sharing options...
Valuater Posted September 21, 2005 Share Posted September 21, 2005 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 Nextwhere what I want in the expression is:until the end of the array or something like the array returns nullthanx in advance!! maybe like thisFor $i = 1 to $array[0] Filewriteline("test.txt", $array[$i]) Nexthope that helps8)sometimes this works with 1 number less than $array[0]For $i = 1 to $array[0] -1 Filewriteline("test.txt", $array[$i]) Nextit depends....hope that helps too8) Link to comment Share on other sites More sharing options...
Shibuya Posted September 21, 2005 Author Share Posted September 21, 2005 maybe like thisFor $i = 1 to $array[0] Filewriteline("test.txt", $array[$i]) Nexthope that helps8)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!!!" Link to comment Share on other sites More sharing options...
Valuater Posted September 21, 2005 Share Posted September 21, 2005 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) Link to comment Share on other sites More sharing options...
Shibuya Posted September 21, 2005 Author Share Posted September 21, 2005 because YOU are creating the array... you need to set the limitDim $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 works8)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!!!" Link to comment Share on other sites More sharing options...
Valuater Posted September 21, 2005 Share Posted September 21, 2005 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) Link to comment Share on other sites More sharing options...
Shibuya Posted September 21, 2005 Author Share Posted September 21, 2005 Thanks for the detailed explaination!! 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!!!" Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now