Results 1 to 22 of 22

Thread: (RESOLVED) - button captions - please help

  1. #1

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Question (RESOLVED) - button captions - please help

    Hi,

    Ok, so I have 2 forms.. I'll call them "form A" & "form B"

    "Form A" has 72 buttons in an array - don' ask lol.. just bare with it please.

    So it doesn't matter which button I click, "form B" will show.

    "Form B" has a textbox and a button.. the issue I am having is whatever button I clicked on "form A", is changing that particular button caption through "form B".

    When I try, I can only change the 1st one or all of them.. what I want to do is change the one I clicked on.

    Thanks for the help in advance
    Last edited by elRuffsta; Sep 11th, 2014 at 10:00 PM.

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: button captions - please help

    Does form B have 72 buttons as well?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Re: button captions - please help

    No, just a textbox and a button...

  4. #4
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: button captions - please help

    What code are you using at the moment?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  5. #5

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Re: button captions - please help

    Main.command1(index).caption = text1.text which only changes the first one

    And if I do the for I = 0 to 71... I change all the buttons

  6. #6
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: button captions - please help

    I think you meant bear. Too darn cold here tonight to be taking my clothes off for a programming question.

  7. #7

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Re: button captions - please help

    Lol yeah..

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: button captions - please help

    I'm going to guess it's because Index is set to 0... it doesn't have the correct value.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: button captions - please help

    This is the only way I could get it to work.

    Main
    Code:
    Option Explicit
    
    Private Sub Command1_Click(index As Integer)
     Form2.Command1Click (index)
     Form2.Show
    End Sub
    Form2
    Code:
    Option Explicit
    Public Sub Command1Click(index As Integer)
     Main.Command1(index).Caption = Text1.Text
    End Sub
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  10. #10
    Addicted Member
    Join Date
    Jul 2014
    Posts
    176

    Re: button captions - please help

    Name:  Untitled.jpg
