Message 1 of 2
Isolating If, Else if and Else Statements
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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