|
-
May 7th, 2008, 03:53 AM
#1
Thread Starter
Lively Member
[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
-
May 7th, 2008, 04:22 AM
#2
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.
-
May 7th, 2008, 04:29 AM
#3
Thread Starter
Lively Member
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 GetPageName, ByRef 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
-
May 7th, 2008, 07:41 AM
#4
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:
Form1.TabControl1.TabPages(GetPageName)
is Nothing or this:
vb.net Code:
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.
-
May 7th, 2008, 09:00 AM
#5
Thread Starter
Lively Member
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
-
Jan 6th, 2021, 07:30 PM
#6
New Member
Re: reference a control on a tabpage
 Originally Posted by dreamdelerium
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 ?
-
Jan 6th, 2021, 08:45 PM
#7
Re: reference a control on a tabpage
 Originally Posted by IsaaKCh
¿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.
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
|