I am not familiar with VB.NET and, in order to try to understand the legacy code (which is sloppily formatted) I'm maintaining better, I fed it into the indentation machine here.
But this is part of what come out of it:
currentYear = Year(Now)
SQLString = "Select NewBiz from MasterUnitsprojSales where CYear = " & currentYear & " and Unit = '" & Unit & "'"
adoRS = New ADODB.Recordset
adoRS.Open(SQLString, adoCon)
IsNewBusiness = TRUE 'default (if record not found)
Category = "New Business"
If Not adoRS.EOF Then
IsNewBusiness = adoRS.Fields.Item(0).Value <> 0
if Not IsNewBusiness
Category = "Existing Business"
End If
Response.Write("<!-- IsNewBusiness after NOT adoRS.EOF check = " & CStr(IsNewBusiness) & " -->")
End If
adoRS.Close()
If Request.Form.Item("Action") = "Save" Then
Response.Write("<!-- Made it into the Action =Save block -->")
Unit = Request.Form.Item("Unit")
. . .
Is this right? It seems to me that it should be more like this:
currentYear = Year(Now)
SQLString = "Select NewBiz from MasterUnitsprojSales where CYear = " & currentYear & " and Unit = '" & Unit & "'"
adoRS = New ADODB.Recordset
adoRS.Open(SQLString, adoCon)
IsNewBusiness = TRUE 'default (if record not found)
Category = "New Business"
If Not adoRS.EOF Then
IsNewBusiness = adoRS.Fields.Item(0).Value <> 0
if Not IsNewBusiness
Category = "Existing Business"
End If
Response.Write("<!-- IsNewBusiness after NOT adoRS.EOF check = " & CStr(IsNewBusiness) & " -->")
End If
adoRS.Close()
If Request.Form.Item("Action") = "Save" Then
Response.Write("<!-- Made it into the Action =Save block -->")
Unit = Request.Form.Item("Unit")
. . .
I know it's just formatting, and it won't cause the code to work any differently, but it would help me a lot to have it formatted correctly (specifically and especially with the "if"s and "endif"s etc. lining up).
Any time there is an "If" there must be a corresponding "End If" right?
Assuming that's so, this indenterized code is even more confusing:
If Not adoRS.EOF Then
CustomerChk = adoRS.Fields.Item(0).Value
adoRS.Close()
If CustomerChk <> CustNo Then
...Shouldn't it be:
If Not adoRS.EOF Then
CustomerChk = adoRS.Fields.Item(0).Value
adoRS.Close()
If CustomerChk <> CustNo Then
? Otherwise, it makes it look like the first if block ends without any explicit say-so.
Aucun commentaire:
Enregistrer un commentaire