|
-
Oct 30th, 2007, 10:39 AM
#1
Thread Starter
Hyperactive Member
crazy?
is it just me or is this nuts looking ?
Code:
Select Case intSysvolts
Case 230 ' 230
Select Case intPhases
Case 1 ' 1 phase
Select Case strVTRatio
Case "N/A" ' 1 phase
Select Case strCtRatio
Case "200/5" ' 1 phase
strWCLVHV = "1 Ph CT 200/5"
Case "100/5" '3 phase
strWCLVHV = "1 Ph CT 100/5"
Case Else '3 phase
strWCLVHV = "1 Ph"
End Select
Case Else '3 phase
strWCLVHV = "HV 1 Phase 230V??????"
End Select
Case 3 '3 phase
Select Case strVTRatio
Case "N/A" ' 1 phase
Select Case strCtRatio
Case "200/5" ' 1 phase
strWCLVHV = "3 Ph CT 200/5 but 230Volt"
Case "100/5" '3 phase
strWCLVHV = "3 Ph CT 100/5 but 230Volt"
Case Else '3 phase
strWCLVHV = "3 Ph but 230Volt"
End Select
Case Else '3 phase
strWCLVHV = "HV 3 Phase 230V??????"
End Select
Case Else '
strWCLVHV = "Unknown"
End Select
Case 440 ' 440
Select Case intPhases
Case 1 ' 1 phase
Select Case strVTRatio
Case "N/A" ' 1 phase
Select Case strCtRatio
Case "1 PH" ' 1 phase
strWCLVHV = "1 Phase 440V "
Case "W/C" '3 phase
strWCLVHV = "1 Ph 440V WC"
Case Else '3 phase
strWCLVHV = "1 Ph 440V CT"
End Select
Case Else '3 phase
strWCLVHV = "HV 1 Phase 440V??????"
End Select
Case 3 '3 phase
Select Case strVTRatio
Case "N/A" ' 1 phase
Select Case strCtRatio
Case "W/C" ' 1 phase
strWCLVHV = "WC"
Case Else '3 phase
strWCLVHV = "LV CT"
End Select
Case Else '3 phase
strWCLVHV = "HV 3 Phase 440V??????"
End Select
Case Else
strWCLVHV = "Unknown"
End Select
David
-
Oct 30th, 2007, 10:49 AM
#2
Re: crazy?
Well ... I wouldn't go as far as saying it's "nuts" really - it is, at least, neat and easily read. If those power designations are constants that don't change (which it looks like they are) then the code is going to be extremely quick in returning the appropriate string designation.
I'd have put these strings in a table indexed by Phase and Ratio - but this isn't by a long shot the worst select case I've seen in commercial code. Sometimes ya just gotta do it!
-Max
The name's "Peck" .... "Max Peck"
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." - Red Adair
-
Oct 30th, 2007, 10:54 AM
#3
Re: crazy?
It is perfectly indented just as it should be. It is easy to read, easy to follow, and would be easy to make a change to.
"Nuts" is when there is no indentation at all.
-
Oct 30th, 2007, 10:59 AM
#4
Re: crazy?
VS2005 indents automatically to prevent that. What a wonderful feature...
-
Oct 30th, 2007, 11:11 AM
#5
Re: crazy?
 Originally Posted by timeshifter
VS2005 indents automatically to prevent that. What a wonderful feature...
I could not agree more sir. It truly is a beautiful thing!
-
Oct 30th, 2007, 11:30 AM
#6
Re: crazy?
That's not nuts, this is nuts:
Code:
On Error Resume Next
If intSysvolts = 230 Then GoTo bm230
If intSysvolts = 440 Then GoTo bm440
GoTo ResumeNext
bm230:
If intphases = 1 Then GoTo bm1
If intphases = 3 Then GoTo bm3
GoTo DefaultAll1
bm1:
If strVTRatio = "N/A" Then GoTo bmRatio
GoTo ResumeNext
bmRatio:
If strCtRatio = "200/5" Then GoTo bm2005
If strCtRatio = "100/5" Then GoTo bm1005
GoTo bmDefault1
bm2005:
strWCLVHV = "1 Ph CT 200/5"
GoTo ResumeNext
bm1005:
strWCLVHV = "1 Ph CT 100/5"
GoTo ResumeNext
bmDefault1:
strWCLVHV = "1 Ph"
GoTo ResumeNext
DefaultAll1:
strWCLVHV = "HV 1 Phase 230V??????"
GoTo ResumeNext
bm3:
If strVTRatio = "N/A" Then GoTo bmctRatio
GoTo DefaultAll2
bmctRatio:
If strCtRatio = "200/5" Then GoTo bm20052
GoTo ResumeNext
bm20052:
strWCLVHV = "3 Ph CT 200/5 but 230Volt"
If strCtRatio = "100/5" Then GoTo bm10051
GoTo ResumeNext
bm10051:
strWCLVHV = "3 Ph CT 100/5 but 230Volt"
GoTo ResumeNext
DefaultAll2:
strWCLVHV = "Unknown"
GoTo ResumeNext
ResumeNext:
-
Oct 30th, 2007, 11:40 AM
#7
Re: crazy?
That is beyond "nuts" sevenhalo....that is pure insanity.
-
Nov 7th, 2007, 01:02 PM
#8
Re: crazy?
It's not really bad, but if you don't like the appearance, there are ways to clean it up if this is the whole set of choices. I noted these points:
1) The outermost select case has only two options, which branch on an integer, so you could just have an If Else statement, which would do the same thing, but remove two net lines.
2) The comments are pretty much nuts, because regardles of the phase select statement, the comments pretty much always say 3 phase, even when the string is 1 ph.
3) If the voltage is 230, the strings can pretty much be built by concatenating various components together in the above example, so if those are the only options, doing that might make sense. The same is not really true for 440.
None of those suggestions offer any improvement over the posted code, they are just meant to point out alternative looking solutions to the same problem.
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|