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

BlakeMcKennaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
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...
BlakeMcKennaAuthor Commented:
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 .
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
I don't see the point of your ValidateLoadEnvironmentValues() sub, as all it really does is pass the parameters on to GetEnvironmentReadings().  You could do all of this inside of GetEnvironmentReadings() directly...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BlakeMcKennaAuthor Commented:
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!
BlakeMcKennaAuthor Commented:
Thanks for the input Mike!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.