Views: 193
Size:  16.4 KB

    Code for Form1:

    VB Code:
    1. Option Explicit
    2. Public cmdindex As Integer
    3.  
    4. Private Sub cmd_Click(Index As Integer)    
    5.     Me.cmdindex = Index
    6.     Form2.Show
    7. End Sub

    Code for Form2:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Form1.cmd(Form1.cmdindex).Caption = Me.Text1.Text
    3. End Sub
    Last edited by terry002; Sep 11th, 2014 at 09:36 PM.
    If I had helped you...

    Don't forget to mark your Inquiry as RESOLVED...

    I will be glad if you can also give me some Reputation points in helping you (by Clicking Rate This Post)...

    Happy VB Coding Everyone!

  11. #11

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Re: button captions - please help

    Hmm... doesn't work for me..

    I'll have to post my code tomorrow.. maybe seeing that, it will help.

    Right now I do not have internet access, I'm using my phone to be here on the forum

  12. #12
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: button captions - please help

    Quote Originally Posted by terry002 View Post
    Code for Form2:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Form1.cmd(Form1.cmdindex).Caption = Me.Text1.Text
    3. End Sub
    Not quite!

    Code:
        Private Sub Command1_Click()
            Main.Command1(Main.cmdindex).Caption = Me.Text1.Text
        End Sub
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  13. #13

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Re: button captions - please help

    Nice! Ty very much

    Ty everyone for helping

  14. #14
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: button captions - please help

    Quote Originally Posted by elRuffsta View Post
    Nice! Ty very much

    Ty everyone for helping
    Have you "Resolved" the issue?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  15. #15

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Re: (RESOLVED) - button captions - please help

    Yes

    Now tomorrow is gonna come the fun part of this project.. "database"

  16. #16
    Addicted Member
    Join Date
    Jul 2014
    Posts
    176

    Re: button captions - please help

    Quote Originally Posted by Nightwalker83 View Post
    Not quite!
    ...????

    Programming has a vast way of solutions...

    It depends how you understand and how you approach it... As long as you know what you are doing.
    If I had helped you...

    Don't forget to mark your Inquiry as RESOLVED...

    I will be glad if you can also give me some Reputation points in helping you (by Clicking Rate This Post)...

    Happy VB Coding Everyone!

  17. #17
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: (RESOLVED) - button captions - please help

    Edit: Modified in response to techgnome's reply. See quote in following post for original comment and code.

    Form1 Code:
    Code:
    Private Sub Command1_Click(Index As Integer)
      Form2.Show vbModal, Me
      If Form2.DoChange Then Command1(Index).Caption = Form2.NewCaption
      Unload Form2
    End Sub
    Form2 Code:
    Code:
    Option Explicit
    
    Private blnDoChange As Boolean
    
    Property Get DoChange() As Boolean
      DoChange = blnDoChange
    End Property
    
    Property Get NewCaption()
      NewCaption = Text1.Text
    End Property
    
    Private Sub Command1_Click()
      blnDoChange = True
      Hide
    End Sub
    
    Private Sub Command2_Click()
      blnDoChange = False
      Hide
    End Sub
    
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
      If UnloadMode = vbFormControlMenu Then
        Cancel = 1
        blnDoChange = False
        Hide
      End If
    End Sub
    Last edited by Logophobic; Sep 12th, 2014 at 06:14 AM.

  18. #18
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: (RESOLVED) - button captions - please help

    Quote Originally Posted by Logophobic View Post
    For what it's worth, Form2 should be Modal, and Form1 should reference a Form2 variable rather than Form2 referencing a Form1 variable.

    Form1 Code:
    Code:
    Private Sub Command1_Click(Index As Integer)
      Form2.Show vbModal, Me
      If Form2.DoChange Then Command1(Index).Caption = Form2.Text1.Text
      Unload Form2
    End Sub
    Form2 Code:
    Code:
    Option Explicit
    
    Public DoChange As Boolean
    
    Private Sub Command1_Click()
      DoChange = True
      Hide
    End Sub
    
    Private Sub Command2_Click()
      DoChange = False
      Hide
    End Sub
    
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
      If UnloadMode = vbFormControlMenu Then
        Cancel = 1
        DoChange = False
        Hide
      End If
    End Sub
    While that's better, it still results in tight coupling between the two forms. A best practice solution would have a property on Form2 that returns the value... rather than Form1 accessing the form2 textbox directly.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  19. #19
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: (RESOLVED) - button captions - please help

    Touche, and modified accordingly.

  20. #20
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: (RESOLVED) - button captions - please help

    Quote Originally Posted by Logophobic View Post
    Touche, and modified accordingly.
    Although it doesn't really make a difference, if you access a self-defined Public-Property of
    a certain Form-Class - or a selfdefined TextBox on that same Form-Class - both require
    that you use a concrete Form-Interface...

    That said, when working with small Dialogue-Forms which often are shown only modally,
    and have to return something to the caller - one can avoid using Hide or QueryUnload
    and whatnot in the modal-form by simply defining a Public Function on it, which
    internally also ensures the modal showing:

    e.g. into Form2 (the one which is shown modally - having the usual Cancel and an OK-Buttons):

    Code:
    Option Explicit
    
    Private mCaption As String
    
    Public Function ShowModalAndGetNewCaption(OwnerForm As Object, CurCaption As String) As String
      mCaption = CurCaption
        Show vbModal, OwnerForm
      ShowModalAndGetNewCaption = mCaption
    End Function
    
    Private Sub cmdOk_Click()
      mCaption = txtNewCaption.Text
      Unload Me
    End Sub
    
    Private Sub cmdCancel_Click()
      Unload Me
    End Sub

    And within the Calling Form an explicit instantiation (combined with a single method call) is possible:
    Code:
    Option Explicit
    
    Private Sub cmdArr_Click(Index As Integer)
      With New Form2
         cmdArr(Index).Caption = .ShowModalAndGetNewCaption(Me, cmdArr(Index).Caption)
      End With
    End Sub
    The With construct above ensures, that an entire new Form2-instance is created -
    and after the call (after running over End With) again absolutely destroyed.

    Olaf

  21. #21
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: (RESOLVED) - button captions - please help

    Quote Originally Posted by Schmidt View Post
    Although it doesn't really make a difference, if you access a self-defined Public-Property of
    a certain Form-Class - or a selfdefined TextBox on that same Form-Class - both require
    that you use a concrete Form-Interface...
    True... but at least from that point, you only care about the property. You shouldn't need to care if it's Textbox1, Textbox2, or some other data source.

    Quote Originally Posted by Schmidt View Post
    That said, when working with small Dialogue-Forms which often are shown only modally,
    and have to return something to the caller - one can avoid using Hide or QueryUnload
    and whatnot in the modal-form by simply defining a Public Function on it, which
    internally also ensures the modal showing:

    e.g. into Form2 (the one which is shown modally - having the usual Cancel and an OK-Buttons):

    Code:
    Option Explicit
    
    Private mCaption As String
    
    Public Function ShowModalAndGetNewCaption(OwnerForm As Object, CurCaption As String) As String
      mCaption = CurCaption
        Show vbModal, OwnerForm
      ShowModalAndGetNewCaption = mCaption
    End Function
    
    Private Sub cmdOk_Click()
      mCaption = txtNewCaption.Text
      Unload Me
    End Sub
    
    Private Sub cmdCancel_Click()
      Unload Me
    End Sub

    And within the Calling Form an explicit instantiation (combined with a single method call) is possible:
    Code:
    Option Explicit
    
    Private Sub cmdArr_Click(Index As Integer)
      With New Form2
         cmdArr(Index).Caption = .ShowModalAndGetNewCaption(Me, cmdArr(Index).Caption)
      End With
    End Sub
    The With construct above ensures, that an entire new Form2-instance is created -
    and after the call (after running over End With) again absolutely destroyed.

    Olaf
    I thought about that approach too, and I'd agree it's the best of the best practice... and is probably how it would be handled in the real world, but at the same time, I didn't want to potentially muddy things up with a concept the OP wouldn't be able to digest.

    I do like it though. It is elegant. And decouples the forms completely.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  22. #22
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: (RESOLVED) - button captions - please help

    I just realized that we are reinventing the wheel here.

    Code:
    Private Sub Command1_Click(Index As Integer)
      Dim NewCaption As String
      
      NewCaption = InputBox("Enter new caption")
      If NewCaption <> "" Then Command1(Index).Caption = NewCaption
    End Sub

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