Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nested For each loops problem. please help

Status
Not open for further replies.

canberrasnag

Programmer
Nov 25, 2004
19
RU
I am having a problem with two nested FOR EACH loops.
it seems as though the inside for each loop, once complete, at the second attempt into the loop, it goes straight to the exit of the loop as though it has already finished... why????
don't the variables reset?
how can I do this?

the code follows.
the code opens a form in a page, goes through each text field in the form and inserts a character.
if the field name is the same as the name in the outside loop, then it inserts a special character.
I can't get past the first loop.. :(

Code:
' ***********************************************************************************
' * File Name:
' *
' * Author :
' *
' * Company :
' *
' * Date :
' *
' * History :
' *
' ***********************************************************************************

' *********Variable Initialisations blow this line***********************************
Dim IEObject, allowableCharacters(), fileObject, charactersFile
'create the IE application object
Set IEObject = CreateObject("InternetExplorer.Application")

Set fileObject = CreateObject("Scripting.FileSystemObject")
Set charactersFile = fileObject.OpenTextFile("allowedTextFieldCharacters.txt",1)





' *********Main Application Processing goes below this line**************************
iUpperBound = 0
While Not charactersFile.AtEndOfStream
ReDim Preserve allowableCharacters(iUpperBound)
allowableCharacters(iUpperBound) = charactersFile.Read(1)
iUpperBound = iUpperBound + 1
Wend

IEObject.Visible=true
IEObject.Navigate2("
do until IEObject.readyState = 4
loop
Dim insideFormer
For Each former In IEObject.Document.Forms
For Each inputObj In former
MsgBox(inputObj.name)
'MsgBox(inputObj.type)

If inputObj.Type = "text" Then
For Each otherInputObj In insideFormer
'MsgBox(otherInputObj.name)
'MsgBox(otherInputObj.type)
If otherInputObj.Type = "text" Then
'MsgBox(otherInputObj.name)
'MsgBox("Outside : " &inputObj.name & "Inside : " &otherInputObj.name)
If inputObj.name = otherInputObj.name Then
otherInputObj.value = "û"
Else
otherInputObj.value = "A"
End If
End If
Next
MsgBox("Click Submit")
For i = 1 To 50000
Next
IEObject.Visible=true
IEObject.Navigate2("
do until IEObject.readyState = 4
loop
End If
MsgBox("Outside : " &inputObj.name )
Next
Next
 
debugging info missed... inside for loop insideFormer, should read as former. I was trying to use set insideFormer = former to try to get around the problem but it didn't work :(
 
canberrasnag wrote

[1] >>For Each inputObj In former

Should only be:
[tt] For Each inputObj In former.[red]elements[/red][/tt]

[2] >>For Each otherInputObj In insideFormer

This can only be pseudo-code. (Does it operate at all?) You have to expand it with more lines.

- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top