Results 1 to 7 of 7

Thread: [RESOLVED] reference a control on a tabpage

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Location
    Botswana
    Posts
    107

    Resolved [RESOLVED] reference a control on a tabpage

    hey everyone. can anyone tell me how to reference a control's properties (like a textbox width) that is placed on a tabcontrols tabpage

    thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: reference a control on a tabpage

    The fact that it's on a TabPage makes no difference if it was added at design time. You access the control via the same member variable regardless of its parent. Me.TextBox1 is the first TextBox you added to the form regardless of whether it's on the form, a TabPage, or in a GroupBox within a Panel.

    That said, you can always access any containers child controls via its Controls collection. All the controls added directly to the form are in the form's Controls collection. All the controls added to a TabPage are in the TabPage's Controls collection. You can index any container's Controls collection by the ordinal (numeric index) or key (name) of the child control.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Location
    Botswana
    Posts
    107

    Re: reference a control on a tabpage

    i guess is should have more specific. the control i want to reference is created at run time. the code is below

    PHP Code:
    Function GetTop(ByRef GetPageNameByRef GetQName)

            
    On Error GoTo errorhandler

            Dim NewTop
            Dim QTop

            QTop 
    Form1.TabControl1.TabPages(GetPageName).controls(GetQName).top

    'where GetPageName is the name of the page the control is on
    '
    and GetQName is the name of the control i want to reference

            MsgBox
    (QTop)    

            Return 
    QTop

    errorhandler
    :
            If 
    Err.Number 0 Then
            
    Else
                
    MsgBox(Err.Description)
            
    End If

        
    End Function 


    if get the error: Object variable or with block variable not set

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: reference a control on a tabpage

    Yes, you should have been more specific. You should always give the full story from the start.

    Any time you get a NullReferenceException, the first thing to do is to establish which reference is null. In your case you need to determine whether this:
    vb.net Code:
    1. Form1.TabControl1.TabPages(GetPageName)
    is Nothing or this:
    vb.net Code:
    1. Form1.TabControl1.TabPages(GetPageName).controls(GetQName)
    is Nothing. If you don't actually know what problem you're trying to solve then it can make it difficult to solve it.

    On an unrelated note, you're doing something there which, while legal, is very poor practice. NEVER, EVER declare anything without a type. What are these supposed to be:
    Code:
            Dim NewTop
            Dim QTop
    If they're supposed to be Integers then declare tham as such. Otherwise they're both type Object regardless of what you assign to them. You obviously have Option Strict Off, which I suggest you set to On immediately. Option Strict On would not allow you to do things like declare variables without types.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Location
    Botswana
    Posts
    107

    Resolved Re: reference a control on a tabpage

    thanks. still kind of new to this. as it turns out one of my values coming in from the function call was null. it works fine now

  6. #6
    New Member
    Join Date
    Jan 2021
    Posts
    1

    Re: reference a control on a tabpage

    Quote Originally Posted by dreamdelerium View Post
    thanks. still kind of new to this. as it turns out one of my values coming in from the function call was null. it works fine now
    ¿Could you please help me how to use this Component in VB. I am trying to reference a control but I can't. I am using your code ?

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: reference a control on a tabpage

    Quote Originally Posted by IsaaKCh View Post
    ¿Could you please help me how to use this Component in VB. I am trying to reference a control but I can't. I am using your code ?
    That person last posted in 2009, so you're unlikely to get a response. It's generally a bad idea to resurrect ancient threads. Basically, if what you are doing is not working then you're doing it wrong. As you haven't bothered to show us what you're doing, we can't tell you what's wrong with it. You should start your own thread and do as everyone should do, i.e. provide a FULL and CLEAR explanation of the problem. Explain exactly what you're trying to achieve, how you're trying to achieve it and what happens when you try. You can provide a link to this thread if you think that doing so would add value. You will have a much better chance of getting help from a range of people with a new thread than one that's over a decade old and marked Resolved. I would have ignored your post, except that I was already subscribed to this thread and got a notification. Everyone else who didn't is unlikely to see your post.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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