?
Solved

Select Case not selecting

Posted on 2004-11-15
9
Medium Priority
?
224 Views
Last Modified: 2010-04-24
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
0
Comment
Question by:6784
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 34

Expert Comment

by:flavo
ID: 12588312
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
 
LVL 5

Expert Comment

by:TRUENEUTRAL
ID: 12588417
'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
 

Author Comment

by:6784
ID: 12588744
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 34

Expert Comment

by:flavo
ID: 12588776
well you can do it the slow way

Call ClearButtonClick("btnVMClear")  for example.

Dave
0
 

Author Comment

by:6784
ID: 12589152
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
 
LVL 34

Accepted Solution

by:
flavo earned 500 total points
ID: 12589169
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
 
LVL 7

Expert Comment

by:J_Mak
ID: 12589208
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
 
LVL 5

Expert Comment

by:TRUENEUTRAL
ID: 12589223
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
 

Author Comment

by:6784
ID: 12589377
flavo,
thanks it worked. And thanks to all the others that posted suggestions.

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question