2013-09-01 165 views
0

這個循環的問題是什麼?每個循環的雙倍數

我注意到a字符串沒有改變,但我想它應該移動到列表中的下一個字符串,而它可以正常工作ProxyList

Public Class Form1 

    Public ProxyList As New List(Of String) 
    Public AccountList As New List(Of String) 

    For Each a As String In AccountList 
     Dim z() As String = a.Split(":") 

     For Each p As String In ProxyList 
      ' SENDS WEBREQUESTS BY USING ACCOUNTS AND SETS PROXY ' 
     Next 
    Next 

末級

+0

'AccountList'中有多少個字符串? – Tim

+0

超過150+,但它只是不跳過第一個。 – Zozo

+0

你是否已經在調試器中逐步完成代碼?是否拋出任何異常?如果你在'AccountList'初始化的地方顯示代碼,這可能會有所幫助。 – Tim

回答

0

通過賬戶列表這將循環一次在proxyList每一個項目,如果在帳戶列表5項和10 proxyList那麼這段代碼將循環50次。這段代碼沒有什麼問題,除非它不符合你想要的。

從您的評論你想爲accountList和proxyList雙方提前向前一視同仁,你應該定義一個新類:

Public Class ProxyAccount 
    Public Proxy As String 
    Public Account As String 
End Class 

那麼你的代碼變成:

Public Class Form1 

    Public ProxyList As New List(Of ProxyAccount) 

    For Each pa As ProxyAccount In ProxyList 
     Dim a as String = pa.Account 
     Dim z() As String = a.Split(":") 
     Dim p as String = pa.Proxy 
     ' SENDS WEBREQUESTS BY USING ACCOUNTS AND SETS PROXY ' 
     Next 
    Next 
End Class 

或者你也可以做到這一點以及:

Public Class Form1 

    Public ProxyList As New List(Of String) 
    Public AccountList As New List(Of String) 

    For i as Integer = 0 To ProxyList.Count - 1 
     If i >= AccountList.Count Then 
      Exit For 
     End If 
     Dim a As String = AccountList(i)  
     Dim z() As String = a.Split(":") 
     Dim p as String = ProxyList(i) 
     ' SENDS WEBREQUESTS BY USING ACCOUNTS AND SETS PROXY ' 
    Next 
End Class 

這兩個工作都很好,但你會想要重構代碼以更清潔。

+0

感謝幫助我,我試過第二個,它的工作原理:D – Zozo