Results 1 to 4 of 4

Thread: problem getting out of infinite loop and incremting values

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Arrow 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:





    VB Code:
    1. ' start from here
    2. 'Private Const sURL As String = "http://localhost/player/player.asp?id="
    3. Dim CurrID As Integer
    4.  
    5.  
    6. Private Function NextURL(Optional Reset As Boolean = False) As String
    7.     If CurrID = 0 Or Reset Then CurrID = 16411
    8.     If CurrID = 16420 Then Exit Function
    9.    
    10.  Const sURL As String = "http://localhost/player/player.asp?id="
    11.         'NextURL = sURL & CuurID
    12.         NextURL = sURL & CurrID
    13.        
    14.         MsgBox "URL:" & NextURL
    15.  
    16.         CurrID = CurrID + 1
    17.        
    18.         MsgBox "CurrID" & CurrID
    19.        
    20.         'Text2.Text = Inet1.OpenURL(CurrURL, icString)
    21.              ' MsgBox "testing"
    22.     'End If
    23. End Function
    24.  
    25.  
    26. [B]' once i click the go button this function start with first url and should
    27. keep chaing url by incrementing it untill it reaches end of the range[/B]
    28. Private Sub Command3_Click()
    29.  
    30. Dim CurrURL As String
    31. CurrURL = NextURL
    32. 'to reset
    33. CurrURL = NextURL(True)
    34.  
    35. Text1.Text = CurrURL
    36. MsgBox "CurrentUrl:" & CurrURL
    37. MsgBox "nexturl:" & NextURL
    38.  
    39.     Select Case Index
    40.     Case 0
    41.         If Text1.Text <> "" Then
    42.             [B]Text2.Text = Inet1.OpenURL(CurrURL, icString)[/B]
    43.              
    44.            
    45.         End If
    46.    
    47.     Case 1
    48.         End
    49.     End Select
    50.    'MsgBox "testing"
    51.    
    52. Command4_Click
    53. Command3_Click ' caling himself again
    54. End Sub
    55.  
    56. Private Sub Command4_Click()
    57. ' It returns a string so just use it like:
    58. 'Text3.Text = GetLine2(Text2.Text, "mp3player.swf?playlist=", ".exe")
    59. Text3.Text = "http://localhost/player/" & GetLine2(Text2.Text, "mp3player.swf?playlist=", ".exe")
    60. Command5_Click
    61.  
    62. End Sub
    63.  
    64. Private Function GetLine2(ByVal sText As String, ByVal sStart As String, ByVal sEnd As String) As String
    65.     Dim lPos As Long, lEnd As String
    66.     lPos = InStr(1, sText, sStart, vbTextCompare)
    67.     If lPos Then
    68.         lEnd = InStr(lPos, sText, sEnd)
    69.         If lEnd Then
    70.             GetLine2 = Mid$(sText, lPos + Len(sStart), lEnd - (lPos + Len(sStart))) & sEnd
    71.         Else
    72.             GetLine2 = Mid$(sText, lPos + Len(sStart))
    73.         End If
    74.     End If
    75. End Function
    76.  
    77.  
    78. Private Sub Command5_Click()
    79. Select Case Index
    80.     Case 0:
    81.         If Text3.Text <> "" Then
    82.             Text4.Text = Inet1.OpenURL(Text3.Text, icString)
    83.         End If
    84.    
    85.     Case 1:
    86.         End
    87. End Select
    88.  
    89. Command7_Click
    90. End Sub
    91.  
    92.  
    93. ' this funcion needs to write to a text file
    94. Private Sub Command7_Click()
    95. 'Dim Parser As New clsXMLParser
    96.  ' Dim Node As clsXMLNode
    97.   'Dim Child As clsXMLNode
    98.   Dim fn As Long
    99.   'Dim i As Long
    100.  
    101.  'Dim path As String
    102.   'Dim title As String
    103.  
    104.   fn = FreeFile
    105.   Open "C:\albums.txt" For Append As #fn
    106.   'Yes. Use Print #fn instead of Write #fn
    107.     'Write #fn, Text4.Text
    108.     Print #fn, Text4.Text
    109.   Close #fn
    110.  
    111.   [B]MsgBox " file written successfully to the file!"[/B]
    112. ' after this part i want the url get incremented and it getchecked in Command3_Click
    113.  
    114. End Sub
    Last edited by tony007; Apr 28th, 2006 at 07:33 PM.

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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?

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    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:
    1. Dim CurrID As Integer
    2.  
    3.  
    4. Private Function NextURL(Optional Reset As Boolean = False) As String
    5.     If CurrID = 0 Or Reset Then [B]CurrID = 16411[/B]    If [B]CurrID = 16420 [/B] Then Exit Function
    6.    
    7.  [B]Const sURL As String = "http://localhost/player/player.asp?id="[/B]
    8.         'NextURL = sURL & CuurID
    9.         NextURL = sURL & CurrID
    10.        
    11.         MsgBox "URL:" & NextURL
    12.  
    13.         CurrID = CurrID + 1
    14.        
    15.         MsgBox "CurrID" & CurrID
    16.        
    17.         'Text2.Text = Inet1.OpenURL(CurrURL, icString)
    18.              ' MsgBox "testing"
    19.     'End If
    20. End Function
    21.  
    22. Private Sub Command3_Click()
    23.  
    24. Dim CurrURL As String
    25. [B]CurrURL = NextURL[/B]
    26. 'to reset
    27. [B]CurrURL = NextURL(True)[/B]
    28.  
    29.  
    30.  
    31. Text1.Text = CurrURL
    32. MsgBox "CurrentUrl:" & CurrURL
    33. MsgBox "nexturl:" & NextURL
    34.  
    35.     Select Case Index
    36.     Case 0
    37.         If Text1.Text <> "" Then
    38.             Text2.Text = Inet1.OpenURL(CurrURL, icString)
    39.              
    40.            
    41.         End If
    42.    
    43.     Case 1
    44.         End
    45.     End Select
    46.    'MsgBox "testing"
    47.    
    48. [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]
    49. [B]Command3_Click ' caling himself again[/B]
    50. End Sub
    Last edited by tony007; Apr 28th, 2006 at 07:30 PM.

  4. #4
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: problem getting out of infinite loop and incremting values

    Also try using VBCODE tags instead of the CODE tags you currently use.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width