Select Case not selecting

I am building an asp.net app. I have three  buttons that clear different section of a user form. I am trying to have the clearbutton click event call a subprocedure that will determine which botton was clicked and then clear the text. I am using varibles to hold which botton was click and it look likes that is not work. Could you please look at my code and help me out.

thanks

Private Sub btnVMClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVMClear.Click
        Dim strbutton As String
        Dim strVMClear As String

        strbutton = strVMClear

        Call ClearButtonClick()

          End Sub


Private Sub ClearButtonClick()
        Dim strButton As String
        Dim strVMCLear
        Dim strVCCLear
        Dim strVRClear

        Select Case strButton

            Case Is = strVMCLear

                txtSOrtName.Text = ""
                txtNamePart1.Text = ""
                txtLegalName1.Text = ""
                txtNamePart2.Text = ""
                txtLegalName2.Text = ""
                ddlEmpCategory.SelectedIndex = 0
                ddlVenGroup.SelectedIndex = -1
                radlVat.Items(0).Selected = True

            Case Is = strVCCLear

                ddlFactor.SelectedIndex = -1
                ddlVenCategory.SelectedIndex = -1
                ddlPayMethod.SelectedIndex = -1
                ddlPayTerms.SelectedIndex = -1
                radlSwitch.Items(3).Selected = True

            Case Is = strVRClear

                ddlCountry.SelectedIndex = -1
                ddlRespOffice.SelectedIndex = -1
                txtAddress1.Text = ""
                txtAddress2.Text = ""
                txtAddress3.Text = ""
                txtCity.Text = ""
                txtPostalCode.Text = ""
                txtPhone.Text = ""
                txtExt.Text = ""
                txtFax.Text = ""
                txtLegalName1.Text = ""
                txtLegalName2.Text = ""
                txtContactName.Text = ""
                chkEFT.Checked() = True
                txtBankAccount.Text = ""
                txtBranchCode.Text = ""
                txtSwiftAddress.Text = ""
                txtBankRef.Text = ""
                txtBankName.Text = ""
                txtBankPlace.Text = ""
                txtEmail.Text = ""
                txtTaxID.Text = ""
                txtGovReg.Text = ""
                txtComment1.Text = ""
                txtComment2.Text = ""
                txtMiscRef1.Text = ""
                txtMiscRef2.Text = ""
                txtMiscRef3.Text = ""
                txtMiscRef4.Text = ""

            Case Else

                txtSOrtName.Text = ""
                txtNamePart1.Text = ""
                txtLegalName1.Text = ""
                txtNamePart2.Text = ""
                txtLegalName2.Text = ""
                ddlEmpCategory.SelectedIndex = 0
                ddlVenGroup.SelectedIndex = -1
                radlVat.Items(0).Selected = True
                ddlFactor.SelectedIndex = -1
                ddlVenCategory.SelectedIndex = -1
                ddlPayMethod.SelectedIndex = -1
                ddlPayTerms.SelectedIndex = -1
                radlSwitch.Items(3).Selected = True
                ddlCountry.SelectedIndex = -1
                ddlRespOffice.SelectedIndex = -1
                txtAddress1.Text = ""
                txtAddress2.Text = ""
                txtAddress3.Text = ""
                txtCity.Text = ""
                txtPostalCode.Text = ""
                txtPhone.Text = ""
                txtExt.Text = ""
                txtFax.Text = ""
                txtLegalName1.Text = ""
                txtLegalName2.Text = ""
                txtContactName.Text = ""
                chkEFT.Checked() = True
                txtBankAccount.Text = ""
                txtBranchCode.Text = ""
                txtSwiftAddress.Text = ""
                txtBankRef.Text = ""
                txtBankName.Text = ""
                txtBankPlace.Text = ""
                txtEmail.Text = ""
                txtTaxID.Text = ""
                txtGovReg.Text = ""
                txtComment1.Text = ""
                txtComment2.Text = ""
                txtMiscRef1.Text = ""
                txtMiscRef2.Text = ""
                txtMiscRef3.Text = ""
                txtMiscRef4.Text = ""


        End Select



    End Sub
6784Asked:
Who is Participating?
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.

flavoCommented:
Id suggest a little change.

change this top bit

Private Sub ClearButtonClick()
        Dim strButton As String
        Dim strVMCLear
        Dim strVCCLear
        Dim strVRClear

        Select Case strButton


to

Private Sub ClearButtonClick(strButton as string)

        Select Case strButton

'then in your first sub use

Private Sub btnVMClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVMClear.Click

        Call ClearButtonClick(sender.Name)

          End Sub

