Problem with module and form load slow
Hi guys
I have a problem with my form and module, I have created hundred of thousands lines of the code that are stored on module. I placed the name of the title on module for my form to read on but I cannot understand why it take ages for my form to reload, are there a way that I can make them display quickly??
Let me know if possible and I'm looking forward to work on it.
Thanks,
Mark
Re: Problem with module and form load slow
Reasons for a slow Form Load:
* Loading info from a file - Aggrivated if a networked location.
* Long repetitive loops. (ie 10000 + iterations)
* DataBase access - SQL or Access, the More data and tables the longer.
* Unplanned Recursion. (Many ways for this to happen)
* Bad Code....... (not that your a bad programmer)
* waiting for responce from external Unit . (Serialport, USB, Printer)
* Populating Listboxes, Comboboxes from external data.
These are only the main reasons, there are many more. Dbl check all of the above items if you are using them in your form....
Otherwise post some code so that we can look over it for you...
Gremmy...
Re: Problem with module and form load slow
post the code of your load and/or activated events in the form.
1 Attachment(s)
Re: Problem with module and form load slow
Code:
Private Sub Testbox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Testbox.TextChanged
If Me.Testbox.Text = "0" Then
Me.TrackBar2.Value = "0"
End If
If Me.Testbox.Text = 1 Then
Me.TrackBar2.Value = 1
End If
If Me.Testbox.Text = 2 Then
Me.TrackBar2.Value = 2
End If
If Me.Testbox.Text = 3 Then
Me.TrackBar2.Value = 3
End If
If Me.Testbox.Text = 4 Then
Me.TrackBar2.Value = 4
End If
If Me.Testbox.Text = 5 Then
Me.TrackBar2.Value = 5
End If
If Me.Testbox.Text = 6 Then
Me.TrackBar2.Value = 6
End If
If Me.Testbox.Text = 7 Then
Me.TrackBar2.Value = 7
End If
If Me.Testbox.Text = 8 Then
Me.TrackBar2.Value = 8
End If
If Me.Testbox.Text = 9 Then
Me.TrackBar2.Value = 9
End If
Test1()
End Sub
I have included the attachment for Test1(), it has 2000 lines of the code which and when I type the number of value from 0 to 1,091. I need to them part of my form so are there any other situations that I can reload my form quickly without the needs to run of those 2000 lines of code??
I have put the 2000 lines code on module but it hasn't solve it.
Thanks,
Mark
Re: Problem with module and form load slow
Wow for the small snippet i think we have some serious trouble with your code.
Ill download it later and try to analyze it slowly to help you.
Re: Problem with module and form load slow
Well just saw the code.
Its 35568 lines long.
And its all hardcoded. Sorry I dont have so much time to analyze this.
But the issue is obvius. You are executing 35568 lines of code when opening your form.
You should really review your code, and consider a select case, a formula or something.
Re: Problem with module and form load slow
Yeah, that's the longest work I have ever deals with. The main problem is I don't have any experience how I could executive and make my form run quicker, this is the first time I have deals with in my life. Hopefully one of you can advise me what to do then I can solve it myself if I have to cut the code and paste on other module in order that would help the form to run quicker without the needs to read hundred lines of the codes??
Plz let me know what I will have to do.
Thanks guys :)
Re: Problem with module and form load slow
I can cut the HUGH module down to less than 10 lines .....
Firstly .. when everything is so sequential ... why are you checking one for one .... use range checking...
About 3/4 of this can be replaced with just
Code:
If Val(Form2.Testbox.Text) > Val(Form2.Testing.SelectedItem) Then
Form2.Testbox.Text = Cstr(Form2.Testing.SelectedItem)
End If
and the rest of it is replaced with..
Code:
If Val(Form2.Testbox.Text) < 10 Then
Form2.Testbox.Text = "10"
End If
Thats six lines of code to do what your doing in Thousands of lines...
Replace the Module and the section of code you have above with just these six lines, and test your application again...
Gremmy....
Re: Problem with module and form load slow
Oooops wait .. one more to add to this .. I only noticed now that the code in the post is different to the module...
the code on the post can be replaced with ..
Code:
If val(Me.Testbox.Text) <=9 Then
Me.TrackBar2.Value = val(Me.Testbox.Text)
End If
So thats a total of 9 lines of code....
Gremmy...
Re: Problem with module and form load slow
Thanks gremmy. I was too busy to do that myself.
I still wonder what the heck are all those crazy numbers
Re: Problem with module and form load slow
Quote:
Originally Posted by Havok
Thanks gremmy. I was too busy to do that myself.
I still wonder what the heck are all those crazy numbers
It's probably limiting some reference input value according to a listitem and sliderbar..
I still want to know how long it took to type out all those If-Then statements.... :D
Gremmy....
Re: Problem with module and form load slow
Thanks for the help, you have now saved my time! What about writing the value if the large numbers is bigger than the smaller numbers, something would be looks like this:
Code:
If Val(Options1.Textbox.Text = "33") >= 32 Then
Testbox.ShowDialog()
End If
I know that > is bigger than the smaller numbers, I tried to input > on my form but it hasn't working properly yet.
Thanks,
Mark
Re: Problem with module and form load slow
the correct method whould be more alongs the lines of
Code:
If Val(Options1.Textbox.Text) >= 32 Then
Testbox.ShowDialog()
End If
the syntax is
IF [Object] < / = / > / >= / <= [Object] THEN
where object can be a variable or value..
< : Less than
> : Greater than
= : Equal
<= : Less than or equal
>= : Greater than or equal
Can i just ask, how long have you been programming for ????
Gremmy....
Re: Problem with module and form load slow
Thanks, but the methods is still incorrect. When I type the text "33" on the Testbox large than 32, i have received an error:
Value of '33' is not valid for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'.
It got nothing to do with the maximum when I type the large numbers. Normally it should appear the dialog when I type the large numbers on the testbox. Why do I have received an error, something need to get it right??
Thanks,
Mark
P.S I have been programming for around 2 years so why do you ask? :D
Re: Problem with module and form load slow