![]() |
Calling a Sub passing Textbox name
Hello all, I am new to this forum and still somewhat green in VBA but
have quite a bit of Delphi and C++ programming experience so that i what makes my problem even more frustrating. I have created a sub that will make changes to a textbox's propertie based on the value the user entered compared to the value of a label. I would like to be able to pass to this sub the names of the textbo and the label that it should use for it's testing and changes. Here is what I have written so far, keep in mind this doesn't work: Sub TextBoxChanges(thebox As TextBox, thelbl As Label) thebox.BackColor = RGB(255, 255, 255) thebox.ForeColor = RGB(0, 0, 0) If Val(thebox.Text) = Val(thelbl.Caption) Then thebox.BackColor = RGB(0, 100, 0) thebox.ForeColor = RGB(255, 255, 255) ElseIf Val(thebox.Text) = Val(thelbl.Caption) - 1 Then thebox.BackColor = RGB(255, 0, 50) thebox.ForeColor = RGB(255, 255, 255) ElseIf Val(txt_h1.Text) = Val(thelbl.Caption) - 2 Then thebox.BackColor = RGB(255, 255, 0) thebox.ForeColor = RGB(0, 0, 0) ElseIf Val(txt_h1.Text) = Val(thelbl.Caption) + 1 Then thebox.BackColor = RGB(165, 165, 165) thebox.ForeColor = RGB(0, 0, 0) End If End Sub Private Sub txt_h1_Change() Call TextBoxChanges(txt_h1, lbl_p1) End Sub I have 18 text boxes so I would like to have an onChange event for eac textbox so that I can save some code. Any help would be apreciated please post back if you need more information. Thanks -- Message posted from http://www.ExcelForum.com |
Calling a Sub passing Textbox name
Declare the arguments as control types
Sub TextBoxChanges(thebox As MsForms.TextBox, thelbl As MSForms.Label) -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Ducttape19 " wrote in message ... Hello all, I am new to this forum and still somewhat green in VBA but I have quite a bit of Delphi and C++ programming experience so that is what makes my problem even more frustrating. I have created a sub that will make changes to a textbox's properties based on the value the user entered compared to the value of a label. I would like to be able to pass to this sub the names of the textbox and the label that it should use for it's testing and changes. Here is what I have written so far, keep in mind this doesn't work: Sub TextBoxChanges(thebox As TextBox, thelbl As Label) thebox.BackColor = RGB(255, 255, 255) thebox.ForeColor = RGB(0, 0, 0) If Val(thebox.Text) = Val(thelbl.Caption) Then thebox.BackColor = RGB(0, 100, 0) thebox.ForeColor = RGB(255, 255, 255) ElseIf Val(thebox.Text) = Val(thelbl.Caption) - 1 Then thebox.BackColor = RGB(255, 0, 50) thebox.ForeColor = RGB(255, 255, 255) ElseIf Val(txt_h1.Text) = Val(thelbl.Caption) - 2 Then thebox.BackColor = RGB(255, 255, 0) thebox.ForeColor = RGB(0, 0, 0) ElseIf Val(txt_h1.Text) = Val(thelbl.Caption) + 1 Then thebox.BackColor = RGB(165, 165, 165) thebox.ForeColor = RGB(0, 0, 0) End If End Sub Private Sub txt_h1_Change() Call TextBoxChanges(txt_h1, lbl_p1) End Sub I have 18 text boxes so I would like to have an onChange event for each textbox so that I can save some code. Any help would be apreciated, please post back if you need more information. Thanks. --- Message posted from http://www.ExcelForum.com/ |
Calling a Sub passing Textbox name
Thanks a bunch, that worked perfect. I knew that it wouldn't be muc
but when you don't know it can be frustrating. Anyways thanks -- Message posted from http://www.ExcelForum.com |
All times are GMT +1. The time now is 06:49 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com