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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

For Each looop will not stop

Status
Not open for further replies.

rbri

Programmer
Jun 27, 2002
84
US
Hello Everyone

I am writing a script using the hta extension to get a GUI interface. One of my options to do is list the vendor daemon and port number it is using. the sub I use to populate the array is working and fill the array properly. When I call the sub that reads the array is having a problem that I can't seem to figure out. When the for each loop gets to the end of the array I expect it to stop return the variable I filled and write it to my text window, however that does not happen it just keeps looping inside the array and never returns. Any help you can provide will be greatly appreiciated. Thank you for your help. Below is the sub I am using to get the info I wanted.

Sub portuse()

pickvendor()
pickserv()
intNum = 0
intArraySize = UBound(aintPNum)
MsgBox intArraySize
strOutput = "Vendor Daemon" & vbTab & "Port Num" & vbNewLine
For Each strLine In astrVDName
Msgbox "Vendor Daemon" & " " & "Port Num" & vbNewLine & strLine & vbTab & vbTab & aintPNum(intNum)
strOutput = strOutput & strLine & vbTab & vbTab & aintPNum(intNum) & vbNewLine
intNum = intNum + 1
Next
document.forms.licmgr.output.value = strOutput
intNum = 0

End Sub

As you can see I have put variaous message boxes in trying to debug but, I still can't seem to find what is wrong. I was able to confirm that the array does have the correct data in it because as the for loop does it's looping I get the answers I expect howerver if I remove that msgbox from inside the for loop the loop never stops. I was able to get the for loop to stop by adding an "if" statement using the ubound answer to get inside the "if" statement then I said "Exit For" it did exit long enough to write to my text window but, then entered the for loop again. I even tried "Exit Sub" after the code that set the data to the text window but it seemed to ignore the "Exit Sub" statement. I am really confused.
 
Where does astrVDName come from?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Hello

Here is the sub that populates the astrVDName array.

Sub pickvendor()

intNum = 0
For i = 0 To licmgr.vendors.Length - 1
If licmgr.vendors.options(i).Selected Then
' MsgBox licmgr.vendors.Selected.Options
select case licmgr.vendors.options(i).text
case "MSC"
intPortNum = "1700"
strVDName = "msc"
case "Fluent"
intPortNum = "7241"
strVDName = "FluentLm"
case "Altair"
intPortNum = "7789"
strVDName = "altair_Lm"
case "Ansys"
intPortNum = "1055"
strVDName = "ansysd"
case "Amesim"
intPortNum = "27100"
strVDName = "AMED"
case "Theorem"
intPortNum = "7601"
strVDName = "theorem"
case "GTISoft"
intPortNum = "27005"
strVDName = "GTISOFT"
case "Abaqus"
intPortNum = "27009"
strVDName = "abaqus"
case "StarCD"
intPortNum = "1999"
strVDName = "lmcd"
case "Ansoft"
intPortNum = "27001"
strVDName = "ansoftd"
case "Mentor"
intPortNum = "1717"
strVDName = "mgcld"
case else
msgbox "Error! Please try again"
end select
aintPNum(intNum) = intPortNum
astrVDName(intNum) = strVDName
intNum = intNum + 1
End If

Next

End Sub

Thanks
 
What if you try this:

Code:
Sub portuse()

  pickvendor()
  pickserv()
  intNum = 0
  intArraySize = UBound(aintPNum)
  MsgBox intArraySize
  strOutput = "Vendor Daemon" & vbTab & "Port Num" & vbNewLine
  Do While intNum <= UBound(astrVDName)
   Msgbox "Vendor Daemon" & "   " & "Port Num" & vbNewLine & strLine & vbTab & vbTab & aintPNum(intNum)
   strOutput = strOutput &  astrVDName(intNum) & vbTab & vbTab & aintPNum(intNum) & vbNewLine
  intNum = intNum + 1
  Loop
  document.forms.licmgr.output.value = strOutput
  intNum = 0
 
End Sub

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Hello

I get the same error here is the error I receive:

Line 399
Char 3
Subscript out of range 'intNum'
Code 0

This is line 399:
Msgbox "Vendor Daemon" & " " & "Port Num" & vbNewLine & astrVDName(intNum) & vbTab & vbTab & aintPNum(intNum)

If I comment this line out then it fails on the next line
This is line 400:
strOutput = strOutput & astrVDName(intNum) & vbTab & vbTab & aintPNum(intNum) & vbNewLine

Thanks
 
On the line that errors, echo out the value of intNum so you know if it is going out of range high or low.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Hello
Ok I did that it showed that it was low that the uBound value I checked and for some reason probably me not paying attention but, the arrays where set to different values I made them both the sam now the error message is gone but, my odd behavior is still there. The program now prints to my textwindow and to the msgbox I was using for testing but, for some reason it will not exit the sub after displaying the values that I ask for it starts over isplaying them again but, only to the msgbox not the text window but, it will not come out of the sub. Here is the code after I made the changes you suggested.

Sub portuse()

pickvendor()
pickserv()
intNum = 0
strOutput = "Vendor Daemon" & vbTab & "Port Num" & vbNewLine & vbNewLine
Do While intNum <= UBound(astrVDName)
Msgbox "Vendor Daemon" & " " & "Port Num" & vbNewLine & astrVDName(intNum) & vbTab & vbTab & aintPNum(intNum)
strOutput = strOutput & astrVDName(intNum) & vbTab & vbTab & aintPNum(intNum) & vbNewLine
intNum = intNum + 1
Loop
document.forms.licmgr.output.value = strOutput
intNum = 0

End Sub

I am not sure if I somehow put a hidden character in or one of my lines of code is causing this strange dehavior.

Thanks
 
How does portuse() get called? Is it being called from within a loop?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Are astrVDName and aintPNum dimmed globally (ie outside any procedure/function body) ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hello
Sorry for the long delay I was gone Friday and Monday.
Here is the code that calls portuse().

Sub picksub()

For i = 0 To document.forms.licmgr.infochoice.Length - 1
If document.forms.licmgr.infochoice(i).Checked = True Then
select case document.forms.licmgr.infochoice(i).value
case "servstat"
servstat()
case "licavail"
licavail()
case "licexp"
licexp()
case "licuse"
licuse()
case "licinuse"
licinuse()
case "portuse"
portuse()
case else
msgbox "Error! Please try again"
end select
End If
Next

End Sub

The two variables as aintPNum and astrVDName are both Dim outside of the Sub's at top before any sub's are called but, they are only initiated as Dim's not Public.

Thanks
 
I haven't had time to look into this in depth, but just so that you know, dimming the variables in the main portion of the script makes them global by default.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top