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

KitaYama

Well-known member
Local time
Today, 22:19
Joined
Jan 6, 2022
Messages
1,541
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: 138
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, 21:19
Joined
May 7, 2009
Messages
19,245
the ComboStyle of the first combo is set as cbtDropdownList (i think not allowed to edit?)
while the second is cbtDropdownEdit.

it doesn't show the Value you selected because what is being shown is the Button number you clicked.
 

KitaYama

Well-known member
Local time
Today, 22:19
Joined
Jan 6, 2022
Messages
1,541
the ComboStyle of the first combo is set as cbtDropdownList (i think not allowed to edit?)
while the second is cbtDropdownEdit.

it doesn't show the Value you selected because what is being shown is the Button number you clicked.
 

KitaYama

Well-known member
Local time
Today, 22:19
Joined
Jan 6, 2022
Messages
1,541
the ComboStyle of the first combo is set as cbtDropdownList (i think not allowed to edit?)
while the second is cbtDropdownEdit.

it doesn't show the Value you selected because what is being shown is the Button number you clicked.
In Both case this same code has been used:

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

IF the combo is in edit mode the value is shown. If the combo can not be edited, the value is empty.
My question is why when the combo is set to not to be editable, the value is empty.
In Both case, the same function from class is executed.
 

moke123

AWF VIP
Local time
Today, 09:19
Joined
Jan 11, 2013
Messages
3,920
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.
I spent days going through the thread I posted above. It gets much easier to understand over time and experimenting.
 

isladogs

MVP / VIP
Local time
Today, 14:19
Joined
Jan 14, 2017
Messages
18,226
Perhaps I'm missing the point here but the Combo Box example always shows blue due to this line of code:
Code:
.ComboSetInitialItem 0    '// Selected Item

The result from the Edit Combo Box isn't saved for future use
 

KitaYama

Well-known member
Local time
Today, 22:19
Joined
Jan 6, 2022
Messages
1,541
I spent days going through the thread I posted above. It gets much easier to understand over time and experimenting.
Well, you have a good knowledge of programming in vba.
I don't even understand what does 4294967295# or &H7FFFFFFF in following code means.

Code:
    y = value And 4294967295#
    If (y > &H7FFFFFFF) Then
        x = CLng(y - 4294967296#)
        x2 = value / 4294967296# - 1
    Else
        x = CLng(y)
        x2 = value / 4294967296#
    End If
 

KitaYama

Well-known member
Local time
Today, 22:19
Joined
Jan 6, 2022
Messages
1,541
Perhaps I'm missing the point here but the Combo Box example always shows blue due to this line of code:
Code:
.ComboSetInitialItem 0    '// Selected Item

The result from the Edit Combo Box isn't saved for future use
That is the default selected item. You can select some other color and click OK.
You'll notice the combo index changes.

The default is also used in checkboxes, listboxes, option boxes in other tabs.
 

isladogs

MVP / VIP
Local time
Today, 14:19
Joined
Jan 14, 2017
Messages
18,226
Yes I know that ... but it still won't pick up your choice from the other example

If you are interested, I used a few examples from Kevin Bell's task dialog code (with permission) as part of my example app:
 

sonic8

AWF VIP
Local time
Today, 15:19
Joined
Oct 27, 2015
Messages
998
IF the combo is in edit mode the value is shown. If the combo can not be edited, the value is empty.
My question is why when the combo is set to not to be editable, the value is empty.
In Both case, the same function from class is executed.
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.

There might be an alternative way to retrieve the text displayed, but I don't know what it might be.

As you cannot add your own custom text to the non-edit ComboBox, there is no need to retrieve the text of the combo box.
 

sonic8

AWF VIP
Local time
Today, 15:19
Joined
Oct 27, 2015
Messages
998
Is there any way I can reach him?
There is a "Contact" section on the website you linked to.

I'm desperate to make this work.
What exactly is your problem? As stated in my previous post, with the non-edit example there is no option for the user to add his own text. So, you can simply use the index of the selected combo box value to get to the text you added to the combo box when initializing the dialog.
 

KitaYama

Well-known member
Local time
Today, 22:19
Joined
Jan 6, 2022
Messages
1,541
As you cannot add your own custom text to the non-edit ComboBox,
I can. The following adds " test" to the list.

Code:
        Do Until rs.EOF
            .ComboAddItem rs!Color
            rs.MoveNext
        Loop
        .ComboAddItem "test"
        .ShowDialog
 

KitaYama

Well-known member
Local time
Today, 22:19
Joined
Jan 6, 2022
Messages
1,541
What exactly is your problem?
I want to show a combo box that's not editable and when the user selects an item, I want to work on selected item.
I need to retrieve what the user has selected.

But .ResultComboText is empty if the combo box is un-editable.
 

isladogs

MVP / VIP
Local time
Today, 14:19
Joined
Jan 14, 2017
Messages
18,226
Why do you need a task dialog message for this?
Suggest you create your own customised message form for this purpose
 

KitaYama

Well-known member
Local time
Today, 22:19
Joined
Jan 6, 2022
Messages
1,541
Why do you need a task dialog message for this?
Suggest you create your own customised message form for this purpose
With all respects, I don't think it's the answer to my question.

Yes I know I can always use a custom form for what I need.
My question was why when the combo is set to be un-editable the value is empty.
 

sonic8

AWF VIP
Local time
Today, 15:19
Joined
Oct 27, 2015
Messages
998
I can. The following adds " test" to the list.
Let me clarify what I meant: The user cannot add a completely new text by typing in the combo box.

I want to show a combo box that's not editable and when the user selects an item, I want to work on selected item.
I need to retrieve what the user has selected.
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.
But .ResultComboText is empty if the combo box is un-editable.
While explaining the technical cause for this, I didn't fail to notice the mere fact. ;-)
 

Users who are viewing this thread

Top Bottom