Solved

Is this legal in VB.NET if not, why and how to solve it.

Posted on 2004-09-16
12
519 Views
Last Modified: 2010-08-05
okay,...in the code for my main for which contains tcProfile.   - Please read below

if tcProfile.tabPageCollection(tpAlertinformation.Contains(grpAlert.Contains(pnlEnablealert.Contains(cboEmailaddress.txt)))) <> "" The

etc , etc, etc,

Now,...this isn't quite working...can someone tell me what's up? and I'm going about this wrong?

Thanks,


Thomas
0
Comment
Question by:croag
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12080256
What are you trying to do?  Contains returns a true/false, so how would you use that as an index to a collection?

Bob
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 12080831
are you looking for the indexof() method which returns the index of a value here ? that would make more sense for use in the indexing of another collection.
0
 
LVL 1

Author Comment

by:croag
ID: 12082185
Hello,


Thanks for the read!...Well, I 'm just trying to write an IF statement in the load of the form...The thing is, the combo box that I'm trying to check, lives within panel which lives in a group which lives in a tabpage which belongs to a tabcontrol. Phew. Anyhelp is appreciated. Thanks!
0
 
LVL 5

Expert Comment

by:tzxie2000
ID: 12083105
could you test just


if (cboEmailaddress.text) <> "" Then
end if

We do not need to use contains to access it
the contains just used to go through the controls in the page
0
 
LVL 5

Expert Comment

by:tzxie2000
ID: 12083109
sorry for more ()

if cboEmailaddress.text <> "" Then
end if
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12083527
This is what I use to find a control recursively looking through other container controls:

  Public Function FindControlByName(ByVal containerParent As Object, ByVal nameSearch As String) As Control

    ' Description:
    '  Starting with the top-level container, search through each control looking for a control
    '  with the specified name.  If the current control has children controls, such as a GroupBox, then
    '  recursively call this routine to search for the control in each container.  

    ' VB.NET is different in this regard from VB6, where Me.Controls in VB6 contained all the controls
    ' for the form, and in VB.NET it contains only the top-level controls.

    Dim foundControl As Control

    Try

      For Each controlCurrent As Control In containerParent.Controls

        If controlCurrent.Controls.Count > 0 Then

          ' The current control owns other controls, so search through the
          ' controls for that container for the specified control name.
          foundControl = FindControlByName(controlCurrent, nameSearch)
        End If

        ' Control not found from the container search?
        If foundControl Is Nothing Then

          ' Control matched by name?
          If controlCurrent.Name = nameSearch Then

            ' Return a reference to the control to the caller.
            foundControl = controlCurrent

            ' Don't go any further, since the control was found.
            Exit For

          End If ' Control matched by name?

        Else

          ' Don't go any further, since the control was found on the container.
          Exit For

        End If ' Control not found from the container search?

      Next controlCurrent

    Finally

    End Try

    Return foundControl

  End Function 'FindControlByName'

Bob
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:croag
ID: 12087113
Thank you all for your input. Bob, I believe that you understand me the best. Is this function that you have written necessary for VB.NET only or was it neccessary for VB6 as well? If so, why? Also, Do you think you could show how you use your little function here in a piece of code...say..between form1 and form2, each containing a text box? Also, should that function have to be a module Thank you soooooooo much in advace.I've upped the points! Thanks!
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12087167
In VB6, you didn't have the concept of containers having a Controls property.  In VB.NET 2005, you will be able to reference a control by it's name:

GroupBox("textInput")

This isn't here yet, so this IMHO is necessary in VB.NET 2002 or 2003, since you can't reference controls by name.

You could have this as as shared function in a class module (like String.Format):

Public Class Utility

  Public Shared Function FindControlByName

End Class

Call by Utility.FindControlByName(form1, "textInput")

Bob
0
 
LVL 1

Author Comment

by:croag
ID: 12087696
Maaan....thank you sooo much bob. You are alifesaver like none other. one last little thing...please? can I put pass that 'Call by Utility.FindControlName(formname,controlname)' into a different varibles in the load event on each form? if so. how..


Thank you soooo much...this has been great!!!!
0
 
LVL 1

Author Comment

by:croag
ID: 12088643
more points still for that last piece of info..then I'm all set I believe! Thanks!
0
 
LVL 1

Author Comment

by:croag
ID: 12098501
can I put pass that 'Call by Utility.FindControlName(formname,controlname)'  above into a different varibles in the load event on each form so as to make limit the amount of typing I woud have to do (by not having to type Utility.FindControlName each time)? if so. how..
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 190 total points
ID: 12101227
I am not exactly sure what you are asking for?

Bob
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now