|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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: ![]() [VBCODE] ' 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 ' 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 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 Text2.Text = Inet1.OpenURL(CurrURL, icString) 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 MsgBox " file written successfully to the file!" ' after this part i want the url get incremented and it getchecked in Command3_Click End Sub[/VBCODE] |
|
#2
|
||||
|
||||
|
Quote:
Hi, your problem is the fact that you call the function NextURL each time (in the line I have highlighted) and pass the parameter "True" to it which has the effect of resetting the CurrID back to 16411 each time!!! Just take this line out. Just a couple of observations: Firstly: It is a good idea to always declare Option Explicit at the start of your code as it will force you to adhere to strict naming conventions and wont let you use variables that you haven't declared. And secondly, you do not need to declare sURL as a Constant again within the NextURL Function because you have already declared it as a Global Constant!! |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Problem getting out of infinite loop and incremting values |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|