|
-
Sep 5th, 2005, 08:28 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Calling other forms???
Hello!!!
I have created a class sub procedure to clear textboxes in any form but I
can't seem to compile my class library. The error always keeps me from
compiling.
Here are the codes:
VB Code:
Public Shared Sub ClearTextboxes(ByVal AutoForms As Form, ByVal StartText As Integer, ByVal EndText As Integer)
Dim Start As Integer
For Start = StartText To EndText
Select Case Start
Case 1
AutoForms.textbox1.text = "" 'Textbox1 is not recognized by the compiler when textbox1 is in form1.
Case 2
AutoForms.textbox2.text = "" 'Textbox2 is not recognized by the compiler when textbox1 is in form1.
Case 3
AutoForms.textbox3.text = "" 'Textbox3 is not recognized by the compiler when textbox1 is in form1.
Case 4
AutoForms.textbox4.text = "" 'Textbox4 is not recognized by the compiler when textbox1 is in form1.
Case 5
AutoForms.textbox5.text = "" 'Textbox5 is not recognized by the compiler when textbox1 is in form1.
Case 6
AutoForms.textbox6.text = "" 'Textbox6 is not recognized by the compiler when textbox1 is in form1.
End Select
Next
End Sub
Please help me.
-
Sep 5th, 2005, 08:30 PM
#2
Re: Calling other forms???
have you tried declaring AutoForms as its actual form type?, eg As Form1, not As Form in general
-
Sep 5th, 2005, 08:38 PM
#3
Thread Starter
Hyperactive Member
Re: Calling other forms???
Yes. That is a good idea but I am creating my project on a class module
which has no objects entered in a design mode.
What I want in my project is that I can inherit all the objects in form1 and
pass it to my AutoForms parameter.
Please help me.
-
Sep 5th, 2005, 08:45 PM
#4
Re: Calling other forms???
but you still have a class type of Form1 correct?
what i mean is to change this
ByVal AutoForms As Form
to this
ByVal AutoForms As Form1
so AutoForm is an exact model of the Form1 class type
rather than a model of its inheritance Form, which doesnt know about the objects on form1
however if what u mean by no objects in design is.. you have a base form and in code you're adding the textbox controls to it, in that case you will need to use
AutoForms.Controls
to access the controls on the form, do a loop on them and check the names
If Me.Controls(0).Name = "TextBox1" Then
-
Sep 5th, 2005, 08:55 PM
#5
Thread Starter
Hyperactive Member
Re: Calling other forms???
WOW!!!
That's a great idea.
This is what I really wanted in my code:
VB Code:
Public Shared Sub ClearTextboxes(ByVal AutoForms As Form, ByVal StartText As Integer, ByVal EndText As Integer)
Dim Start As Integer
For Start = StartText To EndText
Select Case Start
Case 1
If AutoForms.Controls(0).Name = "TextBox1" Then
AutoForms.Controls(0).Text = ""
End If
Case 2
If AutoForms.Controls(1).Name = "TextBox2" Then
AutoForms.Controls(1).Text = ""
End If
Case 3
If AutoForms.Controls(2).Name = "TextBox3" Then
AutoForms.Controls(2).Text = ""
End If
Case 4
If AutoForms.Controls(3).Name = "TextBox4" Then
AutoForms.Controls(3).Text = ""
End If
Case 5
If AutoForms.Controls(4).Name = "Textbox5" Then
AutoForms.Controls(4).Text = ""
End If
Case 6
If AutoForms.Controls(5).Name = "TextBox6" Then
AutoForms.Controls(5).Text = ""
End If
End Select
Next
End Sub
Man. You're great. Thanks.
I wish I could be as intelligent as you.
-
Sep 5th, 2005, 09:07 PM
#6
Re: [RESOLVED] Calling other forms???
if you are hardcoding the the index number "AutoForms.Controls(5)" then there is no need to check the name, the name was just for doing it in a loop, i would infact recommend making a function so you can do this whenever
eg.
VB Code:
function GetControl(frm as Form, cname as string) as control
dim i as integer
for i = 0 to frm.controls.count-1
if frm.controls(i).Name = cname Then return frm.controls(i)
next
return nothing 'loop finished and no return made
end function
so old syntax being
AutoForms.TextBox1.Text = ""
new syntax being
GetControl(AutoForms,"Textbox1").Text = ""
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|