Isolating If, Else if and Else Statements

Isolating If, Else if and Else Statements

AMN3161
Advocate Advocate
481 Views
1 Reply
Message 1 of 2

Isolating If, Else if and Else Statements

AMN3161
Advocate
Advocate

I have a pretty long code that is a bunch of variations of this

If iProperties.Value("Custom", "Part_Number_1") = "" And iProperties.Value("Custom", "Part_Number_2") = "" And iProperties.Value("Custom", "Part_Number_3") = "" And iProperties.Value("Custom", "Part_Number_4") = "" And iProperties.Value("Custom", "Part_Number_5") = "" And System.IO.File.Exists(iProperties.Value("Custom", "Project_BOM")) = True Then

Dim partNumber As String = iProperties.Value("Project", "Part Number")
partNumber = partNumber.Trim().ToUpper()
i = GoExcel.FindRow("P:\_MASTER_PART_LIST\MASTER_PART_LIST.xls", "MASTER_PART_LIST", "Part No.", "=", partNumber)

If i = -1

	iProperties.Value("Project", "Description") = "The entered Part Number does not exist in the Master Parts List"
	iProperties.Value("Project", "Vendor") = "The entered Part Number does not exist in the Master Parts List"
	
Else

	iProperties.Value("Project", "Description") = GoExcel.CurrentRowValue("Description")
	iProperties.Value("Project", "Vendor") = GoExcel.CurrentRowValue("Manufacturer")
	
	Dim partDescription As String = iProperties.Value("Project", "Description")
	partDescription = partDescription.ToUpper()
	iProperties.Value("Project", "Description")= partDescription

	Dim partVendor As String = iProperties.Value("Project", "Vendor")
	partVendor = partVendor.ToUpper()
	iProperties.Value("Project", "Vendor") = partVendor

End If

oXLS = iProperties.Value("Custom", "Project_BOM")
oSheet = "BOM"
GoExcel.Open(oXLS, oSheet)

For r = 11 To 161

i = String.Compare(iProperties.Value("Project", "Part Number"), GoExcel.CellValue(oXLS, oSheet, "F" & r), True)

If i = 0 Then

Dim CellValue As String = GoExcel.CellValue(oXLS, "BOM", "B" & r)
Dim StrArray As Object
Dim StrResult As String = ""
StrArray = Split(CellValue,vbLf)
For i = LBound(StrArray) To UBound(StrArray)
	If StrResult = "" Then 
		StrResult = StrResult & StrArray(i)
	Else
		StrResult = StrResult & "; " & StrArray(i)
	End If
Next
iProperties.Value("Project", "Stock Number") = StrResult & ";"

r = 161

If iProperties.Value("Project", "Stock Number") = ";" Then iProperties.Value("Project", "Stock Number") = "N/A"
        
Else If i = -1
        
        iProperties.Value("Project", "Stock Number") = "The Part Number doesn't exist in the Project BOM"
        
End If

Next r

End If

 But i am having problems making those If i = -1 and Else statements into If, Else if and Else statements because i am getting errors with End Ifs in other lines of the code. What is a good way to isolate parts of my code to not have their statements interfere with each other?

I can post the entire things but its long and repetitive, figure a small part of it would be enough. I am very novice with this FYI

0 Likes
482 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor

Hi @AMN3161.  Using 1 Tab key press worth of indentation per block level of the code always helped me keep things straight.  The iLogic rule editor will often attempt to create the indentation for you on the next line after you hit Enter at the end of an opening line of a block of code like an If statement line, expecting that the next line will be at a lower level, but you can't always rely on that behavior.  If you include more code on the same 'If' line, after the 'Then', it is then expecting that block of code to be contained to that line.  So if you have done that, then you start the next line with 'Else' or 'ElseIf' it does not work correctly.  You should always wrap an 'If' statement to the next line immediately after the 'Then' keyword, then you can start the next line with 'Else' or 'ElseIf'.  But if you need to use longer lines of code, you can use the " _" (space, then an underscore) at the end of an unfinished line of code, to wrap it to the next line, when you want to wrap it in an unusual location, and maintain its functionality.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes