Results 1 to 7 of 7

Thread: VB.NET Nothing Value

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2013
    Location
    Manila
    Posts
    22

    Question VB.NET Nothing Value

    I have a code that splits the design of my form.
    But when I add this control programmatically the value of m_splitBar is always nothing.
    I want this object not to be nothing because I'm performing some manipulations there like,
    (bar.FindForm.Width),
    In VB6 the equivalent of this is (bar.parent.Width).
    The "parent object" in createSplitBar function is the Main Form. i just passing it.
    Can someone lend me a hand? I hope you guys understand. Thanks In Advance =)



    Private WithEvents m_splitBar As PictureBox

    Public Sub createSplitBar(ByVal name As String, ByVal parent As Object)
    m_splitBar = parent.Controls.Add(m_splitBar)
    setSplitterProperties(m_splitBar)
    m_imp.setSplitterProperties(CType(m_splitBar, Control))
    End Sub



    ANOTHER CLASS:
    Public Sub setSplitterProperties(ByRef bar As System.Windows.Forms.Control) 'dito
    bar = New System.Windows.Forms.Control

    With bar
    '.Width = VB6.TwipsToPixelsX(75)
    .Cursor = System.Windows.Forms.Cursors.SizeWE
    .Left = VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(bar.FindForm.Width) / 2)
    End With
    End Sub

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

    Re: VB.NET Nothing Value

    The only place that you assign anything to that variable is here:
    Code:
    m_splitBar = parent.Controls.Add(m_splitBar)
    That line of code makes no sense and, even if it did, it wouldn't help. That Add method is a Sub, not a Function, so it doesn't return anything that you can assign to a variable. Apart from that, what you're adding is the value of the same variable, which has not had anything assigned to it at that point. If you want the variable not to be Nothing then you have to actually assign something to it. Create a PictureBox object and assign it to the variable.
    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
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: VB.NET Nothing Value

    Did you perhaps intend to do this with that line of code:
    Code:
    m_splitBar = parent.Controls("m_splitBar")
    i.e. get a control from the parent by name and assign that to your variable? That's a pretty dodgy thing to do but, as long as the parent has a control with that name, it would work.
    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

  4. #4

    Thread Starter
    Junior Member
    Join Date
    May 2013
    Location
    Manila
    Posts
    22

    Re: VB.NET Nothing Value

    Thanks Sir JM ^_^, but the name of the m_splitBar is equal to "".
    In VB6 (when adding a controls):
    parent.Controls.add("VB.PictureBox", name, parent) which name is the name of the picturebox and parent is the form.
    While in VB.NET, it is just
    parent.Controls.Add(m_splitBar) thats why the m_splitbar has a name = "". No Value..
    So therefore, we cannot access the picturebox in that form.
    Is there a way to access it? Hope you understand.
    I really appreciate it.

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

    Re: VB.NET Nothing Value

    If a control has no Name it's because you didn't give it one. If you want a control to have a Name then, unless you're adding it in the designer, you have to give it a Name.

    That said, there should be no need. The control should be being pushed in from the outside, not pulled in from the inside.
    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

  6. #6

    Thread Starter
    Junior Member
    Join Date
    May 2013
    Location
    Manila
    Posts
    22

    Re: VB.NET Nothing Value

    Hi Sir JM,

    Can't figure the meaning of this "The control should be being pushed in from the outside, not pulled in from the inside.".
    Can you elaborate it for us?

    Thanks,
    Les
    Last edited by lesterluma; Oct 28th, 2015 at 07:56 PM. Reason: mispelled

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

    Re: VB.NET Nothing Value

    Quote Originally Posted by lesterluma View Post
    Hi Sir JM,

    Can't figure the meaning of this "The control should be being pushed in from the outside, not pulled in from the inside.".
    Can you elaborate it for us?

    Thanks,
    Les
    It appears to me that you have a user control on a form and that user control needs to make use of another control on the same form. Is that correct? If so then it should be the responsibility of the form to pass the user control a reference to the other control, not the responsibility of the user control to go to the form and get it. The user control should not assume anything about the form it's on other than that it's a form. It should have a property or method that can be accessed from outside, by the form, to pass in a reference to the other 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

Tags for this Thread

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