problem getting out of infinite loop and incremting values
Hi all. I got this application that once go button clicked it takes single url value and goes trough some process as shown in pic and at the end writes the content of text4 to a text file. Now i want automate this process for range of range of URL i tried to do the following but i get into infinite loop and value of URL does not get incremented and only one url get executed succssefully!! I be happy if some one look at it and let me know how i can fix this problem.Thanks
layout of form without using loop for single url . which works perfectly:
http://www.vbforums.com/images/ieimages/2006/04/1.jpg
VB Code:
' start from here
'Private Const sURL As String = "http://localhost/player/player.asp?id="
Dim CurrID As Integer
Private Function NextURL(Optional Reset As Boolean = False) As String
If CurrID = 0 Or Reset Then CurrID = 16411
If CurrID = 16420 Then Exit Function
Const sURL As String = "http://localhost/player/player.asp?id="
'NextURL = sURL & CuurID
NextURL = sURL & CurrID
MsgBox "URL:" & NextURL
CurrID = CurrID + 1
MsgBox "CurrID" & CurrID
'Text2.Text = Inet1.OpenURL(CurrURL, icString)
' MsgBox "testing"
'End If
End Function
[B]' once i click the go button this function start with first url and should
keep chaing url by incrementing it untill it reaches end of the range[/B]
Private Sub Command3_Click()
Dim CurrURL As String
CurrURL = NextURL
'to reset
CurrURL = NextURL(True)
Text1.Text = CurrURL
MsgBox "CurrentUrl:" & CurrURL
MsgBox "nexturl:" & NextURL
Select Case Index
Case 0
If Text1.Text <> "" Then
[B]Text2.Text = Inet1.OpenURL(CurrURL, icString)[/B]
End If
Case 1
End
End Select
'MsgBox "testing"
Command4_Click
Command3_Click ' caling himself again
End Sub
Private Sub Command4_Click()
' It returns a string so just use it like:
'Text3.Text = GetLine2(Text2.Text, "mp3player.swf?playlist=", ".exe")
Text3.Text = "http://localhost/player/" & GetLine2(Text2.Text, "mp3player.swf?playlist=", ".exe")
Command5_Click
End Sub
Private Function GetLine2(ByVal sText As String, ByVal sStart As String, ByVal sEnd As String) As String
Dim lPos As Long, lEnd As String
lPos = InStr(1, sText, sStart, vbTextCompare)
If lPos Then
lEnd = InStr(lPos, sText, sEnd)
If lEnd Then
GetLine2 = Mid$(sText, lPos + Len(sStart), lEnd - (lPos + Len(sStart))) & sEnd
Else
GetLine2 = Mid$(sText, lPos + Len(sStart))
End If
End If
End Function
Private Sub Command5_Click()
Select Case Index
Case 0:
If Text3.Text <> "" Then
Text4.Text = Inet1.OpenURL(Text3.Text, icString)
End If
Case 1:
End
End Select
Command7_Click
End Sub
' this funcion needs to write to a text file
Private Sub Command7_Click()
'Dim Parser As New clsXMLParser
' Dim Node As clsXMLNode
'Dim Child As clsXMLNode
Dim fn As Long
'Dim i As Long
'Dim path As String
'Dim title As String
fn = FreeFile
Open "C:\albums.txt" For Append As #fn
'Yes. Use Print #fn instead of Write #fn
'Write #fn, Text4.Text
Print #fn, Text4.Text
Close #fn
[B]MsgBox " file written successfully to the file!"[/B]
' after this part i want the url get incremented and it getchecked in Command3_Click
End Sub
Re: problem getting out of infinite loop and incremting values
I'm sorry but I don't understand your question. Could you show more urls and the data you want to get from them? Also please let me know where the urls are stored in your program. A textbox?
Re: problem getting out of infinite loop and incremting values
Quote:
Originally Posted by MartinLiss
I'm sorry but I don't understand your question. Could you show more urls and the data you want to get from them? Also please let me know where the urls are stored in your program. A textbox?
The url is like this :
Code:
http://localhost/player/player.asp?id=
and the value of url id is supposed to change and it starts from id=16411 to id=16420 .
At start of each itteration the url get placed in text1 and it get manipulated and the result of text4 will be written to text file and it has to chanege increment url id and do the same thing over and over till ur id reaches16420. Right now my program executes the first url with id=16411 only over and over !!! What i want after execution of each url the next url get executed untill i reach url with id=16420 but apparently the url id does not get incremented at all therefore the function is runing for ever and writs the same data over and over :( . I be happy if some one tell me how to increment url id correctly and i do not fall in infinite loop.Thanks
The bold parts are importent parts
VB Code:
Dim CurrID As Integer
Private Function NextURL(Optional Reset As Boolean = False) As String
If CurrID = 0 Or Reset Then [B]CurrID = 16411[/B] If [B]CurrID = 16420 [/B] Then Exit Function
[B]Const sURL As String = "http://localhost/player/player.asp?id="[/B]
'NextURL = sURL & CuurID
NextURL = sURL & CurrID
MsgBox "URL:" & NextURL
CurrID = CurrID + 1
MsgBox "CurrID" & CurrID
'Text2.Text = Inet1.OpenURL(CurrURL, icString)
' MsgBox "testing"
'End If
End Function
Private Sub Command3_Click()
Dim CurrURL As String
[B]CurrURL = NextURL[/B]
'to reset
[B]CurrURL = NextURL(True)[/B]
Text1.Text = CurrURL
MsgBox "CurrentUrl:" & CurrURL
MsgBox "nexturl:" & NextURL
Select Case Index
Case 0
If Text1.Text <> "" Then
Text2.Text = Inet1.OpenURL(CurrURL, icString)
End If
Case 1
End
End Select
'MsgBox "testing"
[B]Command4_Click ===> for each value of url id i want this and rest of function execute then this function runs with incremented url id till i reach end of the rang[/B]
[B]Command3_Click ' caling himself again[/B]
End Sub
Re: problem getting out of infinite loop and incremting values
Also try using VBCODE tags instead of the CODE tags you currently use.