|
-
Jun 6th, 2006, 03:19 PM
#1
Thread Starter
New Member
[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!
Last edited by S3CUR3; Jun 6th, 2006 at 05:20 PM.
-
Jun 6th, 2006, 04:36 PM
#2
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.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Jun 6th, 2006, 05:19 PM
#3
Thread Starter
New Member
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.
Using VB .Net 2005 Express.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|