PAGING dictionary array

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

PAGING dictionary array

Post by sal21 »

Based the image attached possible to create a paging of a dictonary array?

Note:
The label is named LTEST, when appaer the actually value of paging item
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78481
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: PAGING dictionary array

Post by HansV »

Please provide more detailed information.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

Re: PAGING dictionary array

Post by sal21 »

In image have 4 button.

> Goto the next item of array, >> goto the last item of array , < bak one item of array,<< first item of array....ecc

During the sroll, show in label the current item value.

User avatar
HansV
Administrator
Posts: 78481
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: PAGING dictionary array

Post by HansV »

That's not really detailed information...
Let's say you have an array MyArray.

Code: Select all

Dim MyIndex As Long

Private Sub cmdBack_Click()
    If MyIndex > LBound(MyArray) Then
        MyIndex = MyIndex - 1
        LTEST.Caption = MyArray(MyIndex)
    End If
End Sub

Private Sub cmdFirst_Click()
    MyIndex =LBound(MyArray)
    LTEST.Caption = MyArray(MyIndex)
End Sub

Private Sub cmdLast_Click()
    MyIndex = UBound(MyArray)
    LTEST.Caption = MyArray(MyIndex)
 End Sub

Private Sub cmdNext_Click()
    If MyIndex < UBound(MyArray) Then
        MyIndex = MyIndex + 1
        LTEST.Caption = MyArray(MyIndex)
    End If
End Sub
Best wishes,
Hans

User avatar
SpeakEasy
4StarLounger
Posts: 550
Joined: 27 Jun 2021, 10:46

Re: PAGING dictionary array

Post by SpeakEasy »

Why not use a scrollbar control?

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

Re: PAGING dictionary array

Post by sal21 »

SpeakEasy wrote:
19 Mar 2023, 14:56
Why not use a scrollbar control?
Never used.

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

Re: PAGING dictionary array

Post by sal21 »

HansV wrote:
16 Mar 2023, 21:13
That's not really detailed information...
Let's say you have an array MyArray.

Code: Select all

Dim MyIndex As Long

Private Sub cmdBack_Click()
    If MyIndex > LBound(MyArray) Then
        MyIndex = MyIndex - 1
        LTEST.Caption = MyArray(MyIndex)
    End If
End Sub

Private Sub cmdFirst_Click()
    MyIndex =LBound(MyArray)
    LTEST.Caption = MyArray(MyIndex)
End Sub

Private Sub cmdLast_Click()
    MyIndex = UBound(MyArray)
    LTEST.Caption = MyArray(MyIndex)
 End Sub

Private Sub cmdNext_Click()
    If MyIndex < UBound(MyArray) Then
        MyIndex = MyIndex + 1
        LTEST.Caption = MyArray(MyIndex)
    End If
End Sub
hi. bro.
confused...
i have a dictionary item, not a tiical array, sorry.

thi is my code:

Code: Select all

Private Sub MSFlexGrid1_Click()

    If CLng(Me.LNRAR.Caption) >= 1 Then

        With MSFlexGrid1

            .Redraw = False

            R = .MouseRow
            C = .Col

            .Row = R
            .Col = C

            If R >= 1 Then

                Select Case C

                Case 0

                    If .CellPicture = Me.Image1.Picture Then
                        Set .CellPicture = Me.Image2.Picture
                        VALORE = .TextMatrix(R, C + 1)
                        MYDICT.Add R, VALORE
                        .TextMatrix(R, 10) = 2
                        Me.LNR.Caption = CLng(Me.LNR.Caption) + 1
                    Else
                        Set .CellPicture = Me.Image1.Picture
                        VALORE = .TextMatrix(R, C + 1)
                        MYDICT.Remove R
                        .TextMatrix(R, 10) = 1
                        Me.LNR.Caption = CLng(Me.LNR.Caption) - 1
                    End If

                Case 1

                    If .TextMatrix(R, 9) > "" Then
                        IMG = .TextMatrix(R, 9)
                        Call APRI_IMG
                    Else
                        IMG = "NONDISP.jpg"
                        Call APRI_IMG
                    End If

                End Select

                .Redraw = True

            End If

        End With

    End If

End Sub

User avatar
HansV
Administrator
Posts: 78481
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: PAGING dictionary array

Post by HansV »

Sorry, I have no idea.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

Re: PAGING dictionary array

Post by sal21 »

HansV wrote:
19 Mar 2023, 18:50
Sorry, I have no idea.
in this case possible to fill Marray under:

MYDICT.Add R, VALORE
'Here fill Myrray based VALORE (peraphs with a Redimpreserve?)

note:
maintain naturally the part of dictionary for other use

User avatar
HansV
Administrator
Posts: 78481
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: PAGING dictionary array

Post by HansV »

After you have filled MYDICT, you can get an array of all items:

MYARRAY = MYDICT.Items
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

Re: PAGING dictionary array

Post by sal21 »

HansV wrote:
20 Mar 2023, 09:20
After you have filled MYDICT, you can get an array of all items:

MYARRAY = MYDICT.Items
WOW!!! tks

quicly remove item in array list based VALORE, without a for next?

is this part:
...
VALORE = .TextMatrix(R, C + 1)
MYDICT.Remove R
'...
'here the code to remove item VALORE from Myarray just filled
...

User avatar
HansV
Administrator
Posts: 78481
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: PAGING dictionary array

Post by HansV »

Just get MYDICT.Items again.
Best wishes,
Hans

User avatar
SpeakEasy
4StarLounger
Posts: 550
Joined: 27 Jun 2021, 10:46

Re: PAGING dictionary array

Post by SpeakEasy »

Here's how you might use a scrollbar

Code: Select all

'Assumes a form with a Label called Label1 and an hScroll called HCroll1

Option Explicit
Private MyDic As Dictionary

Private Sub Form_Load()
    InitialiseExample
End Sub

Private Sub InitialiseExample()
    Set MyDic = PopulateDictionary ' get an example dictionary
    SetupScrollbar HScroll1, MyDic ' Set up scrollbar appropriate for this dictionary
End Sub

 ' This is for example. Obviously you will already have a dictionary, so you would not need to do this bit
Private Function PopulateDictionary() As Dictionary
    Set PopulateDictionary = New Dictionary
    Dim lp As Long
    For lp = 1 To 100
        ' In this example dictionary is holding strings, but could be anything, e.g. Picture objects
        PopulateDictionary.Add "Label " & lp, "Dictionary Item " & lp
    Next
End Function

' Sets up an HScroll to scroll appropriately for a specific dictionary object
Private Sub SetupScrollbar(targetscroll As HScrollBar, targetdic As Dictionary)
        With targetscroll
            .Max = targetdic.Count - 1
            .Min = 0 ' lowest element of a Dictionary
            .SmallChange = 1
            .LargeChange = .Max - .Min
            .Value = .Max
            .Value = .Min  ' cheap way to force a change event
    End With
End Sub

' Show appropriate dictionary item when we scroll
Private Sub HScroll1_Change()
    Label1.Caption = MyDic.Items(HScroll1.Value)
End Sub