CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Select Case

  1. #1
    Join Date
    May 2001
    Posts
    155

    Select Case

    I have a toolbar with print,save,open, and new. but when i use select case, and i click on the button that says "new" it prints. What's wrong?

    --Ant
    --------------------------------------------------
    check out my newest freeware
    E-mail me at: [email protected]
    for the address

  2. #2
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Select Case

    Your select Case choices are wrong or incomplete.

    John G

  3. #3
    Join Date
    May 2001
    Posts
    155

    Re: Select Case

    How do you complete one?

    --Ant
    --------------------------------------------------
    check out my newest freeware
    E-mail me at: [email protected]
    for the address

  4. #4
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Select Case

    Make sure all the values you are looking for are in a Case statement. IF they are not and you have a "Case Else" then "Case Else" will catch any values passed to the Select statement that do not meet your criteria.
    If you are still having problems with your Select, post the code so someone can find out what you are doing wrong.

    John G

  5. #5
    Join Date
    May 2001
    Posts
    155

    Re: Select Case

    Inside the Toolbar Click event:

    Select Case tool
    Case new
    Dim f as Form2
    set f = new Form2
    f.show
    Case print
    Dim text
    text = Richtextbox1.text
    Printer.print Text
    Printer.enddoc
    Case save
    ' and it goes on and on
    Case else
    Msgbox "What!?"
    End Select




    --Ant
    --------------------------------------------------
    check out my newest freeware
    E-mail me at: [email protected]
    for the address

  6. #6
    Join Date
    Jan 2001
    Posts
    365

    Re: Select Case

    hi
    try this..
    i think u have to give double quot for the passing string . i mean new,print...

    Select Case tool
    Case "new"
    MsgBox "new"
    Case "print"
    MsgBox "print"
    Case "save"
    MsgBox "save"
    Case Else
    MsgBox "What!?"
    End Select




  7. #7
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Select Case

    A couple of suggested changes. Your select probably is not working because of the use or reserved words (ie print). I suspect you are using those words in your toolbuttons in which case it makes them strings. You need to encloise them in apostrophe's to use them as strings. Also when doing this you need to watch out for Upper/Lower case mixing. The lCase function will help in this regards.

    private Sub Command1_Click()
    Dim f as Form2 ' Moved
    Select Case LCase(tool) ' Modified
    Case "new" ' Modified
    set f = new Form2
    Dim text
    text = Richtextbox1.text
    Printer.print text
    Printer.EndDoc
    set f = nothing ' Added
    Case "save" ' Modified
    ' and it goes on and on
    Case else
    MsgBox "What!?"
    End Select
    End Sub




    John G

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

Featured