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

TopCatOnyxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ǩa̹̼͍̓̂ͪͤͭ̓u͈̳̟͕̬ͩ͂̌͌̾̀ͪf̭̤͉̅̋͛͂̓͛̈m̩̘̱̃e͙̳͊̑̂ͦ̌ͯ̚d͋̋ͧ̑ͯ͛̉Commented:
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
TopCatOnyxAuthor Commented:
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.

ǩa̹̼͍̓̂ͪͤͭ̓u͈̳̟͕̬ͩ͂̌͌̾̀ͪf̭̤͉̅̋͛͂̓͛̈m̩̘̱̃e͙̳͊̑̂ͦ̌ͯ̚d͋̋ͧ̑ͯ͛̉Commented:
The "Value 0 is not valid for SelectedIndex" error is due to your setter where you wrote

    lbRate1.SelectedIndex = CInt(value)

It seems the designer passes 0 as a default value to the setter during runtime. This is easily overcome as demonstrated below.

As for you arithmetic overflow, you say it is passing 129600000 as the initial value. When you multiply this by 60000, you overflow the bounds of an integer variable. I can't seem to reproduce this error without manually setting SetTime in the designer to 129600000.
Set(ByVal value As Double)
    If lbRate1.Items.Count > 0 Then
        lbRate1.SelectedIndex = CInt(value)
    Else
        lbRate1.SelectedIndex = -1
    End If
End Set

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TopCatOnyxAuthor Commented:
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!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.