For..next - Move to next iteration

For..next - Move to next iteration

filippo.costantin3HZMT
Advocate Advocate
1,422 Views
2 Replies
Message 1 of 3

For..next - Move to next iteration

filippo.costantin3HZMT
Advocate
Advocate

Hi everyone, 

 

I have a problem in a code because I want to move to next iteration in a For..next cycle. 

 

When I read an Excel Files, I write a For..next cycle to read every cells, but if the string contains a specific word I need to pass at next iteration. 

 

This is what I read from Excel File. In the second column when I find the word "ANGOLO" (yellow cells) I need to move to next iteration. I attached my Ilogic code

 

 

1.PNG

 

Nome_File_XLS="TK190037_Pavia_Distinta di produzione -RIVESTIMENTO"

SharedVariable("Percorso") = "C:\Users\filippo.costantin\Desktop\WORKPLACE"

'parameter foglio excel
Dim File_corrente = Nome_File_XLS
Dim X_NomeFoglio As String = "Lamiera"
Dim X_PRCodice As String = "C"
Dim X_Descrizione As String = "D"
Dim X_Quantità As String = "E"
Dim X_Colore As String = "F"
Dim X_Spessore As String = "G"
Dim X_HPannello As String = "H"
Dim X_Modulo As String = "J"
Dim X_Gancio As String = "K"
Dim X_CTG As String = "P"
Dim X_Lavorazione As  String ="S"

'parametri del pannello
Dim PR_Codice As String
Dim Descrizione As String

For i As Integer = 60 To 70
	PR_Codice = GoExcel.CellValue(SharedVariable("Percorso") & "\" & File_corrente, X_NomeFoglio, X_PRCodice & i)
	Descrizione=GoExcel.CellValue(SharedVariable("Percorso") & "\" & File_corrente, X_NomeFoglio, X_Descrizione & i)	
	MessageBox.Show(PR_Codice, "Title")
	
	If (String.IsNullOrEmpty(PR_Codice)) Then
		Exit For
	MessageBox.Show("NULLA", "Title")	
	End If
	
	If Descrizione.Contains("Angolo") = True Then
		MessageBox.Show("Angolo", "Title")
		Continue For	
	End If

Next

 

I try to use "Continue For" but it doesen't run correctly. 

Can someone help me?

0 Likes
Accepted solutions (1)
1,423 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor
Accepted solution

the "Continue For" doesnt do anything here because its the last thing in the loop that gets done. You should use the "Continue For" before the things that you want to be skipped.  (Or did you leef out some code her?) maby you can try this:

For i As Integer = 60 To 70
	PR_Codice = GoExcel.CellValue(SharedVariable("Percorso") & "\" & File_corrente, X_NomeFoglio, X_PRCodice & i)
	Descrizione=GoExcel.CellValue(SharedVariable("Percorso") & "\" & File_corrente, X_NomeFoglio, X_Descrizione & i)	
	If Descrizione.Contains("Angolo") = True Then
		MessageBox.Show("Angolo", "Title")
		Continue For	
	End If
	MessageBox.Show(PR_Codice, "Title")
	
	If (String.IsNullOrEmpty(PR_Codice)) Then
' i changed the order here the message box would never been shown
                MessageBox.Show("NULLA", "Title")	
		Exit For
	        
	End If
Next

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 3

filippo.costantin3HZMT
Advocate
Advocate

Hi,

Now it run thanks, but i don't undestand why before the code that I write doesn't work. Where I wrong? 

I only switch the if whit "EXIT" and with "CONTINUE", but I think it shold run. 

Could you explain me?

 

Thanks

0 Likes