Cesar Francisco

There are 45 textboxes to fill.

Code Snippet

Private Sub HECalculator_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

TextBox1.Text = "0.0"

TextBox2.Text = "0.0"

TextBox3.Text = "0.0"

TextBox4.Text = "0.0"

TextBox5.Text = "0.0"

TextBox6.Text = "0.0"

TextBox7.Text = "0.0"

TextBox8.Text = "0.0"

TextBox9.Text = "0.0"

.

...

....

.....

.......

End Sub




Re: Visual Basic General How to fill textboxes with "0.0" s

FalconDW

I think what you're looking for is to write a simple loop that goes through all the textboxes on your form and fills them for you. I've posted an example below that just looks for all textboxes on the form, but you could be more specific inside the loop to say something like, 'if the textbox has this property, then...'

Code Snippet

For Each t As TextBox In Me.Controls

t.Text = "0.0"

Next

Hope that helps...





Re: Visual Basic General How to fill textboxes with "0.0" s

Cesar Francisco

It looks brilliant.

I got this error ( )

Unable to cast object of type 'System.Windows.Forms.PictureBox' to type 'System.Windows.Forms.TextBox'.






Re: Visual Basic General How to fill textboxes with "0.0" s

anubisascends

This error means that you are trying to turn a picture box into a textbox. Can you post a code sample of what caused the error






Re: Visual Basic General How to fill textboxes with "0.0" s

Cesar Francisco

Code Snippet

Private Sub HECalculator_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

For Each t As TextBox In Me.Controls

t.Text = "0.0"

Next

TextBox1.Text = "0.0"

End Sub

Yes. There are to PictureBoxes on the Form. Taking them out, the error message turns on the labels. It seems to me, that anything else oder than TextBoxes will cause an exeption.






Re: Visual Basic General How to fill textboxes with "0.0" s

Spidermans_DarkSide - MSP, VSIP

FalconDW wrote:

I think what you're looking for is to write a simple loop that goes through all the textboxes on your form and fills them for you. I've posted an example below that just looks for all textboxes on the form, but you could be more specific inside the loop to say something like, 'if the textbox has this property, then...'

Code Snippet

For Each t As TextBox In Me.Controls

t.Text = "0.0"

Next

Hope that helps...

Hi Cesar & FalconDW,

You are close but you need to allow for other controls, so use TypeOf. >>>>

Code Snippet

For Each Ctrl As Control In Me.Controls

If TypeOf(Ctrl) Is TextBox Then Ctrl.Text = "0.0"

Next

This should work.

Regards,

S_DS






Re: Visual Basic General How to fill textboxes with "0.0" s

Cesar Francisco

Well done ! Mesmerized.






Re: Visual Basic General How to fill textboxes with "0.0" s

Spidermans_DarkSide - MSP, VSIP

Cesar Francisco wrote:

Well done ! Mesmerized.

Hi Cesar,

Please remember to mark my post

as answer

if it has helped you and fully answered your question.

Regards,

S_DS