Computing.Net > Forums > Programming > VB6 Question

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

VB6 Question

Reply to Message Icon

Name: Sci-Guy
Date: September 14, 2003 at 22:54:05 Pacific
OS: XP Pro
CPU/Ram: Athlon 1800XP T'bred/512M
Comment:

I have a form on which I want the user, at runtime, to be able to change the caption property of a number of command buttons. I want the user to be able to choose a command button from a drop-down combo box, listed by current caption. I also want the command buttons' caption property to be updated in the combo box. Can anyone help?



Sponsored Link
Ads by Google

Response Number 1
Name: Chi Happens
Date: September 15, 2003 at 15:16:38 Pacific
Reply:

So where are you having problems? How far have you gotten?

If you have NO knowledge of VB6, here are some ideas to put you in right direction:

1) Use a collection of buttons (meaning Command1(0) Command1(1) Command1(2)) so that it is easier to program.

2) A combo box contains a collection of list items, you can access (edit/remove) the list items by using their index.

3) Using the two idea above you can use a for loop to iterate through the captions.

Combo1.Clear
For Index = 0 To Command1.Count -1
    Combo1.List(Index) = Command1(Index).Caption
Next Index

4) Finally, you assign the caption like:
Command1(Index).Caption = "Some Caption" ' This can be a variable as well, so if you place an edit box on the form and fill it with the text of the Combo box selected item, you would assign it back to the command button like:
Command1(Index).Caption = Text1.Text

Hope this helps, if you have an actual issue, post it, I can help.

Chi Happens


0

Response Number 2
Name: Sci-Guy
Date: September 15, 2003 at 22:41:25 Pacific
Reply:

Chi,
Thanks for your reply.

I was a little tired when I posted, hence the general lack of specifics in my post.

Yes, I have used a collection of buttons and the For loop.

My problem is that I want the user to enter (in a text box) a new caption for the button that was chosen from the combo box. No matter what I do, I can only change the caption of Command1(0).

How can I make the change apply only to the button that was chosen from the combo box?

As for the caption being updated in the combo list, I have an idea that I'd like to try before asking for help with it (I think this should be rather simple to do).



0

Response Number 3
Name: borelli35
Date: September 16, 2003 at 00:17:00 Pacific
Reply:

Are you deriving your index value from the combo box and then using that value to reference/sub-script command1(?) or am I mis-understanding what you have done so far?

borelli35


0

Response Number 4
Name: Sci-Guy
Date: September 16, 2003 at 06:10:58 Pacific
Reply:

I've managed to get this working on a form that has a collection of four command buttons. Here's what I had to do to get it working:
If Combo1.Text = Combo1.List(0) Then
Command1(0).Caption = Text1.Text
ElseIf Combo1.Text = Combo1.List(1) Then
Command1(1).Caption = Text1.Text
ElseIf Combo1.Text = Combo1.List(2) Then
Command1(2).Caption = Text1.Text
ElseIf Combo1.Text = Combo1.List(3) Then
Command1(3).Caption = Text1.Text
End If
I'm planning on eventually having a form with a collection of 24 buttons that the user can change the caption on.
Is there a better way to do this?


0

Response Number 5
Name: AlwaysWillingToLearn
Date: September 17, 2003 at 08:26:18 Pacific
Reply:

Hello im not sure if you have solved this problem but i have made a way in which this can be achieved. basically you put anything you like within the combo box, but i presume u will put the name of the buttons,
ie command1(0), command1(1) etc.

The way i have chosen uses the index value from the combo box, so for example if the first name within your combo bo is
command1(0), the index value you would have clicked is (0).

This index is stored within a variable, which is of type public. then you may put some text within text1 and press the 'Go' or 'Ok' button.

this will then change the appropriate buttons caption.

''''''''''CODE''''''''
Public TheIndex

'Note that these values can also be read into the combo box at design time

Private Sub Form_Load()
Combo1.AddItem "Command1(0)", 0
Combo1.AddItem "Command1(1)", 1
Combo1.AddItem "Command1(2)", 2
End Sub

Private Sub Combo1_Click()
TheIndex = Combo1.ListIndex
End Sub

Private Sub Command2_Click()
Command1(TheIndex).Caption = Text1.Text
End Sub

email me and Let me know if you like it i would appreciate that.
Have a nice day :)


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: VB6 Question

easy VB6 questions www.computing.net/answers/programming/easy-vb6-questions/5807.html

Simple VB6 question www.computing.net/answers/programming/simple-vb6-question/14752.html

VB6 Question www.computing.net/answers/programming/vb6-question/10483.html