Re: Yet Another gem from the VB6 code I'm "porting"
-
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 Ifand 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.
-
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 Ifand 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.
-
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
"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!valuebut 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.
-
"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!valuebut 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.
Rob Grainger wrote:
The code is liberally littered with them. I can almost forgive it on db access:
Dim s As String
s = "" & rs!valueThats 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:
-
"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!valuebut 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.
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