Maria Torres
asked on
How to change label text from a calling function
I have a form that calls a routine (located in the general module.vb) and this routine suppose to change the label text that reside on the form. I'm passing as one of the arguments of the routine, the calling form . I don't know why, but an error is generated. When I specify the passing argument to be of type form, the error generated is "Label1 is not a memeber of System.Windows.Forms.Form" . When I then change the argument type to be of type object, nothing is returned.
Can someone please tell me what I am doing wrong? Thank you.
[within the calling FORM]
Call qtrByMth(frmProvider.cbxPe riod.Text. Substring( 0, 2), Me)
[the function]
Public Sub qtrByMth(ByVal sQtr As String, ByVal objForm As Object)
Select Case sQtr
Case "Q3"
objForm.Label1.Text = "July"
objForm.Label4.Text = "July"
CType(objForm.Controls.Fin d("Label1" , True)(0), Label).Text = "January"
objForm.Label2.Text = "August"
objForm.Label5.Text = "August"
objForm.Label3.Text = "September"
objForm.Label6.Text = "September"
end select
Can someone please tell me what I am doing wrong? Thank you.
[within the calling FORM]
Call qtrByMth(frmProvider.cbxPe
[the function]
Public Sub qtrByMth(ByVal sQtr As String, ByVal objForm As Object)
Select Case sQtr
Case "Q3"
objForm.Label1.Text = "July"
objForm.Label4.Text = "July"
CType(objForm.Controls.Fin
objForm.Label2.Text = "August"
objForm.Label5.Text = "August"
objForm.Label3.Text = "September"
objForm.Label6.Text = "September"
end select
ASKER
The routine will be used by more than one Form. Therefore, I need to be able to pass the form to the routine so that I can update several of the labels. I tried passing the form's name as one of the parameters to the routine, but I still was unable to change the labels' text.
Still not clear at what I am doing wrong. Any help is greatly appreciated.
(Note: I'm using Framework NET version 1.1)
Still not clear at what I am doing wrong. Any help is greatly appreciated.
(Note: I'm using Framework NET version 1.1)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Either change Form to the name of your desired Form (Form1, Form2, etc...), or actually search the generic form instance for the control with a matching name that you are looking for. You could also Cast the generic Form instance to a specific type and access the controls that way.
It's not clear to me which approach is best for your situation.
If you only need this function to work with ONE specific type of Form then simply change Form to the specific Form name.