Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old April 29th, 2006, 12:44 AM
ehsanking ehsanking is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 207 ehsanking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 3 m 51 sec
Reputation Power: 4
Talking 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:





[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]

Reply With Quote
  #2  
Old May 10th, 2006, 10:24 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Moderator
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,932 sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 6 Days 22 h 36 m 35 sec
Reputation Power: 1243
Quote:
Originally Posted by ehsanking
Code:
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

Private Sub Command3_Click()

Dim CurrURL As String
CurrURL = NextURL
'to reset
CurrURL = NextURL(True)


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!!

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Problem getting out of infinite loop and incremting values


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT