Results 1 to 8 of 8

Thread: crazy?

  1. #1

    Thread Starter
    Hyperactive Member Davadvice's Avatar
    Join Date
    Apr 2007
    Location
    Glasgow (Scotland)
    Posts
    440

    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

  2. #2
    Hyperactive Member Max Peck's Avatar
    Join Date
    Oct 2007
    Posts
    384

    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

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  4. #4
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: crazy?

    VS2005 indents automatically to prevent that. What a wonderful feature...

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: crazy?

    Quote 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!

  6. #6
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    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:

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: crazy?

    That is beyond "nuts" sevenhalo....that is pure insanity.

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    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
  •  



Click Here to Expand Forum to Full Width