Outsourced Conversion



  • I got a bug report today about a self-resizing multi-line textbox that was sizing itself so the last line wasn't visible.  I looked at the code that calculates the height and found this:

    Dim i, j As Integer
    txtHolds.Height = 68
    txtHolds.Text = NewText
    i = InStr(NewText, vbCrLf)
    If i * 2 > 10 Then
        txtHolds.Height = VB6.TwipsToPixelsY(txtHolds.Height + ((i * 2) - 1) * 145) - 5
    End If

    I thought, well there's the problem.  I actually wonder how this ever worked, but it's been in production for two years and the form is used quite a bit.

    This code was converted from VB6 to VB.Net a few years back.  We outsourced the job and had asked that no functionality be changed, just make the app work in .Net.  I assumed this was an upgrade bug due to the fact that VB6 used a twip based coordinate system and .Net uses a pixel based coordinate system.  So, I go back to the VB6 version (fully expecting to find a VB6 atrocity) and I find this:

    txtHolds.Text = NewText
    txtHolds.Height = TextHeight(NewText) * 1.25

    Holy Crap!!!  How did they get from there to the current code?



  • So when the first crlf is before position 6, the height is 68, when it occurs later it adds 68 to 290 times the position in the string minus 145, converts that number with some call and subtracts 5 and makes it the new height? Weird, very weird. That would work in very specific circumstances only. I can only imagine that the programmer took the two test cases where crlf occurs after position 5, and fitted a linear function on InStr(NewText, vbCrLF) to yield the same value as the original function. No functionality changed in a very, er, inventive way.



  • @Jaime said:

    Holy Crap!!!  How did they get from there to the current code?
    Not sure, but cannabis indica is one of the sacred plants of India.  I'd start my investigation there.



  • @TGV said:

    So when the first crlf is before position 6, the height is 68, when it occurs later it adds 68 to 290 times the position in the string minus 145, converts that number with some call and subtracts 5 and makes it the new height? Weird, very weird. That would work in very specific circumstances only. I can only imagine that the programmer took the two test cases where crlf occurs after position 5, and fitted a linear function on InStr(NewText, vbCrLF) to yield the same value as the original function. No functionality changed in a very, er, inventive way.
    I don't think the programmer went that far.  The first line of the text is always 11 characters long.  The call to VB6.TwipsToPixelsY converts from VB6's twip based coordinate system to .Net's pixel based coordinate system, and is common in upgraded code -- it has absolutely no place in new code.

    The only explanation I can think of is that the programmer found somebody else's (bad) code for a dynamic width text box and kept randomly changing it until it worked almost right.



  • @Jaime said:

    The only explanation I can think of is that the programmer found somebody else's (bad) code for a dynamic width text box and kept randomly changing it until it worked almost right.
    I think this describes 90%* of development done today...

    * - number pulled directly from my ass



  • @C-Octothorpe said:

    I think this describes 90%* of development done today...

    * - number pulled directly from my ass

     Seems like you have a very accurate ass...



  • @C-Octothorpe said:

    I think this describes 90%* of development done today...

    * - number pulled directly from my ass

     Seems like you have a very accurate ass...



  • @C-Octothorpe said:

    @Jaime said:

    The only explanation I can think of is that the programmer found somebody else's (bad) code for a dynamic width text box and kept randomly changing it until it worked almost right.
    I think this describes 90%* of development done today...

    * - number pulled directly from my ass

     

    90% doesn't work. I trtry 89% and 91%. Can you send me teh percent?


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.