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.SelectedInd ex = 0
ddlVenGroup.SelectedIndex = -1
radlVat.Items(0).Selected = True
Case Is = strVCCLear
ddlFactor.SelectedIndex = -1
ddlVenCategory.SelectedInd ex = -1
ddlPayMethod.SelectedIndex = -1
ddlPayTerms.SelectedIndex = -1
radlSwitch.Items(3).Select ed = True
Case Is = strVRClear
ddlCountry.SelectedIndex = -1
ddlRespOffice.SelectedInde x = -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.SelectedInd ex = 0
ddlVenGroup.SelectedIndex = -1
radlVat.Items(0).Selected = True
ddlFactor.SelectedIndex = -1
ddlVenCategory.SelectedInd ex = -1
ddlPayMethod.SelectedIndex = -1
ddlPayTerms.SelectedIndex = -1
radlSwitch.Items(3).Select ed = True
ddlCountry.SelectedIndex = -1
ddlRespOffice.SelectedInde x = -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
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.SelectedInd
ddlVenGroup.SelectedIndex = -1
radlVat.Items(0).Selected = True
Case Is = strVCCLear
ddlFactor.SelectedIndex = -1
ddlVenCategory.SelectedInd
ddlPayMethod.SelectedIndex
ddlPayTerms.SelectedIndex = -1
radlSwitch.Items(3).Select
Case Is = strVRClear
ddlCountry.SelectedIndex = -1
ddlRespOffice.SelectedInde
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.SelectedInd
ddlVenGroup.SelectedIndex = -1
radlVat.Items(0).Selected = True
ddlFactor.SelectedIndex = -1
ddlVenCategory.SelectedInd
ddlPayMethod.SelectedIndex
ddlPayTerms.SelectedIndex = -1
radlSwitch.Items(3).Select
ddlCountry.SelectedIndex = -1
ddlRespOffice.SelectedInde
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
'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
...
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
...
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
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("btnVMCle ar") for example.
Dave
Call ClearButtonClick("btnVMCle
Dave
ASKER
well it didn't like (sender.Name): System.MissingMemberExcept ion: Public member 'Name' on type 'Button' not found
when I tried; Call ClearButtonClick("btnVMCle ar") the Select Case didn't recognizes "btnVMClear"
when I tried; Call ClearButtonClick("btnVMCle
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.SelectedInd ex = 0
ddlVenGroup.SelectedIndex = -1
radlVat.Items(0).Selected = True
Case strVCCLear
ddlFactor.SelectedIndex = -1
ddlVenCategory.SelectedInd ex = -1
ddlPayMethod.SelectedIndex = -1
ddlPayTerms.SelectedIndex = -1
radlSwitch.Items(3).Select ed = True
Case strVRClear
ddlCountry.SelectedIndex = -1
ddlRespOffice.SelectedInde x = -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.SelectedInd ex = 0
ddlVenGroup.SelectedIndex = -1
radlVat.Items(0).Selected = True
ddlFactor.SelectedIndex = -1
ddlVenCategory.SelectedInd ex = -1
ddlPayMethod.SelectedIndex = -1
ddlPayTerms.SelectedIndex = -1
radlSwitch.Items(3).Select ed = True
ddlCountry.SelectedIndex = -1
ddlRespOffice.SelectedInde x = -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
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.SelectedInd
ddlVenGroup.SelectedIndex = -1
radlVat.Items(0).Selected = True
Case strVCCLear
ddlFactor.SelectedIndex = -1
ddlVenCategory.SelectedInd
ddlPayMethod.SelectedIndex
ddlPayTerms.SelectedIndex = -1
radlSwitch.Items(3).Select
Case strVRClear
ddlCountry.SelectedIndex = -1
ddlRespOffice.SelectedInde
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.SelectedInd
ddlVenGroup.SelectedIndex = -1
radlVat.Items(0).Selected = True
ddlFactor.SelectedIndex = -1
ddlVenCategory.SelectedInd
ddlPayMethod.SelectedIndex
ddlPayTerms.SelectedIndex = -1
radlSwitch.Items(3).Select
ddlCountry.SelectedIndex = -1
ddlRespOffice.SelectedInde
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
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
ASKER
flavo,
thanks it worked. And thanks to all the others that posted suggestions.
thanks it worked. And thanks to all the others that posted suggestions.
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
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.Na
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