Code efficiency

bones

Well-known member
Joined
Aug 23, 2014
Messages
143
Programming Experience
Beginner
Is there a better, shorter way to write code like this

VB.NET:
Select Case True
            Case CheckBox1.Checked = True
                Me.Chart1.Series(0).Points.Clear()
                Me.Chart1.Series(1).Points.Clear()
                Me.Chart1.Series(2).Points.Clear()
                Me.Chart1.Series(3).Points.Clear()
                Me.Chart1.Series(4).Points.Clear()
                Me.Chart1.Series(5).Points.Clear()

I would like to streamline my app as best I can. The size of it is already getting my attention. It's typical of everything Microsoft anymore....bloated
 
Is there a better, shorter way to write code like this

VB.NET:
Select Case True
            Case CheckBox1.Checked = True
                Me.Chart1.Series(0).Points.Clear()
                Me.Chart1.Series(1).Points.Clear()
                Me.Chart1.Series(2).Points.Clear()
                Me.Chart1.Series(3).Points.Clear()
                Me.Chart1.Series(4).Points.Clear()
                Me.Chart1.Series(5).Points.Clear()

I would like to streamline my app as best I can. The size of it is already getting my attention. It's typical of everything Microsoft anymore....bloated

Um, it's your code, not Microsoft's. If it's bloated then it's your fault, not there's. If you don't know how to write a loop, which is one of the most fundamental programming concepts in existence, then you're going to have trouble writing any decent code. I suggest that you follow the tutorial link in my signature below and read the chapter on loops. The For and For Each loops would be the better options in this case.
 
Um, it's your code, not Microsoft's. If it's bloated then it's your fault, not there's. If you don't know how to write a loop, which is one of the most fundamental programming concepts in existence, then you're going to have trouble writing any decent code. I suggest that you follow the tutorial link in my signature below and read the chapter on loops. The For and For Each loops would be the better options in this case.

I'll have a look at that..thanks for the link. BTW... if MS programmers are so dam efficient, how come everything they write is ENORMOUS :tennis:
And the VB6 guys I've talked to tell me they don't want to switch because the newer versions require more code to get the job done....
 
Last edited:
I'll have a look at that..thanks for the link. BTW... if MS programmers are so dam efficient, how come everything they write is ENORMOUS :tennis:
And the VB6 guys I've talked to tell me they don't want to switch because the newer versions require more code to get the job done....
Ask those VB6 guys to write some multi-threaded code for you and we'll see what requires more code. You don't know what you're talking about and they are misleading you.
 
Ask those VB6 guys to write some multi-threaded code for you and we'll see what requires more code. You don't know what you're talking about and they are misleading you.

Well... both of your statements are debatable but that's neither here nor there... I can assure you I know a pig when I see one and everything MS has a distinct OINK to it... But it is what it is, common, widely accepted and ultimately it's got to be dealt with by learning how to play in the pen... so I'm learning :friendly_wink:

What I see in searching out solutions are numerous ways to approach any given situation. Some guys will give very small, slick solutions and others give very lengthy code solutions. Naturally it depends on the users knowledge of the tools he holds in his hand...

Perfect example if statement - Most Efficient Way To Write This Loop VB.Net - Stack Overflow

From my seat...I would say Jacob knocked the ball clean out of the park with his answer.... short, sweet efficient. I can see a perfect example of how to now go back to my app and apply that solution. LOVE IT
 
Last edited:
Just a personal addendum, but "VB6 guys" that still do VB6 to this day are usually mostly incompetent in any other language. If they weren't they would have switched away from it somewhere in the last 15 years. Now I know some people are just stuck supporting a VB6 app they cannot convert. But the general rule is if they talk dirt about .NET, it's because they don't know the first thing about it.

As for your original code:

For Each s in Me.Chart1.Series
    s.Points.Clear()
Next


Your Select Case statement is all wrong too:

Select Case CheckBox1.Checked
    Case True


But when you have a boolean there is no point to a select case. Just do an If.

If CheckBox1.Checked Then
    For Each s in Me.Chart1.Series
        s.Points.Clear()
    Next
End If
 
Last edited:
Tell me something it's off this topic..sort of. I'm reading another thread on this forum about that code example I pointed for numeric text boxes. Everyone loved it but you...or so I'm gathering from the posts... Does it or does it not work?
 
both of your statements are debatable
Conversely, your statement that everything Microsoft create is enormous and the fact that it takes more code to do the same thing in VB.NET than VB6 are to be taken as incontrovertible gospel.
 
Perfect example if statement - Most Efficient Way To Write This Loop VB.Net - Stack Overflow

From my seat...I would say Jacob knocked the ball clean out of the park with his answer.... short, sweet efficient. I can see a perfect example of how to now go back to my app and apply that solution. LOVE IT

If you're talking about the answer proposed by Jacob Jase then I would recommend against it. It's poor code for a number of reasons, not least of which it doesn't guarantee that the user will enter numbers into the TextBox, which seems to be the intent. I bet your VB6 friends would love it though, because it compares a String directly to Integers.
 
Conversely, your statement that everything Microsoft create is enormous and the fact that it takes more code to do the same thing in VB.NET than VB6 are to be taken as incontrovertible gospel.

Then there must be quite a few programmers with wrong conclusions out there..... I do not include myself in the "programmer" description. I'm a hack novice at this. I know just enough to be dangerous :cocksure:
 
It would help if you would post a URL to that thread...

But anyways, if you need a numeric textbox, just use a NumericUpDown control.
Sorry ..was juggling a bunch of things at the same time I was posting. It appears the same topic that I found elsewhere and pointed to. Perhaps the code in the other one originated from here.... Force only number entering in textboxes-VBForums
 
Then there must be quite a few programmers with wrong conclusions out there..... I do not include myself in the "programmer" description. I'm a hack novice at this. I know just enough to be dangerous :cocksure:

When it comes to VB6 and VB.NET, there certainly are quite few with wrong conclusions. VB6 was a great tool in its time but that time has gone. Certainly, there's a need to maintain existing VB6 apps and, even now, there are certain things that VB6 can do better/easier then VB.NET. There is a long list of advantages to using VB.NET though. Many VB6 developers are simply pissed off that Microsoft "abandoned" them and hate VB.NET on principle.
 
When it comes to VB6 and VB.NET, there certainly are quite few with wrong conclusions. VB6 was a great tool in its time but that time has gone. Certainly, there's a need to maintain existing VB6 apps and, even now, there are certain things that VB6 can do better/easier then VB.NET. There is a long list of advantages to using VB.NET though. Many VB6 developers are simply pissed off that Microsoft "abandoned" them and hate VB.NET on principle.

You posted in the link I pointed you to. I'm searching for but cannot find your post on numeric textbox Force only number entering in textboxes-VBForums that you reference in your post
 
Back
Top