Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. When you got your numbers, who needs other types

When you got your numbers, who needs other types

Scheduled Pinned Locked Moved The Weird and The Wonderful
questioncomhelptutorial
10 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yusuf
    wrote on last edited by
    #1

    I have being trying to modify a legecy vb com code. First of all, when it is vb you thing nothing can be right. Then you come across something that is shear madness

    Public Function UpdateOrderState(ByVal oldState As Long, ByVal newState As Long)
    Dim StockDir As Long, StockChange As Boolean
    StockChange = True

    Select Case 10 * oldState + newState
    'Case 12, 32 added more options
    Case 12, 32, 42, 52, 62, 72
    StockDir = -1
    'Case 21, 23 added more options
    Case 21, 23, 24, 25, 26, 27
    StockDir = 1
    Case Else
    StockChange = False
    End Select

    If StockChange Then
       'Code removed
    End If
    

    End Function

    What it is doing is that, it is trying to figure out a state change from one to another. All applicable states have values. Now, what if the value of the states change? :mad:

    Yusuf May I help you?

    D I A T J 5 Replies Last reply
    0
    • Y Yusuf

      I have being trying to modify a legecy vb com code. First of all, when it is vb you thing nothing can be right. Then you come across something that is shear madness

      Public Function UpdateOrderState(ByVal oldState As Long, ByVal newState As Long)
      Dim StockDir As Long, StockChange As Boolean
      StockChange = True

      Select Case 10 * oldState + newState
      'Case 12, 32 added more options
      Case 12, 32, 42, 52, 62, 72
      StockDir = -1
      'Case 21, 23 added more options
      Case 21, 23, 24, 25, 26, 27
      StockDir = 1
      Case Else
      StockChange = False
      End Select

      If StockChange Then
         'Code removed
      End If
      

      End Function

      What it is doing is that, it is trying to figure out a state change from one to another. All applicable states have values. Now, what if the value of the states change? :mad:

      Yusuf May I help you?

      D Offline
      D Offline
      Dan Mos
      wrote on last edited by
      #2

      Yusuf wrote:

      Now, what if the value of the states change?

      The code changes too! And on the plus side you get to recompile and deploy the new version. That's what pros do :-\ ;)

      Just an irritated, ranting son of ... an IT guy. At your trolling services

      1 Reply Last reply
      0
      • Y Yusuf

        I have being trying to modify a legecy vb com code. First of all, when it is vb you thing nothing can be right. Then you come across something that is shear madness

        Public Function UpdateOrderState(ByVal oldState As Long, ByVal newState As Long)
        Dim StockDir As Long, StockChange As Boolean
        StockChange = True

        Select Case 10 * oldState + newState
        'Case 12, 32 added more options
        Case 12, 32, 42, 52, 62, 72
        StockDir = -1
        'Case 21, 23 added more options
        Case 21, 23, 24, 25, 26, 27
        StockDir = 1
        Case Else
        StockChange = False
        End Select

        If StockChange Then
           'Code removed
        End If
        

        End Function

        What it is doing is that, it is trying to figure out a state change from one to another. All applicable states have values. Now, what if the value of the states change? :mad:

        Yusuf May I help you?

        I Offline
        I Offline
        Ian Shlasko
        wrote on last edited by
        #3

        It's not even doing that much.... All it's doing is checking whether the state changed to/from 2 (Or neither)...

        If oldState = newState Then
        StockChange = False
        Else if oldState = StockStates.WhateverTheHell2Means Then
        StockDir = 1
        Else if newState = StockStates.WhateverTheHell2Means Then
        StockDir = -1
        End If

        Don't ya just hate legacy code?

        Proud to have finally moved to the A-Ark. Which one are you in?
        Author of the Guardians Saga (Sci-Fi/Fantasy novels)

        Y 1 Reply Last reply
        0
        • Y Yusuf

          I have being trying to modify a legecy vb com code. First of all, when it is vb you thing nothing can be right. Then you come across something that is shear madness

          Public Function UpdateOrderState(ByVal oldState As Long, ByVal newState As Long)
          Dim StockDir As Long, StockChange As Boolean
          StockChange = True

          Select Case 10 * oldState + newState
          'Case 12, 32 added more options
          Case 12, 32, 42, 52, 62, 72
          StockDir = -1
          'Case 21, 23 added more options
          Case 21, 23, 24, 25, 26, 27
          StockDir = 1
          Case Else
          StockChange = False
          End Select

          If StockChange Then
             'Code removed
          End If
          

          End Function

          What it is doing is that, it is trying to figure out a state change from one to another. All applicable states have values. Now, what if the value of the states change? :mad:

          Yusuf May I help you?

          A Offline
          A Offline
          Andrew Rissing
          wrote on last edited by
          #4

          I wonder if you ran code obfuscation on it, would it produce more readable code? :D

          D 1 Reply Last reply
          0
          • I Ian Shlasko

            It's not even doing that much.... All it's doing is checking whether the state changed to/from 2 (Or neither)...

            If oldState = newState Then
            StockChange = False
            Else if oldState = StockStates.WhateverTheHell2Means Then
            StockDir = 1
            Else if newState = StockStates.WhateverTheHell2Means Then
            StockDir = -1
            End If

            Don't ya just hate legacy code?

            Proud to have finally moved to the A-Ark. Which one are you in?
            Author of the Guardians Saga (Sci-Fi/Fantasy novels)

            Y Offline
            Y Offline
            Yusuf
            wrote on last edited by
            #5

            Ian Shlasko wrote:

            Don't ya just hate crappy legacy code?

            ftfy

            Yusuf May I help you?

            1 Reply Last reply
            0
            • Y Yusuf

              I have being trying to modify a legecy vb com code. First of all, when it is vb you thing nothing can be right. Then you come across something that is shear madness

              Public Function UpdateOrderState(ByVal oldState As Long, ByVal newState As Long)
              Dim StockDir As Long, StockChange As Boolean
              StockChange = True

              Select Case 10 * oldState + newState
              'Case 12, 32 added more options
              Case 12, 32, 42, 52, 62, 72
              StockDir = -1
              'Case 21, 23 added more options
              Case 21, 23, 24, 25, 26, 27
              StockDir = 1
              Case Else
              StockChange = False
              End Select

              If StockChange Then
                 'Code removed
              End If
              

              End Function

              What it is doing is that, it is trying to figure out a state change from one to another. All applicable states have values. Now, what if the value of the states change? :mad:

              Yusuf May I help you?

              T Offline
              T Offline
              Thomas Krojer
              wrote on last edited by
              #6

              This looks crazy ... but I would not blame the programming language, the original developer of this piece of ... code? ... will write bad code in any language.

              _ 1 Reply Last reply
              0
              • T Thomas Krojer

                This looks crazy ... but I would not blame the programming language, the original developer of this piece of ... code? ... will write bad code in any language.

                _ Offline
                _ Offline
                _Erik_
                wrote on last edited by
                #7

                I agree, absolutely.

                1 Reply Last reply
                0
                • Y Yusuf

                  I have being trying to modify a legecy vb com code. First of all, when it is vb you thing nothing can be right. Then you come across something that is shear madness

                  Public Function UpdateOrderState(ByVal oldState As Long, ByVal newState As Long)
                  Dim StockDir As Long, StockChange As Boolean
                  StockChange = True

                  Select Case 10 * oldState + newState
                  'Case 12, 32 added more options
                  Case 12, 32, 42, 52, 62, 72
                  StockDir = -1
                  'Case 21, 23 added more options
                  Case 21, 23, 24, 25, 26, 27
                  StockDir = 1
                  Case Else
                  StockChange = False
                  End Select

                  If StockChange Then
                     'Code removed
                  End If
                  

                  End Function

                  What it is doing is that, it is trying to figure out a state change from one to another. All applicable states have values. Now, what if the value of the states change? :mad:

                  Yusuf May I help you?

                  J Offline
                  J Offline
                  Jeremy Hutchinson
                  wrote on last edited by
                  #8

                  Every time you add a new state you need to change the code, recompile and release. And if that weren't enough the third time you'd need to rewrite the function to handle a State of 10. Did you add the "Code removed" comment, or is this function actually doing nothing at all?

                  Y 1 Reply Last reply
                  0
                  • A Andrew Rissing

                    I wonder if you ran code obfuscation on it, would it produce more readable code? :D

                    D Offline
                    D Offline
                    DaveyM69
                    wrote on last edited by
                    #9

                    :laugh: :thumbsup:

                    Dave

                    If this helped, please vote & accept answer!

                    Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
                    BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

                    1 Reply Last reply
                    0
                    • J Jeremy Hutchinson

                      Every time you add a new state you need to change the code, recompile and release. And if that weren't enough the third time you'd need to rewrite the function to handle a State of 10. Did you add the "Code removed" comment, or is this function actually doing nothing at all?

                      Y Offline
                      Y Offline
                      Yusuf
                      wrote on last edited by
                      #10

                      Jeremy Hutchinson wrote:

                      Did you add the "Code removed" comment, or is this function actually doing nothing at all?

                      I did that only for CP. There is some code in that block.

                      Yusuf May I help you?

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups