 |
|
 |
mlNumOfSomething = SomeClass.GetSomething(anIDArray()) For lli = 1 To mlNumOfSomething SomeClass.GetSomeInfo anIDArray(lli), Description:=aDescription ReDim Preserve msAllAgencies(1 To mlNumOfSomething) msSomeArray(lli) = aDescription Next lli
|
|
|
|
 |
|
 |
I was debugging a problem where one policy was not returning a rate. As I drilled into the problem it became clear there was a bad join, I just had no idea how bad. Here it is, all 1732 characters of it.
join policy_rates.dbo.policy_type_rate on rating_exercise.rating_exercise_id=policy_type_rate.rating_exercise_id and RatingPolicyTypeInfo.policy_type_id=policy_type_rate.policy_type_id and isnull(convert(int,datediff(d,birth_date,RatingPolicyTypeInfo.effective_date)/365.25),case when case when issue_date<case when plan_provision_value_effective_date is null or coverage.effective_date>plan_provision_value_effective_date then coverage.effective_date else plan_provision_value_effective_date end then convert(int,datediff(d,birth_date,case when plan_provision_value_effective_date is null or coverage.effective_date>plan_provision_value_effective_date then coverage.effective_date else plan_provision_value_effective_date end)/365.25) when isnull(uw_issue_date,issue_date)<issue_date then convert(int,datediff(d,birth_date,uw_issue_date)/365.25) else issue_age end<18 then 18 else case when issue_date<case when plan_provision_value_effective_date is null or coverage.effective_date>plan_provision_value_effective_date then coverage.effective_date else plan_provision_value_effective_date end then convert(int,datediff(d,birth_date,case when plan_provision_value_effective_date is null or coverage.effective_date>plan_provision_value_effective_date then coverage.effective_date else plan_provision_value_effective_date end)/365.25) when isnull(uw_issue_date,issue_date)<issue_date then convert(int,datediff(d,birth_date,uw_issue_date)/365.25) else issue_age end end) between policy_type_rate.minimum_age_number and policy_type_rate.maximum_age_number and convert(int,datediff(d,birth_date,getdate())/365.25) between isnull(policy_type_rate.minimum_current_age_number,18) and isnull(policy_type_rate.maximum_current_age_number,110)
I'm not sure if it's a good or bad thing that I can just forwarded the problem to the original developer.
|
|
|
|
 |
|
 |
Aren't you just so glad we are no longer stuck with 80 character coding sheets...  If Barbie is so popular, why do you have to buy her friends?
Eagles may soar, but weasels don't get sucked into jet engines.
If at first you don't succeed, destroy all evidence that you tried.
|
|
|
|
 |
|
 |
Never realized that SQL allows you to place case statements within a join statement, though I guess nothing would syntatically prevent such.
I would highly recommend placing those conversions/etc. into the secondary query being joined (or wrapped in a second query) just to remove the eyebleeding IsNull that trails into the mile long case statements.

|
|
|
|
 |
|
 |
Private Function SomeCrappyCode(lsDate As String) As Long On Error GoTo ErrorHandler
Dim llRetval Dim llPosition As Long llPosition = InStr(lsDate, "Jan") If llPosition > 0 Then lsDate = Left(lsDate, llPosition - 1) & Format(DateSerial(98, 1, 1), "MMM") & right(lsDate, Len(lsDate) - 3) llRetval = True Exit Function End If mlUpdateMonthStringLocale = llRetval Exit Function ErrorHandler:
WriteErrorLogEntry Err.number, "SomeCrappyCode", Err.description Exit Function Resume
End Function
|
|
|
|
 |
|
 |
Ingenious solution to the problem indeed. Obviously it'd be better of with a switch statement though  Jeroen De Dauw --- Forums ; Blog ; Wiki--- 70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|
 |
|
 |
I am not sure how it works in VB exactly, but in a normal language this code would alter local variables lsDate and llRetval without affecting the outside world. So, this function does virtually nothing. Am I right?Greetings - Jacek
|
|
|
|
 |
|
 |
in this case, the incoming parameter defaults to "ByRef", lRetVal defaults to Variant, and the return value is only set when the line of code "ThisFunctionName = aValue", so luckily it sets the lsDate param, but the return value is never set 'cause the author was retarded
|
|
|
|
 |
|
 |
Wes Jones wrote: the return value is never set 'cause the author was retarded
...Greetings - Jacek
|
|
|
|
 |
|
 |
Imagine my horror to find the following code style employed in a body of code I've inherited (VBA, hopefully I'll be able to migrate it away)..
I must say though, there's one VB6/VBA feature I stumbled across in code at work today that makes all these pale into insignificance for obfuscation potential. It's our old friend GoSub/Return.
Function MyFunction ' Do some stuff GoSub CheckRoutine
' Other Stuff GoTo TheEnd
CheckRoutine: ' More stuff Return
TheEnd:
' Cleanup End Function
Refactoring this steaming pile's gonna be fun. (The original function is 250 lines, and oddly, it calls other functions/subs, as well as using GoSub to access "nested" functions).
Last time I saw that pair of keywords actually used in a program dates back to my 2nd computer - the ZX Spectrum. Please reassure me that Microsoft had the good sense to remove these before the advent of VB.NET
|
|
|
|
 |
|
 |
almost gone[^]: EndIf, GoSub, Let, Variant, and Wend are retained as keywords, although they are no longer used in Visual Basic .NET
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
 |
|
 |
Yes, I checked that shortly after posting earlier. Hopefully I won't find similar treasures in the newer code base then.
Same guy seems inordinately fond of empty true-parts of If statements:
If x = 3 Then Else ' Statements here End If
and other horrors, I'll try and keep you posted.
|
|
|
|
 |
|
 |
It's ugly, but will be optimised away.
Panic, Chaos, Destruction. My work here is done.
|
|
|
|
 |
|
 |
