Results 1 to 7 of 7

Thread: [RESOLVED] Command Button Help

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Resolved [RESOLVED] Command Button Help

    See if i had one command button how would i get it to change captions when it has been clicked and when its been clicked it changed name and also opens up another new form i had this code in mind but it dosent seem to work.


    VB Code:
    1. Private Sub Command2_Click()
    2. If Command2.Caption = "Search" Then
    3. Form2.Show
    4. ElseIf
    5. If Command2.Caption = "Stop Search" Then
    6. Form3.Show
    7. End If
    8. End Sub

  2. #2
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Command Button Help

    VB Code:
    1. Private Sub Command2_Click()
    2. If Command2.Caption = "Search" Then
    3. [B]Command2.Caption = "Stop Search"[/B]
    4. Form2.Show
    5. ElseIf
    6. If Command2.Caption = "Stop Search" Then
    7. [B]Command2.Caption = "Search"[/B]
    8. Form3.Show
    9. End If
    10. End Sub

  3. #3
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Command Button Help

    VB Code:
    1. Private Sub Command2_Click()
    2. If Command2.Caption = "Search" Then
    3. Form2.Show
    4. 'ElseIf  <-- This should be End If
    5. End If
    6.  
    7. If Command2.Caption = "Stop Search" Then
    8. Form3.Show
    9. End If
    10. End Sub
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  4. #4
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Command Button Help

    VB Code:
    1. Private Sub Command2_Click()
    2. If Command2.Caption = "Search" Then
    3. Command2.Caption = "Stop Search"
    4. Form2.Show
    5. End If
    6. If Command2.Caption = "Stop Search" Then
    7. Command2.Caption = "Search"
    8. Form3.Show
    9. End If
    10. End Sub
    Its because you wern't setting the caption after it had been clicked.

    edit: also the end if is missing as pradeep said
    Chris

  5. #5
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Command Button Help

    Oops missed the ElseIf part

  6. #6
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Command Button Help

    Quote Originally Posted by DigiRev
    Oops missed the ElseIf part
    And I missed the caption part

    Anyways, You don't need 2 If's, one is sufficient.

    VB Code:
    1. Private Sub Command2_Click()
    2.     If Command2.Caption = "Search" Then
    3.         Command2.Caption = "Stop Search"
    4.         Form2.Show
    5.     Else
    6.         Command2.Caption = "Search"
    7.         Form3.Show
    8.     End If
    9. End Sub

    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: [RESOLVED] Command Button Help

    thanks guys

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