The problem is that your varibles were all over the shop.

If you Dim a varibale in a Sub, you WONT be able to access it the way you were trying to in another sub / function

HTH

Dave

0
TRUENEUTRALCommented:
'change to
        Dim strbutton As String
Private Sub btnVMClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVMClear.Click
        Dim strVMClear As String="1"
        strbutton = strVMClear

        Call ClearButtonClick()

          End Sub


Private Sub ClearButtonClick()
        Dim strVMCLear
        Dim strVCCLear
        Dim strVRClear
...
0
6784Author Commented:
flavo,

havn't tested yet, but I am getting an error when I use the Call statment in another clickevent.
Its say that sender (sender.Name) is not declared and not on the others.

Thanks
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

flavoCommented:
well you can do it the slow way

Call ClearButtonClick("btnVMClear")  for example.

Dave
0
6784Author Commented:
well it didn't like (sender.Name): System.MissingMemberException: Public member 'Name' on type 'Button' not found

when I tried;  Call ClearButtonClick("btnVMClear")  the Select Case didn't recognizes "btnVMClear"
0
flavoCommented:
change all your  Case Is = strVMCLear

to  Case Is = "strVMCLear"

so youll have


Private Sub ClearButtonClick(strButton as string)

        Select Case strButton

            Case Is = "strVMCLear"

                txtSOrtName.Text = ""
                txtNamePart1.Text = ""
                txtLegalName1.Text = ""
                txtNamePart2.Text = ""
                txtLegalName2.Text = ""
                ddlEmpCategory.SelectedIndex = 0
                ddlVenGroup.SelectedIndex = -1
                radlVat.Items(0).Selected = True

            Case "strVCCLear"

                ddlFactor.SelectedIndex = -1
                ddlVenCategory.SelectedIndex = -1
                ddlPayMethod.SelectedIndex = -1
                ddlPayTerms.SelectedIndex = -1
                radlSwitch.Items(3).Selected = True

            Case "strVRClear"

                ddlCountry.SelectedIndex = -1
                ddlRespOffice.SelectedIndex = -1
                txtAddress1.Text = ""
                txtAddress2.Text = ""
                txtAddress3.Text = ""
                txtCity.Text = ""
                txtPostalCode.Text = ""
                txtPhone.Text = ""
                txtExt.Text = ""
                txtFax.Text = ""
                txtLegalName1.Text = ""
                txtLegalName2.Text = ""
                txtContactName.Text = ""
                chkEFT.Checked() = True
                txtBankAccount.Text = ""
                txtBranchCode.Text = ""
                txtSwiftAddress.Text = ""
                txtBankRef.Text = ""
                txtBankName.Text = ""
                txtBankPlace.Text = ""
                txtEmail.Text = ""
                txtTaxID.Text = ""
                txtGovReg.Text = ""
                txtComment1.Text = ""
                txtComment2.Text = ""
                txtMiscRef1.Text = ""
                txtMiscRef2.Text = ""
                txtMiscRef3.Text = ""
                txtMiscRef4.Text = ""

            Case Else

                txtSOrtName.Text = ""
                txtNamePart1.Text = ""
                txtLegalName1.Text = ""
                txtNamePart2.Text = ""
                txtLegalName2.Text = ""
                ddlEmpCategory.SelectedIndex = 0
                ddlVenGroup.SelectedIndex = -1
                radlVat.Items(0).Selected = True
                ddlFactor.SelectedIndex = -1
                ddlVenCategory.SelectedIndex = -1
                ddlPayMethod.SelectedIndex = -1
                ddlPayTerms.SelectedIndex = -1
                radlSwitch.Items(3).Selected = True
                ddlCountry.SelectedIndex = -1
                ddlRespOffice.SelectedIndex = -1
                txtAddress1.Text = ""
                txtAddress2.Text = ""
                txtAddress3.Text = ""
                txtCity.Text = ""
                txtPostalCode.Text = ""
                txtPhone.Text = ""
                txtExt.Text = ""
                txtFax.Text = ""
                txtLegalName1.Text = ""
                txtLegalName2.Text = ""
                txtContactName.Text = ""
                chkEFT.Checked() = True
                txtBankAccount.Text = ""
                txtBranchCode.Text = ""
                txtSwiftAddress.Text = ""
                txtBankRef.Text = ""
                txtBankName.Text = ""
                txtBankPlace.Text = ""
                txtEmail.Text = ""
                txtTaxID.Text = ""
                txtGovReg.Text = ""
                txtComment1.Text = ""
                txtComment2.Text = ""
                txtMiscRef1.Text = ""
                txtMiscRef2.Text = ""
                txtMiscRef3.Text = ""
                txtMiscRef4.Text = ""


        End Select



    End Sub