If you type Wend in Visual Studio in VB code it automatically replaces it with End While. I can't decide whether that's intended to be helpful (we'll fix that for you, sir) or whether it's a subtle nudge (learn the new syntax, dummy!).
I must admit, I always rather liked the Let keyword. It seemed like such a polite way to code. I say, old chap, would you mind terribly letting a = b. Thanks awfully.
|
|
|
|
 |
|
 |
I think the last time I used a Gosub/Return was either on a Commodore 64, or maybe on VAX/VMS BASIC... either way, it was mid '80s....
In this day and age, even with VBA in mind, there is no reason to use that pair of keywords.
Tim
|
|
|
|
 |
|
 |
If Something() Then lblpnl10(1).Caption = GetCaptionText(10977, lblpnl10(1).Caption) lblpnl10(0).Caption = GetCaptionText(10978, lblpnl10(0).Caption) frapnl10(0).Caption = GetCaptionText(10979, frapnl10(0).Caption) chkKeepOrigRadioName.Caption = GetCaptionText(10980, chkKeepOrigRadioName.Caption) lblpnl03(14).Caption = GetCaptionText(10981, lblpnl03(14).Caption) lblpnl03(13).Caption = GetCaptionText(10982, lblpnl03(13).Caption) Frame12.Caption = GetCaptionText(10983, Frame12.Caption) Label13.Caption = GetCaptionText(10984, Label13.Caption) Label5.Caption = GetCaptionText(10985, Label5.Caption) Label14.Caption = GetCaptionText(10986, Label14.Caption) Frame9.Caption = GetCaptionText(10987, Frame9.Caption) chkLogLateShiftEnd.Caption = GetCaptionText(10988, chkLogLateShiftEnd.Caption) ....48 more End If
|
|
|
|
 |
|
 |
you should order those statements alphabetically; that improves maintainability.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
 |
|
 |
Wow, this guy knows nothing, look at all those magic numbers, how are you meant to know what they mean?
Const Number1 As Int32 = 0 Const Number2 As Int32 = 1 Const Number3 As Int32 = 13 Const Number4 As Int32 = 14 Const Number5 As Int32 = 10977 Const Number6 As Int32 = 10978 Const Number7 As Int32 = 10979 Const Number8 As Int32 = 10980 Const Number9 As Int32 = 10981 Const Number10 As Int32 = 10982 Const Number11 As Int32 = 10983 Const Number12 As Int32 = 10984 Const Number13 As Int32 = 10985 Const Number14 As Int32 = 10986 Const Number15 As Int32 = 10987 Const Number16 As Int32 = 10988
If Something() Then chkLogLateShiftEnd.Caption = GetCaptionText(Number16, chkLogLateShiftEnd.Caption) chkKeepOrigRadioName.Caption = GetCaptionText(Number8, chkKeepOrigRadioName.Caption) Frame9.Caption = GetCaptionText(Number15, Frame9.Caption) Frame12.Caption = GetCaptionText(Number11, Frame12.Caption) frapnl10(Number1).Caption = GetCaptionText(Number7, frapnl10(Number1).Caption) Label13.Caption = GetCaptionText(Number12, Label13.Caption) Label14.Caption = GetCaptionText(Number14, Label14.Caption) Label5.Caption = GetCaptionText(Number13, Label5.Caption) lblpnl03(Number4).Caption = GetCaptionText(Number9, lblpnl03(Number4).Caption) lblpnl03(Number3).Caption = GetCaptionText(Number10, lblpnl03(Number3).Caption) lblpnl10(Number2).Caption = GetCaptionText(Number5, lblpnl10(Number2).Caption) lblpnl10(Number1).Caption = GetCaptionText(Number6, lblpnl10(Number1).Caption) End If
FTFY (Yes, it is a slow day at work)
CCC solved so far: 2 (including a Hard One!) 37!?!! - Randall, Clerks
|
|
|
|
 |
|
 |
and they say it's hard to improve upon perfection...
|
|
|
|
 |
|
 |
I used to work with a framework that lived off of that. Piles of magic numbers, created by a mechanical engineer of course.
Worked well enough so long as you had the right spreadsheets printed out and wallpapered your cube with them, I assume you have no such spread sheets.
|
|
|
|
 |
|
 |
Didn't they give you the secret decoder ring? 
|
|
|
|
 |
|
 |
It looks like the coder had asked "how to storr datas inside from classes plz help its urgent" on some forum but nobody answered him, so he/she put app data in invisible areas of caption texts. If it is true then try
lblpnl10(0).AutoSize = True  Greetings - Jacek
|
|
|
|
 |
|
 |
We had a contract programmer do some work for us recently. Alas, he was hired by the Pointy Haired One, so this month I get to go over his work and correct errors. Among the steaming pile, I found this nugget:
RunTSMenuItem.Enabled = CBool(IIf(MyUser.HasPermission(Permission.Admin), True, False)) When a user logs into the application, an instance of MyUser is created with all of the user's permissions (among other data.) HasPermission(Permission.whatever) will return true if the user has the requested permission and false otherwise. The above code activates a menu item on a form if the user is an administrator, otherwise the menu item is inactive.
Unfortunately, this guy was overly fond of IIf and used it every opportunity he could, whether needed or not.
|
|
|
|
 |
|
 |
That's a mighty nice turd you found there
|
|
|
|
 |
|
 |
I'm converting an MS Access app to C# & SQL Server. Here's part of an Access query I just came across:
IIf(TX.TX_TYPE="R", IIf(TX.TX_MOSTYPE="P", IIf(TX.TX_DEST_STATUS="A","PO Receipt", IIf(TX.TX_DEST_STATUS="U","PO Receipt Hold","Other")), IIf(TX.TX_DEST_STATUS="A","WIP Receipt", IIf(TX.TX_DEST_STATUS="U","WIP Hold","Other"))), IIf(TX.TX_TYPE="I",IIf(ISNULL(RTRIM(TX.TX_MOSJOB)) Or RTRIM(TX.TX_MOSJOB)="","Shipment Return","Reverse Issue"), IIf(TX.TX_ORIGIN_STATUS=TX.TX_DEST_STATUS,"Loc Transfer", IIf(TX.TX_ORIGIN="SCRAPPED","Reverse Scrap", IIf(TX.TX_ORIGIN_STATUS="J","Count Adj Up", IIf(TX.TX_ORIGIN_STATUS="D","PN Change To", IIf(TX.TX_ORIGIN_STATUS="I","Reverse Unplanned Issue", IIf(TX.TX_ORIGIN_STATUS="A" And TX.TX_DEST_STATUS="U","Hold", IIf(TX.TX_ORIGIN_STATUS="U" And TX.TX_DEST_STATUS="A","Off Hold","Other"))))))))) AS [Transaction Type]
You'll notice that TX.TX_DEST_STATUS="A" is being evaluated more than once.
Go figure
Everything makes sense in someone's mind
moved on Thursday, January 28, 2010 7:54 AM
|
|
|
|
 |