Jump to content

Please help for double loop


Recommended Posts

Hi Guys, I spent a whole day but couldn't figure out how can I solve this problem.

#include <IE.au3>

#include <array.au3>

#include <ExcelCOM_UDF.au3>

#include <File.au3>

#include <string.au3>

HotKeySet ("{ESC}", "Terminate")

Dim $Array [5]

$Array[0]= "_1"

$Array[1]= "_2"

$Array[2]= "_3"

$Array[3]= "_4"

$Array[4]= "_5"

Dim $eArray [5]

$eArray [0] = "cat"

$eArray [1] = "dog"

$eArray [2] = "tiger"

$eArray [3] = "bat"

$eArray [4] = "fish"

For $i = 0 To UBound($Array) -1

$file = FileOpen ("C:\animals\template.html",0)

$text = FileRead ($file)

FileClose ($file)

$import = StringReplace ($text,"TitleName","animals")

For $e = 0 To UBound($eArray) -1 #####---> It only loop 1 time

$export = StringReplace ($import,"VolNo",$eArray [$e])

If Not StringInStr ($export, "VolNo") Then

ExitLoop

EndIf

Next

$capture = StringReplace ($export,"TitleNumber","file"&$Array [$i])

$convert = FileOpen ("C:\animals\" & "file" &$Array [$i] &".html", 2)

FileWrite ($convert, $capture)

FileClose ($convert)

Next

#################

Here I got these files, everthing ok except "VolNo" which only contain "cat" for the whole files. Here the sample ;

template.html ---->

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Show Me</title>

</head>

<body>

<p>TitleName</p>

<p>VolNo</p>

<p>TitleNumber </p>

</body>

</html>

file_1.html ---->

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Show Me</title>

</head>

<body>

<p>animals</p>

<p>cat</p>

<p>file_1 </p>

</body>

</html>

file_2.html ---->

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Show Me</title>

</head>

<body>

<p>animals</p>

<p>cat</p> ####--->does't change

<p>file_2 </p>

</body>

</html>

file_3.html ---->

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Show Me</title>

</head>

<body>

<p>animals</p>

<p>cat</p> ####--->does't change

<p>file_3 </p>

</body>

</html>

And so on

file_4.html

file_5.html

How can I loop for both two variable array. Or I have to use the muli dim array right? Please help. Thanks.

Func Terminate ()

Exit 0

EndFunc

Link to comment
Share on other sites

Your second For loop only executes once because of the following lines.

After your StringReplace function, $export will never contain "VolNo".

$export = StringReplace ($import,"VolNo",$eArray [$e])
    If Not StringInStr ($export, "VolNo") Then
    ExitLoopoÝ÷ Ûú®¢×ßÙ§¢Û.­â.׫²Ö§uìZrÙr­ʷö·­¯(§ÚqÊ&¦X¬ôß +­¬Ý7éà+­¬­ím£ZÞ«^v'ªºjÚ®¢

I have a few other suggestions on how to clean this up and do it more efficiently, but first let's make sure this is what you intended.

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Link to comment
Share on other sites

Thanks Skruge for your responding. I intend to loop $eArray and $Array along together that mean

First loop I want this file

file_1.html ----> which inside the file contain;

<p>animals</p>

<p>cat</p> ####--> $eArray

<p>file_1 </p> ####--> $Array

Second loop I want this file

file_2.html ----> which inside the file contain;

<p>animals</p>

<p>dog</p> ####--> $eArray

<p>file_2 </p> ####--> $Array

Third loop I want this file

file_3.html ----> which inside the file contain;

<p>animals</p>

<p>tiger</p> ####--> $eArray

<p>file_3 </p> ####--> $Array

Forth loop I want this file

file_4.html ----> which inside the file contain;

<p>animals</p>

<p>bat</p> ####--> $eArray

<p>file_4 </p> ####--> $Array

Fifthloop I want this file

file_5.html ----> which inside the file contain;

<p>animals</p>

<p>fish</p> ####--> $eArray

<p>file_5 </p> ####--> $Array

I try to use the multi dimension as you suggested. But I have the limit knowledge. Especially each one of $eArray and $Array store 300 vairiable. I have seen many sample provided in this forum but it just a few loops. I no have an ideal how to handle 300 loops like this

$Array[0][0]="cat-_1"

$Array[1][0]="dog-_2"

$Array[0][1]="tiger-_3"

$Array[1][1]="bat-_4"

$Array[x][y]="fish-_5"

|

|

|

v

$Array [y][x]="whale-_300"

What are x and y? Moreover, how can I refer the variable loop it should be "$Array [$e] [$i]" right? So when I declare the variable it should be

Dim $Array [$e] [$i]

$Array[0][0]="cat-_1"

$Array[1][0]="dog-_2"

$Array[0][1]="tiger-_3"

$Array[1][1]="bat-_4"

$Array[x][y]="fish-_5"

|

|

|

v

$Array [y][x]="whale-_300"

Right? Thanks again.

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