Idea??

Hope this is it

Dave
0

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
J_MakCommented:
Try this:

Private Sub ClearButtonClick()
        Dim strButton As String
        Dim strVMCLear As String
        Dim strVCCLear As String
        Dim strVRClear As String

        Select Case strButton

            Case strVMCLear

                txtSOrtName.Text = ""
                txtNamePart1.Text = ""
                txtLegalName1.Text = ""
                txtNamePart2.Text = ""
                txtLegalName2.Text = ""
                ddlEmpCategory.SelectedIndex = 0
                ddlVenGroup.SelectedIndex = -1
                radlVat.Items(0).Selected = True

            Case strVCCLear

                ddlFactor.SelectedIndex = -1
                ddlVenCategory.SelectedIndex = -1
                ddlPayMethod.SelectedIndex = -1
                ddlPayTerms.SelectedIndex = -1
                radlSwitch.Items(3).Selected = True

            Case strVRClear

                ddlCountry.SelectedIndex = -1
                ddlRespOffice.SelectedIndex = -1
                txtAddress1.Text = ""
                txtAddress2.Text = ""
                txtAddress3.Text = ""
                txtCity.Text = ""
                txtPostalCode.Text = ""
                txtPhone.Text = ""
                txtExt.Text = ""
                txtFax.Text = ""
                txtLegalName1.Text = ""
                txtLegalName2.Text = ""
                txtContactName.Text = ""
                chkEFT.Checked() = True
                txtBankAccount.Text = ""
                txtBranchCode.Text = ""
                txtSwiftAddress.Text = ""
                txtBankRef.Text = ""
                txtBankName.Text = ""
                txtBankPlace.Text = ""
                txtEmail.Text = ""
                txtTaxID.Text = ""
                txtGovReg.Text = ""
                txtComment1.Text = ""
                txtComment2.Text = ""
                txtMiscRef1.Text = ""
                txtMiscRef2.Text = ""
                txtMiscRef3.Text = ""
                txtMiscRef4.Text = ""

            Case Else

                txtSOrtName.Text = ""
                txtNamePart1.Text = ""
                txtLegalName1.Text = ""
                txtNamePart2.Text = ""
                txtLegalName2.Text = ""
                ddlEmpCategory.SelectedIndex = 0
                ddlVenGroup.SelectedIndex = -1
                radlVat.Items(0).Selected = True
                ddlFactor.SelectedIndex = -1
                ddlVenCategory.SelectedIndex = -1
                ddlPayMethod.SelectedIndex = -1
                ddlPayTerms.SelectedIndex = -1
                radlSwitch.Items(3).Selected = True
                ddlCountry.SelectedIndex = -1
                ddlRespOffice.SelectedIndex = -1
                txtAddress1.Text = ""
                txtAddress2.Text = ""
                txtAddress3.Text = ""
                txtCity.Text = ""
                txtPostalCode.Text = ""
                txtPhone.Text = ""
                txtExt.Text = ""
                txtFax.Text = ""
                txtLegalName1.Text = ""
                txtLegalName2.Text = ""
                txtContactName.Text = ""
                chkEFT.Checked() = True
                txtBankAccount.Text = ""
                txtBranchCode.Text = ""
                txtSwiftAddress.Text = ""
                txtBankRef.Text = ""
                txtBankName.Text = ""
                txtBankPlace.Text = ""
                txtEmail.Text = ""
                txtTaxID.Text = ""
                txtGovReg.Text = ""
                txtComment1.Text = ""
                txtComment2.Text = ""
                txtMiscRef1.Text = ""
                txtMiscRef2.Text = ""
                txtMiscRef3.Text = ""
                txtMiscRef4.Text = ""


        End Select



    End Sub
0
TRUENEUTRALCommented:
oh,
are you trying to us enums?

Private enum ButtonEvent
   strVMCLear=1
   strVCCLear=2
   strVRClear=3
end enum

       Dim strbutton As ButtonEvent

Private Sub btnVMClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVMClear.Click
        strbutton = ButtonEvent.strVMClear

        Call ClearButtonClick()

          End Sub


Private Sub ClearButtonClick()
        select case strbutton
            case ButtonEvent.strVMClear

            case ButtonEvent.strVCCLear

            case ButtonEvent.strVRClear
        end select
end sub
0
6784Author Commented:
flavo,
thanks it worked. And thanks to all the others that posted suggestions.

0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.