[RESOLVED]VB .Net 2005 - How to avoid duplicate Select Case (Noob alert)
I'm writing a program that requires a huge Select Case loop. It analyzes each character of a string and, depending on what character it is, modifies a variable. Here's the first loop:
VB Code:
Private Sub cmdDo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDo.Click
txtOutput.Text = "Please wait..."
strOutput = ""
strInput = txtInput.Text
intInLength = txtInput.Text.Length
i = 1
For i = 1 To Len(strInput) Step 8
strCurChar = Mid(strInput, i, 8)
Select Case strCurChar
Case Is = "a"
strCurChar = "bogus text"
'all other cases here
Case Else
strCurChar = ""
End Select
strOutput = strOutput & strCurChar
txtOutput.Text = strOutput
Next
End Sub
I've got a second button that will do the same thing as the first loop, but instead of using the data from txtInput, it takes it from the clipboard. All that really needs to change is to assign strInput to the clipboard data instead of the textbox. In my mind, the best way to do this looks like this:
VB Code:
Private Sub cmdDoFromCB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDoFromCB.Click
txtInput.Text = Clipboard.GetText()
RaiseEvent Click(cmdDo)
End Sub
But VB gives me an error saying "Derived classes cannot raise base class events."
Hopefully someone with more experience can show me how to do this without copying the entire loop again into the second button's event. Any help is much appreciated.
Thanks!
Re: VB .Net 2005 - How to avoid duplicate Select Case (Noob alert)
Put the whole cmdDo_Click routine into a sub that's not an event. Have both cmdDo_Click and cmdDoFromCB_Click call that sub.
Re: VB .Net 2005 - How to avoid duplicate Select Case (Noob alert)
Wow, that was really simple. Thanks for your help (and patience)! I'd be lost without these forums.