Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 5th, 2005, 05:12 AM
Authorized User
 
Join Date: Apr 2005
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help writing functions please

I was wondering if it is possible to put the following into functions and have a Sub called Sub CheckMain(sender as object, e as eventargs) to call the functions, I'm sure there is a way, but not sure how to implement it I've been working on it for the past two days, any help would be really appreciated, or sample code.

Code:
Sub CheckMain(sender As Object, e As EventArgs)

    Select Case sys.SelectedItem.Value
        Case "6024H-I", "6014H-T", "6014P-82R", "7044H-T"
            xeon800.visible = True

        Case "6013P-T", "6023P-I"
            xeon.visible = True

        Case "5013C-T"
            p4.visible = True

        Case "6113L-8"
            itanium.visible = True

        Case Else
            MsgBox("Please choose a Server to continue")

    End Select

End Sub

Sub CheckMain1(sender As Object, e As EventArgs)

    Select Case sys.SelectedItem.Value
        Case "6014P-82R", "6113L-8"
            scsi.visible = True

        Case "6014H-T", "6013P-T", "5013C-T", "6023P-I", "7044H-T"
            sata.visible = True

        Case "6023P-I"
            ide.visible = True

        Case Else
            MsgBox("Please Select a Server to continue")

    End Select

End Sub

Sub CheckMain2(sender As Object, e As EventArgs)

    Select Case sys.SelectedItem.Value
        Case "6024H-I", "6023P-I", "7044H-T"
            TAPE.visible = True

        Case "5013C-T"
            nocpu.visible = False

        Case "6113L-8", "6023P-I"
            check1.visible = False

        Case "6113L-8"
            FDD.visible = False

        Case Else
            MsgBox("Please Select a Server to continue")

    End Select

End Sub
 
Old April 5th, 2005, 08:24 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Could you elaborate more on what you are trying to do? I don't see anywhere that you are using the parameters that you are specifying for your procedures.

J
 
Old April 5th, 2005, 09:05 AM
Authorized User
 
Join Date: Apr 2005
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry for not being specific, as you can see from my opening post I have 3 Sub commands all of which have the same arguement "Select Case sys.SelectedItem.Value
", on my form I have a dropdown list ID=sys, and a OnSelectedIndexChange=CheckMain command which then goes through the Sub and makes other DDL's visible dependant on which arguement is true. Now my problem is that on my OnSelectedIndexChange I can't put in CheckMain,CheckMain1 and CheckMain2, so I am thinking if I put them into functions then I'll be able to find which statements are true and get values returned, and just use the one Sub to call the functions, but the problem is I'm a novice to VB.NET and am not sure how to structure the function, which is what I need help with. Unless if there is an easier way, I've read books, gone through forums and googled, but no luck.

 
Old April 5th, 2005, 09:34 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Let me just clarify a few things. First, this is a Windows application, correct?

Next, the DDL "sys" has all of the values listed in all 3 of the different Sub's Select statements? If they all come from the same DDL, why are you putting them in 3 different Select statements in 3 different Subs?

Next, why can't you call these Subs(or Sub as I see it you only need one) from the SelectedIndexChanged event?

Next, you don't need "sender" and "e" unless you plan on doing something with them. It shouldn't affect the outcome of your procedure but it isn't necessary as you have it written.

J
 
Old April 5th, 2005, 09:58 AM
Authorized User
 
Join Date: Apr 2005
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes it is a windows application, I just tried what I think you are trying to say, I've put all the Sub's into one (see code).
But I'm getting compilation error, but when I put (sender As Object, e As EventArgs) the program compiles, but not all the statements get executed EG:
If you select 5013C-T from the dropdown list, then the only statement to execute is p4.visible = True, whereas I need the following to become visible p4.visible = True, sata.visible = True, nocpu.visible = False.
I hope that makes sence??

Code:
Sub CheckMain()

    Select Case sys.SelectedItem.Value

        Case "6024H-I", "6014H-T", "6014P-82R", "7044H-T"
            xeon800.visible = True

        Case "6013P-T", "6023P-I"
            xeon.visible = True

        Case "5013C-T"
            p4.visible = True

        Case "6113L-8"
            itanium.visible = True

        Case "6014P-82R", "6113L-8"
            scsi.visible = True

        Case "6014H-T", "6013P-T", "5013C-T", "6023P-I", "7044H-T"
            sata.visible = True

        Case "6023P-I"
            ide.visible = True

        Case "6024H-I", "6023P-I", "7044H-T"
            TAPE.visible = True

        Case "5013C-T"
            nocpu.visible = False

        Case "6113L-8", "6023P-I"
            check1.visible = False

        Case "6113L-8"
            FDD.visible = False

        Case Else
            MsgBox("Please Select a Server to continue")

    End Select

End Sub
 
Old April 5th, 2005, 10:20 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

OK, I tried your code and here is what I get. Mine compiles and functions without the sender, e parameters. Change "sys.SelectedItem.Value" to "sys.SelectedItem".

'----------------------------------------------------------------

Sub CheckMain()

        Select Case sys.SelectedItem

            Case "6024H-I", "6014H-T", "6014P-82R", "7044H-T"
                xeon800.Visible = True

            Case "6013P-T", "6023P-I"
                xeon.Visible = True

            Case "5013C-T"
                p4.Visible = True

            Case "6113L-8"
                itanium.Visible = True

            Case "6014P-82R", "6113L-8"
                scsi.Visible = True

            Case "6014H-T", "6013P-T", "5013C-T", "6023P-I", "7044H-T"
                sata.Visible = True

            Case "6023P-I"
                ide.Visible = True

            Case "6024H-I", "6023P-I", "7044H-T"
                tape.Visible = True

            Case "5013C-T"
                noCPU.Visible = False

            Case "6113L-8", "6023P-I"
                check1.Visible = False

            Case "6113L-8"
                fdd.Visible = False

            Case Else
                MsgBox("Please Select a Server to continue")

        End Select

    End Sub

    Private Sub sys_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles sys.SelectedIndexChanged
        CheckMain()
    End Sub

'----------------------------------------------------------------


J
 
Old April 5th, 2005, 10:35 AM
Authorized User
 
Join Date: Apr 2005
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you so much for your time J, that code works perfectly,

 
Old April 5th, 2005, 11:05 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

No problem.





Similar Threads
Thread Thread Starter Forum Replies Last Post
C# functions daniel.mihalcea C# 2008 aka C# 3.0 3 September 11th, 2008 05:10 PM
C functions...??? ethantinder C# 2 April 25th, 2008 02:25 AM
functions xelepi PHP How-To 1 March 10th, 2006 02:59 AM
Help with Functions megabytes C# 1 August 7th, 2003 12:48 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.