Results 1 to 3 of 3

Thread: [RESOLVED]VB .Net 2005 - How to avoid duplicate Select Case (Noob alert)

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    13

    Resolved [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:
    1. Private Sub cmdDo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDo.Click
    2.         txtOutput.Text = "Please wait..."
    3.         strOutput = ""
    4.         strInput = txtInput.Text
    5.         intInLength = txtInput.Text.Length
    6.         i = 1
    7.         For i = 1 To Len(strInput) Step 8
    8.             strCurChar = Mid(strInput, i, 8)
    9.             Select Case strCurChar
    10.                 Case Is = "a"
    11.                     strCurChar = "bogus text"
    12.  
    13. 'all other cases here
    14.  
    15.                 Case Else
    16.                     strCurChar = ""
    17.             End Select
    18.             strOutput = strOutput & strCurChar
    19.             txtOutput.Text = strOutput
    20.         Next
    21.     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:
    1. Private Sub cmdDoFromCB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDoFromCB.Click
    2.         txtInput.Text = Clipboard.GetText()
    3.         RaiseEvent Click(cmdDo)
    4.     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.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    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

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    13

    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
  •  



Click Here to Expand Forum to Full Width