Link to home
Start Free TrialLog in
Avatar of 6784
6784

asked on

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
Avatar of flavo
flavo
Flag of Australia image

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

Avatar of TRUENEUTRAL
TRUENEUTRAL

'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
...
Avatar of 6784

ASKER

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
well you can do it the slow way

Call ClearButtonClick("btnVMClear")  for example.

Dave
Avatar of 6784

ASKER

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"
ASKER CERTIFIED SOLUTION
Avatar of flavo
flavo
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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
Avatar of 6784

ASKER

flavo,
thanks it worked. And thanks to all the others that posted suggestions.