Stuff that value in there or how not to process a webform.



  • <FONT color=#008000 size=2>

    Reinventing the wheel and More!!!!!!!!!!!!!!  This I found used to mash together values from webcontrols and then to take the resulting value and store that in the database.  This was so unnecessary. And I am so glad we don't write apps in VB anymore.</FONT>

    <FONT color=#0000ff size=2></FONT>

    <FONT color=#0000ff size=2>'*************************************************************
    '*************************************************************
    '***This Class Handles bit level flags. allowing you to    ***
    '***Access individual bits within a variable               ***
    '*** You can check the status and modify the bit pattern   ***
    '***                                                       ***
    '*** Use with care and remember that modifying a single    ***
    '*** bit WILL drastically alter the value of any variable  ***
    '*************************************************************
    '*************************************************************</FONT>

    <FONT color=#0000ff size=2>''' -----------------------------------------------------------------------------
    ''' Project  : internet_live
    ''' Class  : BitProcessor
    '''
    ''' -----------------------------------------------------------------------------
    ''' <summary>
    ''' Provides a way to work with individual bits as flags
    ''' </summary>
    ''' <remarks>
    ''' This Class Handles bit level flags. allowing you to
    ''' Access individual bits within a variable You can check
    ''' the status and modify the bit itself. Use with care and
    ''' remember that modifying a single bit WILL drastically alter
    ''' the value of any variable
    ''' </remarks>
    ''' -----------------------------------------------------------------------------
    Public Class BitProcessor</FONT>

    <FONT color=#0000ff size=2>    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        '' Fields - Implementation variables
        ''
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''</FONT>

    <FONT color=#0000ff size=2>    ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' Integer count for error checking
        ''' </summary>
        ''' <remarks>
        ''' Because the bitproccessor can only handle 32 bits it is important to make sure
        ''' that we do not run over.
        ''' </remarks>
        ''' -----------------------------------------------------------------------------
        Private _index As Integer = 0 'mind the underscore at the beginning</FONT>

    <FONT color=#0000ff size=2>    ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' The value whose bits to check/modify
        ''' </summary>
        ''' <remarks>
        ''' This variable holds the value associated with the MyByte property
        ''' </remarks>
        ''' -----------------------------------------------------------------------------
        Private _MyByte32Bit As Integer = 0 'This is our control byte 32 bits of pseudo unsigned goodness woot!</FONT>

    <FONT color=#0000ff size=2>    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        '' Properties                                         ''
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Public Property index() As Integer
            Get
                Return _index
            End Get
            Set(ByVal Value As Integer)
                If Value < 32 And Value >= 0 Then
                    _index = Value
                End If
            End Set
        End Property</FONT>

    <FONT color=#0000ff size=2>
        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' an Indexed boolean property that allows access to the individual bits
        ''' </summary>
        ''' <param name="index"></param>
        ''' <value></value>
        ''' <remarks>
        ''' This property applies a mask to the bits of our value
        ''' to either set, unset or read the bit value.
        ''' The bit mask used is 1<<index where index is the bit number to check/modify
        '''
        ''' The Bit Mask is used in conjunction with the following logical algorithms.
        '''
        ''' Check bit: MyByte AND mask
        ''' SET Bit:  MyByte OR mask
        ''' UnSET Bit:  MyByte AND  (Not mask)
        '''
        ''' <James brown voice>Hoouugh HA. I'ma bit machine...Houuughh!</James brown voice>
        ''' </remarks>
        ''' -----------------------------------------------------------------------------
        Default Public Property Bits(ByVal index As Integer) As Boolean
            Get
                If (index <= 31 And (index >= 0)) Then
                    'lets check our bit
                    Dim mask As Integer = (1 << index) 'set our mask
                    If (_MyByte32Bit And mask) = False Then
                        Return False
                    Else
                        Return True
                    End If
                Else
                    'our bit index is out of range so Crash and Burn baby!!!
                    Throw New HttpException(9002, "Bit Proccessor encountered an error: Bits Index out of range", 9002)
                    'Err.Raise(9002, "BitProccessor", "Bit Index out of range")
                End If
            End Get
            Set(ByVal Value As Boolean)
                Dim mask As Integer = (1 << index)  'set our mask
                If Value Then 'we set the bit
                    _MyByte32Bit = _MyByte32Bit Or mask
                Else 'lets unset (rape) the bit
                    _MyByte32Bit = _MyByte32Bit And (Not mask)
                End If
            End Set
        End Property</FONT>

    <FONT color=#0000ff size=2>    ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' Provides access to the to a 32 Byte Integer to work with
        ''' </summary>
        ''' <value></value>
        ''' <remarks>
        ''' The above sums it up
        ''' </remarks>
        '''---------------------------------------------------------------
        Public Property MyByte() As Integer
            Get
                Return _MyByte32Bit
            End Get
            Set(ByVal Value As Integer)
                _MyByte32Bit = Value
            End Set
        End Property</FONT>

    <FONT color=#0000ff size=2>    ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' Creates a bitpattern from a checkbox/checkboxlist,radiobutton,radiobuttonlist control.
        ''' </summary>
        ''' <param name="myControl">A webControl to make a bit pattern from</param>
        ''' <returns>a string containing the type name of the control.</returns>
        ''' <remarks>
        ''' </remarks>
        ''' -----------------------------------------------------------------------------
        Public Function addControlValues(ByRef myControl As WebControl) As String
            Dim strControlType As String
            strControlType = myControl.GetType.Name().ToLower</FONT>

    <FONT color=#0000ff size=2>        Select Case strControlType
                Case "checkboxlist"
                    'run checkboxlist function
                    addCheckboxList(myControl)
                Case "checkbox"
                    'run checkbox function
                    addCheckbox(myControl)
                Case "radiobuttonlist"
                    'run checkboxlist function
                    addRadioButtonList(myControl)
                Case "radiobutton"
                    'run checkbox function
                    addRadioButton(myControl)
            End Select
            Return strControlType
        End Function</FONT>

    <FONT color=#0000ff size=2>    ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' Adds a checkbox to the bit pattern
        ''' </summary>
        ''' <param name="myControl">a checkbox control whose value to add</param>
        ''' <remarks>
        ''' nope
        ''' </remarks>
        ''' -----------------------------------------------------------------------------
        Private Sub addCheckbox(ByRef myControl As CheckBox)
            If _index <> 32 Then
                If myControl.Checked Then
                    Bits(_index) = True
                Else
                    Bits(_index) = False
                End If
                _index += 1
            Else
                Throw New HttpException("Bit Processor Index out of range")
            End If
        End Sub</FONT>

    <FONT color=#0000ff size=2>    ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' Adds a checkboxlist to the bit pattern
        ''' </summary>
        ''' <param name="myControl">a checkboxlist control whose value to add</param>
        ''' <remarks>
        ''' nope
        ''' </remarks>
        ''' -----------------------------------------------------------------------------
        Private Sub addCheckboxList(ByRef myControl As CheckBoxList)
            Dim myItem As ListItem</FONT>

    <FONT color=#0000ff size=2>        If (_index + myControl.Items.Count) < 32 Then
                For Each myItem In myControl.Items
                    'set me?
                    If myItem.Selected = True Then
                        Bits(_index) = True 'Victory is MINE!
                    Else
                        'nahh another time perhaps
                        Bits(_index) = False
                    End If
                    _index += 1 'increment by 1
                Next
            End If
        End Sub</FONT>

    <FONT color=#0000ff size=2>    ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' Adds a radiobutton to the bit pattern
        ''' </summary>
        ''' <param name="myControl">a radiobutton control whose value to add</param>
        ''' <remarks>
        ''' nope
        ''' </remarks>
        ''' -----------------------------------------------------------------------------
        Private Sub addRadioButton(ByRef myControl As RadioButton)
            If _index <> 32 Then
                If myControl.Checked Then
                    Bits(_index) = True
                Else
                    Bits(_index) = False
                End If ' VAAAAGIIIIINA!!!!!!!!
                _index += 1
            Else
                Throw New HttpException("Bit Processor Index out of range")
            End If
        End Sub</FONT>

    <FONT color=#0000ff size=2>    ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' Adds a radiobuttonlist to the bit pattern
        ''' </summary>
        ''' <param name="myControl">a radiobuttonlist control whose value to add</param>
        ''' <remarks>
        ''' nope
        ''' </remarks>
        ''' -----------------------------------------------------------------------------
        Private Sub addRadioButtonList(ByRef myControl As RadioButtonList)
            Dim myItem As ListItem</FONT>

    <FONT color=#0000ff size=2>        If (_index + myControl.Items.Count) < 32 Then
                For Each myItem In myControl.Items
                    'set me?
                    If myItem.Selected = True Then
                        Bits(_index) = True 'Victory is MINE!
                    Else
                        'nahh another time perhaps
                        Bits(_index) = False
                    End If
                    _index += 1 'increment by 1
                Next
            End If
        End Sub
    End Class

    </FONT>


  •  The comments alone - pass the goggles



  • There are some gems in the comments.  James brown and the one about raping bits.



  • I really, really hope those <summary> <remarks> tags are some kind of joke, and don't actually mean someone did an XMLized version of JavaDoc. Though that James Brown voice is a gem in itself!

    @galgorah said:

    <font color="#008000" size="2">And I am so glad we don't write apps in VB anymore.
    I'm really glad I haven't had to touch VB since college. </font>



  • @danixdefcon5 said:

    I really, really hope those <summary> <remarks> tags are some kind of joke, and don't actually mean someone did an XMLized version of JavaDoc.

    <remarks>

    yup

    </remarks>


  • @danixdefcon5 said:

    I really, really hope those <summary> <remarks> tags are some kind
    of joke, and don't actually mean someone did an XMLized version of JavaDoc.

    Believe it or not, but they're actually called XML comments.

    My favourite part for some reason is that it throws HttpException... Also, what's up with all the [color=blue]blue[/color]?



  • @Helix said:

     The comments alone - pass the goggles

     

    I find it's easier to read if you copy/paste into a source code editor.



  • @danixdefcon5 said:

    I really, really hope those <summary> <remarks> tags are some kind of joke, and don't actually mean someone did an XMLized version of JavaDoc. Though that James Brown voice is a gem in itself!

     

    Nope, they're valid XML comments (for example in VB.NET or C#). You can use them to generate XML documentation files which will be used by Visual Studio to show inline help for class members. Also, you can automatically generate MSDN-like documentation from these comments.



  • @MiffTheFox said:

    @Helix said:

     The comments alone - pass the goggles

     

    I find it's easier to read if you copy/paste into a source code editor.

     

    you must be new here


Log in to reply