Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15447

VS 2017 Optimize code

$
0
0
Hi,

I would like to ask something which is still eluding my understanding…

Say I have a button, when this button is click the following is happen:

Code:

If TextBox1. Text = “Test” Then

Textbox2.Text = “Completed”
TextBox2.BackColour = Colour.Green
TextBox2.ForeColour = Color.Yellow
TextBox2.Enabled = True


Textbox3.Text = “Completed”
TextBox3.BackColour = Colour.Green
TextBox3.ForeColour = Color.Yellow
TextBox3.Enabled = True


Textbox4.Text = “Completed”
TextBox4.BackColour = Colour.Green
TextBox4.ForeColour = Color.Yellow
TextBox4.Enabled = True


Textbox5.Text = “Completed”
TextBox5.BackColour = Colour.Green
TextBox5.ForeColour = Color.Yellow
TextBox5.Enabled = True

End If

So basically when a certain condition arise (TextBox1. Text = “Test”) then series of actions happen for “a” textbox and that actions is repeated for some other textboxes as well.

I could have many texboxes with many actions so the code can get very long. So… how to optimize this?

So in my mind something like this needs to happen:

Code:

Dim myTextBoxes as Textbox = Textbox2 + Textbox3 + Textbox4 + Textbox5
And then:

Code:

If TextBox1. Text = “Test” Then
MyTextBoxes.Text = “Completed”
MyTextBoxes.BackColour = Colour.Green
MyTextBoxes.ForeColour = Color.Yellow
MyTextBoxes.Enabled = True

It is obviously not correct….
How can this be achieved?

Thanks

Viewing all articles
Browse latest Browse all 15447

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>