-
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
-
Re: Problem with module and form load slow
Because nobody else would type 30000 lines rather than 10. :)
Code:
If Val(Options1.Textbox.Text) >= 32 Then
Testbox.ShowDialog()
End If
You enter 33 into the textbox, which IS greater than 32, so you get the message. That is what you wanted?
-
Re: Problem with module and form load slow
Yes but the main problem is when I type 33 on the textbox, it should be displaying the messagebox but I have received an error:
Value of '65' is not valid for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'.
The maximum number is only 32 for trackbar, I wanted the textbox to check if I go over the limit numbers of value on trackbar and display straight away if I go over the limit numbers??
Hope you can help.
Thanks,
Mark
-
Re: Problem with module and form load slow
Did you mark the textbox to be VALIDATE(d)? It won't let you exit with the wrong numbers? That's where you need to change the message, if you don't like it.
Usually validation is all that's required. They won't be able to enter anything higher than Maximum
-
Re: Problem with module and form load slow
No I haven't, so how I can change the textbox to be validate??
Thanks,
Mark
-
Re: Problem with module and form load slow
search for that exact error message to find where it's being called.
where did you get the textbox code? it must have a validate event somewhere.
again, search for it.
-
Re: Problem with module and form load slow
-
Re: Problem with module and form load slow
-
Re: Problem with module and form load slow
Can you explain what it is your module is meant to be doing (one paragraph will be fine, not 35,000)? If we could understand what you were doing then we can better understand how to help you and reduce the size of that horrendous chunk of code you have there and maybe even teach your a few coding best practices along the way. ;)
-
Re: Problem with module and form load slow
@Oblio: Will you please stop posting any spams that I have received from you. Read the forum rules and if you continue to spam then you will be banned. Just post the info to this forum which it much welcome. Simple as that.
@visualAd: Well on my method they are doing to move the value from 0 to 32 when I type on the textbox so from 33 to any of the highest value I wanted to receive the messagebox when I type the high numbers on the textbox but I have received an error for the same reasons. I tried to use this code but it didn't solve it correctly
Code:
If Val(Form2.Textbox.Text = "32") <= 31 Then
Form2.TrackBar2.Value = Val(Form2.Textbox.Text)
ElseIf Val(Form2.Textbox.Text = "33") >= 32 Then
Testbox.ShowDialog()
End If
I know that the trackbar2 has maximum number up to 32 but I would be happy to ignore the code for controlling when I type the highest value just after 32. Hope you guys can help me out and get this problem right away.
Thanks,
Mark
-
Re: Problem with module and form load slow
Quote:
Originally Posted by mark103
@Oblio: Will you please stop posting any spams that I have received from you. Read the forum rules and if you continue to spam then you will be banned. Just post the info to this forum which it much welcome. Simple as that.
@visualAd: Well on my method they are doing to move the value from 0 to 32 when I type on the textbox so from 33 to any of the highest value I wanted to receive the messagebox when I type the high numbers on the textbox but I have received an error for the same reasons. I tried to use this code but it didn't solve it correctly
Code:
If Val(Form2.Textbox.Text = "32") <= 31 Then
Form2.TrackBar2.Value = Val(Form2.Textbox.Text)
ElseIf Val(Form2.Textbox.Text = "33") >= 32 Then
Testbox.ShowDialog()
End If
I know that the trackbar2 has maximum number up to 32 but I would be happy to ignore the code for controlling when I type the highest value just after 32. Hope you guys can help me out and get this problem right away.
Thanks,
Mark
Anyone who uses the Val function needs to be shot. Use the Integer.Parse / Float.Parse functions.
Now after reading your previous post it looks like you are still describing the problem. We know that you have a problem, however, in order to help you solve the problem we need to understand what you are trying to achieve. Forget about the code you have posted so far (delete it for all I care - just don't post it again :D) and tell us what the code is doing. Even better, if it is related to a real world scenario tell us what it is because there is probably already an algorithm out there that works well and even if there is not it will help us to understand.
-
Re: Problem with module and form load slow
Quote:
Originally Posted by mark103
@Oblio: Will you please stop posting any spams that I have received from you. Read the forum rules and if you continue to spam then you will be banned. Just post the info to this forum which it much welcome. Simple as that.
Leave the hiring and firing to HR and just concentrate on not getting banned from this forum too ;)
-
Re: Problem with module and form load slow
Quote:
Originally Posted by visualAd
Anyone who uses the Val function needs to be shot. Use the Integer.Parse / Float.Parse functions.
That's a little harsh. Yes VAL is a vb6 function but it still works in .NET. And yes he should use the .parse or possibly ctype. No need to be rude about it.
In this code...
Code:
If Val(Form2.Textbox.Text = "32") <= 31 Then
Form2.TrackBar2.Value = Val(Form2.Textbox.Text)
ElseIf Val(Form2.Textbox.Text = "33") >= 32 Then
Testbox.ShowDialog()
End If
...I don't think it is doing what you think it is. And I am not sure how the VAL function would do this, however, I think it would be parsed like this.
Does " Form2.Textbox.Text = "32" " If the answer is yes, take the val of true which would equal 1. If no, take the val of false which should be 0. Either case would then be less than or equal to 31 and you will always try to set the value of the trackbar to whatever the value is in form2.textbox.text. I think what you are looking for is something like this.
Code:
If CType(Form2.Textbox.Text, Integer) <= 31 Then
Form2.TrackBar2.Value = CType(Form2.Textbox.Text,Integer)
Else
Testbox.ShowDialog()
End If
-
Re: Problem with module and form load slow
Quote:
Originally Posted by sotoasty
That's a little harsh.....
Sorry, I should have added a face to the end of that. Yes Val is in VB6 however I would generally stay away from it then, unless you generally do not know the data type of the data which will be entered.
Anyhow rest assured I did not intend to be rude. May be I should rephrase "using VAL is shooting yourself in the foot" ;) :wave:
-
Re: Problem with module and form load slow
Code:
Dim tbVAL As Integer = 0
If Integer.TryParse(TextBox1.Text, tbVAL) Then
If tbVAL >= 0 AndAlso tbVAL <= 32 Then TrackBar1.Value = tbVAL Else TrackBar1.Value = TrackBar1.Maximum
Else
MessageBox.Show("Numbers Only Please")
End If
@mark, please don't tell me what to do. i posted those links so people would see what they are dealing with. i don't mean this in a mean way, but you need an intro to visual basic programming class.
e.g. What do you think this means
If Val(Form2.Textbox.Text = "32") <= 31
Did you understand the explanation?
@sotoasty - in one thread at MSDN mark103 told someone they were a f'ing c*nt. i am beginning to believe this is a joke.
-
Re: Problem with module and form load slow
Oblio - turn on your PM's
-
Re: Problem with module and form load slow
Quote:
Originally Posted by dglienna
Oblio - turn on your PM's
done
-
Re: Problem with module and form load slow
Quote:
Originally Posted by visualAd
Anyone who uses the Val function needs to be shot. Use the Integer.Parse / Float.Parse functions.
So shoot me ;) .. I often forget if i'm posting in VB6 or .NET ... I've been programming VB(4/5/6) for so long i'm stuck in those methods.. I'm still picking up the .NET way .... please give me a break... ;)
The correct method should have been
Code:
If Cint(Form2.Textbox.Text) <= 31 Then
'---------------
End If
@Mark .. Bdl check what line is throwing that error.. then also what min and max values have you set for the Trackbar ???
-
Re: Problem with module and form load slow
He isn't getting ANY msgbox error, there is some code elsewhere that is throwing that particular error, and it was program generated as well. Search for it, or paste the whole program and someone else will
-
Re: Problem with module and form load slow
It is okay for now guys, thanks for the help! But I have a problem, when I type the number '1' on the textbox, it reaction the first number on the value of the trackbar2 but when I type '1.0' on the textbox which the trackbar2 value should reaction 1001 but it stay on the first value of the trackbar!!!!!!!!
How can I get this to solve??
Thanks,
Mark
-
Re: Problem with module and form load slow
Quote:
Originally Posted by mark103
It is okay for now guys, thanks for the help! But I have a problem, when I type the number '1' on the textbox, it reaction the first number on the value of the trackbar2 but when I type '1.0' on the textbox which the trackbar2 value should reaction 1001 but it stay on the first value of the trackbar!!!!!!!!How can I get this to solve??
Thanks,
Mark
Is this what you are saying - If the textbox has 1 in it then the trackbar.value should be 1, if it has 1.0 the trackbar.value should be 1001?
Does 1 = 1.0?
-
Re: Problem with module and form load slow
Yes that is what I am trying to do, and no 1 is not 1.0. I only want the textbox with 1 that trackbar.value should be 1 and I want to show 1.0 on the textbox which the trackbar.value should be 1001.
I tried this
Code:
If Val(Form2.Textbox.Text) = "1.0" Then
Form2.Trackbar.Value = "1001"
End If
If Val(Form2.Textbox.Text) = "1" Then
Form2.Trackbar.Value = "1"
It didn't work. It shows '1' as value on 1001 on trackbar. It should be on value 1. Hope you can help.
Thanks,
Mark
Quote:
Originally Posted by Oblio
Is this what you are saying - If the textbox has 1 in it then the trackbar.value should be 1, if it has 1.0 the trackbar.value should be 1001?
-
Re: Problem with module and form load slow
Hint -> Does the Val function return a string? How does VB treat a number in quote marks?
Hint 2 -> Tutorial
You should have this as line #1 of any code your write
Option Strict On
And BTW -
Code:
If 1 = 1.0 Then
Debug.WriteLine("They are equal")
End If
-
Re: Problem with module and form load slow
Thanks, but have a problem again. When I type 1.0 on the textbox, the value on trackbar didn't move to 1000. Do you know why the value didn't move to when I type on the textbox 1.0??
Code:
If 1 = 1 Then
Form2.TrackBar2.Value = 1
End If
If 1.0 = 1000 Then
Form2.TrackBar2.Value = 1000
End If
Hope you can help to get it resolve.
Thanks,
Mark
-
Re: Problem with module and form load slow
Mark,
I think it is about time for you to purchase a beginners programming book. You need to understand about variables and objects and such. Look at your If statements.
"If 1 = 1"
This statement will always be true. 1 will always = 1.
"If 1.0 = 1000"
This will never be true. 1.0 will never equal 1000.
What you need to do is compare the values in your text box object.
May I suggest...
Code:
SELECT CASE Form2.Textbox.Text
Case "1"
Form2.TrackBar2.Value = 1
Case "1.0"
Form2.TrackBar2.Value = 1000
Case Else
MsgBox "Please enter 1 or 1.0 in the textbox"
End Select
-
Re: Problem with module and form load slow
:ehh: OMG
I give up. Please read the tutorial at least.
-
Re: Problem with module and form load slow
Quote:
Originally Posted by mark103
Thanks, but have a problem again. When I type 1.0 on the textbox, the value on trackbar didn't move to 1000. Do you know why the value didn't move to when I type on the textbox 1.0??
Code:
If 1 = 1 Then
Form2.TrackBar2.Value = 1
End If
If 1.0 = 1000 Then
Form2.TrackBar2.Value = 1000
End If
This post has seriously made my day. You should become a part time comedian!
If you are being serious however, invest in a VB.NET book or some book that explains about variables. Or better yet, quit wasting people's time and pursue a career in comedy - You'd be fantastic.
-
Re: Problem with module and form load slow
guys, there is no need to suggestions me to go and buy a VB.Net book. I have been with vb for 3 years which I feel good to learn myself so please be nice, help and friendly :)
Apart from that, I still have trouble with the method. I created a new module, I typed and created the code correctly and get things working around better but if I put Testbox.ShowDialog() on my module and if I type any numbers like let say "666", the trackbar value should move to 666 but I have received Testbox.Showdialog. How I can stop that??
Code:
If Val(Form2.Textbox.Text) <= 1000 Then
Form2.TrackBar2.Value = Val(Form2.Textbox.Text)
End If
If Val(Form2.Textbox.Text) = "1000" Then
Form2.TrackBar2.Value = 1000
End If
If Val(Form2.Textbox.Text) >= "1000" Then
Testbox.Showdialog()
End If
I am not over the limit as the maximum number would allows me to type up to 1000. I don't really understand where they are coming from.
Hope you guys can advise with this troubleshoot.
Thanks,
Mark
-
Re: Problem with module and form load slow
If you call this 3 years of VB, you should give up. You cannot compare a STRING to a NUMBER, and when you say "1000" that is NOT the same as 1000.
"1000" is a STRING
1000 is a NUMBER
VAL("1000") turns it INTO a NUMBER (if it was one)
VAL("X") = 0 (because "X" is not a number)
-
Re: Problem with module and form load slow
it just has to be a joke. 666, come on. smile we are on candid forum, right. no one is this bad.
-
Re: Problem with module and form load slow
BOB5731 had an excuse. Don't know what happened to him...
http://www.vbforums.com/showthread.p...hlight=bob5%2A
-
Re: Problem with module and form load slow
Nearly done guys, I'd find it difficult with this task. When I type the numbers so far it works ok but when I try to move the lowest trackbar value numbers like 999, Testbox.Showdialog() appears to come up everytime.
Here it the code:
Code:
If Val(Form2.Textbox.Text) <= 999 Then
Form2.TrackBar2.Value = Val(Form2.Textbox.Text)
End If
If Form2.Textbox.Text = "1.0" Then
Form2.TrackBar2.Value = 1000
End If
If Form2.Textbox.Text > "1.0" Then
Form2.TrackBar2.Value = 1000
Textbox.ShowDialog()
End If
End If
Please can you tell me how I can fix that?? I don't want to remove Testbox.Showdialog() or anything. I just want to go over the limit of 1.0 in order to show Testbox.Showdialog.
Thanks,
Mark
-
Re: Problem with module and form load slow
Not until you READ THE OTHER POSTS
-
Re: Problem with module and form load slow
See my post on above, I'm having trouble. Nothing to do with old post.
-
Re: Problem with module and form load slow
Quote:
Originally Posted by dglienna
If you call this 3 years of VB, you should give up. You cannot compare a STRING to a NUMBER, and when you say "1000" that is NOT the same as 1000.
"1000" is a STRING
1000 is a NUMBER
VAL("1000") turns it INTO a NUMBER (if it was one)
VAL("X") = 0 (because "X" is not a number)
Don't read old posts? :eek: :sick: :lol:
Help yourself, or ignore the help
-
Re: Problem with module and form load slow
Quote:
Originally Posted by mark103
See my post on above, I'm having trouble. Nothing to do with old post.
Yes, I see exactly what your trouble is. You are lazy .... unfortunately the only person who can solve that problem is you.
Show some evidence of being able to grasp the simple concepts of VB and maybe we will be more willing to help. So far, you have failed to explain the problem adequately and you have failed to take on any advice anyone here has given you unless it has been copy and pastable.