Avatar of BlakeMcKenna
BlakeMcKennaFlag for United States of America

asked on 

UserControl is "Nothing"?

I am trying to pass one of three different kinds of UserControls into the below SubProcedure and based on the value of the "testType" parameter, the "uc" will get set accordingly. My problem, however, is that the value of "uc" is Nothing when it enters the Try Catch even though it was assigned as a "userLoad", "userCreep" or "userRepeat" UserControl. How can I capture the appropriate UC when passed in?

Thanks!

    Private Sub ValidateLoadEnvironmentValues(uc As UserControl, testType As String)

        Select Case testType
            Case "Load"
                uc = DirectCast(uc, userLoad)
            Case "Creep"
                uc = DirectCast(uc, userCreep)
            Case "Repeat"
                uc = DirectCast(uc, userRepeat)
        End Select

        Try
            EH.ErrorMessage = String.Empty

            GetEnvironmentReadings(uc, testType)

            If EH.ErrorMessage = String.Empty Then
                AreTestsComplete(uc)
            End If

ProcessMessage:

        Catch ex As Exception
            EH.ErrorMessage = "frmCalibration_3/ValidateLoadEnvironmentValues() - " & ex.Message & "...Contact Engineering!" & "~E"
        End Try
    End Sub

Open in new window

Visual Basic.NET

Avatar of undefined
Last Comment
BlakeMcKenna
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

What does "GetEnvironmentReadings()" do?  Lines like this "uc = DirectCast(uc, userLoad)" don't actually the type of "uc".  It's still a generic UserControl when you pass it.  If Nothing is the problem, it is most likely getting passed in as Nothing...
Avatar of BlakeMcKenna
BlakeMcKenna
Flag of United States of America image

ASKER

It actually references several controls from within the "uc" and then makes another call to a function. The signature parameter "uc" actually does contain a valid UserControl instance .
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of BlakeMcKenna
BlakeMcKenna
Flag of United States of America image

ASKER

I know where your coming from Mike...and makes sense in a normal situation. However, ValidateLoadEnvironmentValues is a SubProcedure that is the object of an "AddressOf" in the dynamic creation of the UserControls. Anyway, I think I figured it out!
Avatar of BlakeMcKenna
BlakeMcKenna
Flag of United States of America image

ASKER

Thanks for the input Mike!
Visual Basic.NET
Visual Basic.NET

Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to Visual Basic pre-2002, it is not the same technology,

96K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo