Link to home
Start Free TrialLog in
Avatar of Richard
RichardFlag for United States of America

asked on

Value changes in InitializeComponent VB2008 Express

I have a block of code in the InitializeComponent module of the designer.  At the start of the module is:
    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
My problem is that the values for a couple of items are not correct and cause an error to be generated.  If i manually change the values to be appropriate, everything works OK,  but if I save the project and reload it the values are back to the inappropriate values.  How can I initialize a value.  Both ClickRate and SetTime are defined in a separate class.  The InitilizeComponent module tries to initialize the ClickRate to 0 and the SetTime to 129600000.  I get an error Value 0 is not valid for SelectedIndex, and an error of Arithmetic operation resulted in an overflow for the SetTime.
Any ideas?
Thanks in advance.

Property ClickRate() As Double
        Get
            If lbRate1.SelectedIndex >= 0 Then
                Return dClickRate(lbRate1.SelectedIndex)
            Else
                Return 0
            End If
        End Get

    Property SetTime() As Double
        Get
            Return CDbl(Timer1.Interval)
        End Get
        Set(ByVal value As Double)                          ' Value is in Minutes - convert to miliseconds
            Timer1.Interval = CInt(value * 1000 * 60)
            Timer1.Enabled = True
            Timer1.Stop()
        End Set
    End Property
        Set(ByVal value As Double)
            lbRate1.SelectedIndex = CInt(value)
        End Set
    End Property

Open in new window

Avatar of kaufmed
kaufmed
Flag of United States of America image

Well you've already seen the message... It should be a glaring indicator as to why your values are changing. The Designer.vb file (and implicitly the InitializeComponent() method) are created for you by the IDE. Any changes you make to it will be overwritten the next time you resize the form, move or add a control, change a property or do anything else in the design window. Any properties which require initializing should be available to you in the Properties window (F4) on the designer screen.
Untitled.jpg
Avatar of Richard

ASKER

I know why the values change.  The issue is why aren't the set (by the designer) to valid values?  It is obvious from the code that the first error comes about when the listbox selection index is referenced before the listbox is populated (in the form load event).  The second error is caused by the designer attempting to set the time value of a timer to an invalid value.  In the properties of the timer, the Interval value is 100.  There is no property to set for the list index in a listbox.  One could populate the listbox in the Property window, but I need to fill it with values unknown at design time.

ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Richard

ASKER

Hi kaufmed,
your idea worked like a charm.  I also did a similar thing for the timer error - I tested the value and pitched it if it was greater than 10000.
Thanks for your help!