Results 1 to 6 of 6

Thread: [RESOLVED] Calling other forms???

  1. #1

    Thread Starter
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Resolved [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:
    1. Public Shared Sub ClearTextboxes(ByVal AutoForms As Form, ByVal StartText As Integer, ByVal EndText As Integer)
    2.         Dim Start As Integer
    3.         For Start = StartText To EndText
    4.             Select Case Start
    5.                 Case 1
    6.                     AutoForms.textbox1.text = "" 'Textbox1 is not recognized by the compiler when textbox1 is in form1.
    7.                 Case 2
    8.                     AutoForms.textbox2.text = "" 'Textbox2 is not recognized by the compiler when textbox1 is in form1.
    9.                 Case 3
    10.                     AutoForms.textbox3.text = "" 'Textbox3 is not recognized by the compiler when textbox1 is in form1.
    11.                 Case 4
    12.                     AutoForms.textbox4.text = "" 'Textbox4 is not recognized by the compiler when textbox1 is in form1.
    13.                 Case 5
    14.                     AutoForms.textbox5.text = "" 'Textbox5 is not recognized by the compiler when textbox1 is in form1.
    15.                 Case 6
    16.                     AutoForms.textbox6.text = "" 'Textbox6 is not recognized by the compiler when textbox1 is in form1.
    17.             End Select
    18.         Next
    19.     End Sub

    Please help me.

  2. #2
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    Re: Calling other forms???

    have you tried declaring AutoForms as its actual form type?, eg As Form1, not As Form in general

  3. #3

    Thread Starter
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Question 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.

  4. #4
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    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

  5. #5

    Thread Starter
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Re: Calling other forms???

    WOW!!!

    That's a great idea.

    This is what I really wanted in my code:

    VB Code:
    1. Public Shared Sub ClearTextboxes(ByVal AutoForms As Form, ByVal StartText As Integer, ByVal EndText As Integer)
    2.         Dim Start As Integer
    3.         For Start = StartText To EndText
    4.             Select Case Start
    5.                 Case 1
    6.                     If AutoForms.Controls(0).Name = "TextBox1" Then
    7.                         AutoForms.Controls(0).Text = ""
    8.                     End If
    9.                 Case 2
    10.                     If AutoForms.Controls(1).Name = "TextBox2" Then
    11.                         AutoForms.Controls(1).Text = ""
    12.                     End If
    13.                 Case 3
    14.                     If AutoForms.Controls(2).Name = "TextBox3" Then
    15.                         AutoForms.Controls(2).Text = ""
    16.                     End If
    17.                 Case 4
    18.                     If AutoForms.Controls(3).Name = "TextBox4" Then
    19.                         AutoForms.Controls(3).Text = ""
    20.                     End If
    21.                 Case 5
    22.                     If AutoForms.Controls(4).Name = "Textbox5" Then
    23.                         AutoForms.Controls(4).Text = ""
    24.                     End If
    25.                 Case 6
    26.                     If AutoForms.Controls(5).Name = "TextBox6" Then
    27.                         AutoForms.Controls(5).Text = ""
    28.                     End If
    29.             End Select
    30.         Next
    31.     End Sub

    Man. You're great. Thanks.

    I wish I could be as intelligent as you.

  6. #6
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    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:
    1. function GetControl(frm as Form, cname as string) as control
    2.   dim i as integer
    3.   for i = 0 to frm.controls.count-1
    4.     if frm.controls(i).Name = cname Then return frm.controls(i)
    5.   next
    6.   return nothing 'loop finished and no return made
    7. 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
  •  



Click Here to Expand Forum to Full Width