Solved Are you good at writing class? Solve this puzzle... (1 Viewer)

KitaYama

Well-known member
Local time
Today, 09:49
Joined
Jan 6, 2022
Messages
1,490
It may be one of the most unusual requests you've ever seen.

I've spent a lot of time to digest this class, but it's out of my league. It may be a simple one for some of you, but for sure a beast for me.
So I really appreciate any kind of help.

If you want to help :
  1. Open the attached database. It's downloaded from here. It's a free utility for different type of messages for Access. If you don't trust attached file, you can download it from its original site.
  2. Select Really Advanced tab above the form
  3. Select Combo Box tab from left.
  4. Click Edit Combo Box button. You'll receive an editable combo box. Select a color from combo box and click OK. At the right side you will see the selected color in front of Value. (this one has no problem)
  5. Now click First button. (Comb Box). You receive an un-editable combo box. Again select a color and click OK. This one doesn't show the value you've selected.
I've been trying to find out why this button doesn't show the value I've selected.
If you click ... buttons in front of each button, you will jump to the procedure.


Any kind of help is much appreciated.
Again my sincere apologies for such an uncommon request.
 

Attachments

  • VBATaskDialog64 201015.accdb
    1.6 MB · Views: 136
Last edited:
Solution
when there is no selection from the combo, error will result, so modify the Property again:
Code:
'arnelgp
'Public Property Get ResultComboText() As String: ResultComboText = sComboText: End Property
Public Property Get ResultComboText() As String
Dim idx As Long
idx = CLng(Nz(nComboIdx, -1))
If idx > -1 Then
    ResultComboText = aComboItems(idx).sText
Else
    ResultComboText = ""
End If
End Property

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:49
Joined
May 7, 2009
Messages
19,169
i don't see anomaly on the sample.
it is doing exactly as it should.

the first row (label) shows the Button you clicked.
the second row shows the Index number.
 

KitaYama

Well-known member
Local time
Today, 09:49
Joined
Jan 6, 2022
Messages
1,490
i don't see anomaly on the sample.
it is doing exactly as it should.

the first row (label) shows the Button you clicked.
the second row shows the Index number.
In both cases, (editable and not editable) the same code is used to retrieve the selected item.

Me.lblButton.Caption = .ResultMain
Me.lblIndex.Caption = .ResultComboIndex
Me.lblValue.Caption = .ResultComboText

If the combo is editable, .ResultcomboText is not empty.
If the combo is not editable, .ResultcomboText is empty.

Are you trying to tell me that :
if the combo is editable, I can retrieve the value (selected item)
BUT
if the combo is not editable I HAVE to use the index of selected item and with the internal array read the selected text? (per @sonic8 's previous post)
 
Last edited:

KitaYama

Well-known member
Local time
Today, 09:49
Joined
Jan 6, 2022
Messages
1,490
You can do this by using the ResultComboIndex property. As you (as developer) added all selectable options to the drop down, you can use the selected index to retrieve the text belonging to that index. The internal aComboItems array in the class module can be used to easily implement this.
@sonic8
I'm really sorry for insisting. I'm just trying to learn something out of this thread.
Do you mean it's normal that if the combo is editable I have access to its value (selected item), but if the combo is not editable, I don't have access to its value and I have to use its selectedindex and another array to find out the selected item?

Can you briefly explain why these two modes are so much different, even if the initializing and filling and showing the dialogue is exactly the same?

I really appreciate your help.
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:49
Joined
May 7, 2009
Messages
19,169
here you try this and see the change i made in ResultComboText property of the Class.
 

Attachments

  • VBATaskDialog64 201015.accdb
    2.2 MB · Views: 90

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:49
Joined
May 7, 2009
Messages
19,169
when there is no selection from the combo, error will result, so modify the Property again:
Code:
'arnelgp
'Public Property Get ResultComboText() As String: ResultComboText = sComboText: End Property
Public Property Get ResultComboText() As String
Dim idx As Long
idx = CLng(Nz(nComboIdx, -1))
If idx > -1 Then
    ResultComboText = aComboItems(idx).sText
Else
    ResultComboText = ""
End If
End Property
 
Solution

sonic8

AWF VIP
Local time
Today, 01:49
Joined
Oct 27, 2015
Messages
998
[/QUOTE]
Can you explain what did you change? Where was the correction you did?
@KitaYama, I don't want to be patronizing, but please pay some more attention to what people are writing in regard to your question.
@arnelgp already said where he made a change:
here you try this and see the change i made in ResultComboText property of the Class.

Can you briefly explain why these two modes are so much different, even if the initializing and filling and showing the dialogue is exactly the same?
Again, I already explained that:
The value of the ResultComboText property is retrieved in the GetComboTextW function using SendMessageW - WM_GETTEXT.
This only works when the ComboBox32 control class displays an Edit control with the text. The "Edit Combo Box" example makes the ComboBox display that Edit control, while the "Combo Box" example doesn't.
To visualize the difference, here are two screenshots from the window hierarchy in Spy++:
This is the dialog with the editable combo box:
1655390304764.png

Here it is with the non-editable combo box:
1655390272508.png


The text is retrieved from the Edit control marked in red.
Please note: This Edit control does not exist when the non-editable combo box is displayed therefore no text can be retrieved from the control.
 

KitaYama

Well-known member
Local time
Today, 09:49
Joined
Jan 6, 2022
Messages
1,490
but please pay some more attention to what people are writing in regard to your question.
I'm doing my best, but unfortunately it's hard to understand all the given advices with my limited knowledge.
That was why I asked for a little more explanation.

I think the image you posted above from spy++ clarifies what you meant.
thanks for your time and help.
 

isladogs

MVP / VIP
Local time
Today, 00:49
Joined
Jan 14, 2017
Messages
18,186
Was this just a learning exercise?
Sorry to labour the point but I still can't see any reason for using a task dialog for this purpose when it is so simple to achieve using a standard combo on a form with an after update event:

1655392716850.png
 

KitaYama

Well-known member
Local time
Today, 09:49
Joined
Jan 6, 2022
Messages
1,490
I still can't see any reason for using a task dialog for this purpose when it is so simple to achieve using a standard combo on a form with an after update event:
May I ask you a question?
If for some reasons, you have VBATaskDialog class in your database, do you go with creating your own simple form, or use the already existing resources you have (in TaskDialog)?

Or what if you need to show a checkbox somewhere else? or an option box? You add one form after another? Or use what TaskDialog has to offer?
The whole point of using a class is that although it may be harder to maintain, but once you have it and everything is set to work as you wish, it's simpler to reuse it over and over and there's no need to add forms and manage things yourself. You simply call an instance of the class and it will do all the job.

To be honest, everything that TaskDialog offers, can be made and used with custom forms. If you look for simplicity and don't care adding numerous forms for each situation, then why using it at all?
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 00:49
Joined
Jan 14, 2017
Messages
18,186
I use task dialogs when they can do something that can't be done using a standard method. In this case it can be done with one line of code.

For info, I contacted Kevin Bell when I tried to use several features from different task dialog examples in one form.
His advice on that occasion. ...create your own customised form to do so. 😏
 

Users who are viewing this thread

Top Bottom