|
-
Sep 11th, 2014, 08:15 PM
#1
Thread Starter
Banned
(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.
-
Sep 11th, 2014, 08:19 PM
#2
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
-
Sep 11th, 2014, 08:21 PM
#3
Thread Starter
Banned
Re: button captions - please help
No, just a textbox and a button...
-
Sep 11th, 2014, 08:35 PM
#4
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
-
Sep 11th, 2014, 08:40 PM
#5
Thread Starter
Banned
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
-
Sep 11th, 2014, 08:41 PM
#6
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.
-
Sep 11th, 2014, 08:50 PM
#7
Thread Starter
Banned
Re: button captions - please help
-
Sep 11th, 2014, 08:58 PM
#8
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
-
Sep 11th, 2014, 09:21 PM
#9
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
-
Sep 11th, 2014, 09:33 PM
#10
Addicted Member
Re: button captions - please help

Code for Form1:
VB Code:
Option Explicit Public cmdindex As Integer Private Sub cmd_Click(Index As Integer) Me.cmdindex = Index Form2.Show End Sub
Code for Form2:
VB Code:
Private Sub Command1_Click() Form1.cmd(Form1.cmdindex).Caption = Me.Text1.Text 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! 
-
Sep 11th, 2014, 09:38 PM
#11
Thread Starter
Banned
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
-
Sep 11th, 2014, 09:41 PM
#12
Re: button captions - please help
 Originally Posted by terry002
Code for Form2:
VB Code:
Private Sub Command1_Click() Form1.cmd(Form1.cmdindex).Caption = Me.Text1.Text 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
-
Sep 11th, 2014, 09:57 PM
#13
Thread Starter
Banned
Re: button captions - please help
Nice! Ty very much
Ty everyone for helping
-
Sep 11th, 2014, 10:01 PM
#14
Re: button captions - please help
 Originally Posted by elRuffsta
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
-
Sep 11th, 2014, 10:31 PM
#15
Thread Starter
Banned
Re: (RESOLVED) - button captions - please help
Yes
Now tomorrow is gonna come the fun part of this project.. "database"
-
Sep 11th, 2014, 10:33 PM
#16
Addicted Member
Re: button captions - please help
 Originally Posted by Nightwalker83
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! 
-
Sep 12th, 2014, 05:50 AM
#17
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.
-
Sep 12th, 2014, 05:57 AM
#18
Re: (RESOLVED) - button captions - please help
 Originally Posted by Logophobic
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
-
Sep 12th, 2014, 06:16 AM
#19
Re: (RESOLVED) - button captions - please help
Touche, and modified accordingly.
-
Sep 12th, 2014, 08:07 AM
#20
Re: (RESOLVED) - button captions - please help
 Originally Posted by Logophobic
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
-
Sep 12th, 2014, 09:10 AM
#21
Re: (RESOLVED) - button captions - please help
 Originally Posted by Schmidt
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.
 Originally Posted by Schmidt
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
-
Sep 12th, 2014, 09:44 AM
#22
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|