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. Re: Yet Another gem from the VB6 code I'm "porting"

Re: Yet Another gem from the VB6 code I'm "porting"

Scheduled Pinned Locked Moved The Weird and The Wonderful
rubyhelpcode-reviewlounge
5 Posts 3 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.
  • R Offline
    R Offline
    Rob Grainger
    wrote on last edited by
    #1

    For some reason, I think they've made that second line overcomplicated...

    If (rst!general_damages <> "100000+") Then
    F.txtDamages = Left("" & rst!general_damages, InStr(1, "" & rst!general_damages, "-", vbTextCompare) - 1)
    Else
    F.txtDamages = Left("" & rst!general_damages, InStr(1, "" & rst!general_damages, "+", vbTextCompare) - 1) ' Could be simplified to F.txtDamages = "100000"
    End If

    and further down...

    MsgBox "Error occured with Worksource ID " & Val("" & F.txtWorksourceID) & " cannot be found"

    txtWorksourceID is a text box, so this prepends an empty string to the contents of a text box, converts that to a number, then converts that back to a string to include in a message. It works of course (there are many,m nay subtle bugs in this project), but doesn't exactly improve maintainability.

    "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

    G 1 Reply Last reply
    0
    • R Rob Grainger

      For some reason, I think they've made that second line overcomplicated...

      If (rst!general_damages <> "100000+") Then
      F.txtDamages = Left("" & rst!general_damages, InStr(1, "" & rst!general_damages, "-", vbTextCompare) - 1)
      Else
      F.txtDamages = Left("" & rst!general_damages, InStr(1, "" & rst!general_damages, "+", vbTextCompare) - 1) ' Could be simplified to F.txtDamages = "100000"
      End If

      and further down...

      MsgBox "Error occured with Worksource ID " & Val("" & F.txtWorksourceID) & " cannot be found"

      txtWorksourceID is a text box, so this prepends an empty string to the contents of a text box, converts that to a number, then converts that back to a string to include in a message. It works of course (there are many,m nay subtle bugs in this project), but doesn't exactly improve maintainability.

      "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

      G Offline
      G Offline
      greldak
      wrote on last edited by
      #2

      Looks like some VB4 code - prepending with an empty string is to cast the variable to a string. Usually only needed if you are concatenating strings which may hold numeric data. Much better ways to castin VB6

      R 1 Reply Last reply
      0
      • G greldak

        Looks like some VB4 code - prepending with an empty string is to cast the variable to a string. Usually only needed if you are concatenating strings which may hold numeric data. Much better ways to castin VB6

        R Offline
        R Offline
        Rob Grainger
        wrote on last edited by
        #3

        "Looks like some VB4 code" - apparently not, the company was born in 2003! The code is liberally littered with them. I can almost forgive it on db access:

        Dim s As String
        s = "" & rs!value

        but really don't see its use in some cases, to paraphrase, things like:

        Dim i As Integer
        Dim s As String
        s = 123
        s = 123 & ("" & val(s)) && ("" & i)

        I think the approach is "we're not sure when we need to cast, or how to do it, so we'll cast everywhere just in case.

        "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

        G D 2 Replies Last reply
        0
        • R Rob Grainger

          "Looks like some VB4 code" - apparently not, the company was born in 2003! The code is liberally littered with them. I can almost forgive it on db access:

          Dim s As String
          s = "" & rs!value

          but really don't see its use in some cases, to paraphrase, things like:

          Dim i As Integer
          Dim s As String
          s = 123
          s = 123 & ("" & val(s)) && ("" & i)

          I think the approach is "we're not sure when we need to cast, or how to do it, so we'll cast everywhere just in case.

          "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

          G Offline
          G Offline
          greldak
          wrote on last edited by
          #4

          Rob Grainger wrote:

          The code is liberally littered with them. I can almost forgive it on db access:

          Dim s As String
          s = "" & rs!value

          Thats where I normally come across it - I'd suspect they found the same site/book to find out how to code it as the originators of the software I work on.

          Rob Grainger wrote:

          I think the approach is "we're not sure when we need to cast, or how to do it, so we'll cast everywhere just in case.

          hehe at least they're consisent :sigh:

          1 Reply Last reply
          0
          • R Rob Grainger

            "Looks like some VB4 code" - apparently not, the company was born in 2003! The code is liberally littered with them. I can almost forgive it on db access:

            Dim s As String
            s = "" & rs!value

            but really don't see its use in some cases, to paraphrase, things like:

            Dim i As Integer
            Dim s As String
            s = 123
            s = 123 & ("" & val(s)) && ("" & i)

            I think the approach is "we're not sure when we need to cast, or how to do it, so we'll cast everywhere just in case.

            "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

            D Offline
            D Offline
            Dan Neely
            wrote on last edited by
            #5

            Rob Grainger wrote:

            "Looks like some VB4 code" - apparently not, the company was born in 2003!

            The brain guilty of creating that code must have been ossified for at least 6 years then. (VB5 came out in 97.)

            Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

            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