Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using dialog button to refresh dialog 1

Status
Not open for further replies.

streetprog

Technical User
Nov 9, 2006
41
US
I have a rather extensive dialog box I'm working on that has a number of textboxes, droplistboxes, and checkboxes.

For one of my textboxes, I want to refresh the Dialog Box so that several droplistboxes become visible or invisible based on the input in the textbox. This works fine, but only if the user selects another droplistbox or checks a checkbox (Case 2 in FileDlgFunction). Is there a way that I can use a button to cause the dialog to refresh but keep the data I've already updated? If I click the button now, it just closes out of the dialog.

In my code, I want ".RefreshButton" to have it check for:

Code:
If DlgText(86) = "1" then DlgVisible 80, 1 : DlgVisible 81, 0 : DlgVisible 82, 0 : DlgVisible 83, 0 : DlgVisible 84, 0

I've removed a lot of the code for purposes of brevity the Identifier$ numbers will be off but I've noted what they refer to.

Code:
Declare Function FileDlgFunction(identifier$, action, suppvalue)

Function FileDlgFunction(identifier$, action, suppvalue)

    Select Case action
        Case 1                                      'dialog started
        Case 2                                      'user changed control or clicked a button
            If DlgControlID(identifier$) = 96 then  'this is where the button is clicked, but it doesn't function correctly
                If DlgText(86) = "1" then DlgVisible 80, 1 : DlgVisible 81, 0 : DlgVisible 82, 0 : DlgVisible 83, 0 : DlgVisible 84, 0 
            End If
    End Select
End Function

Sub Main()

Dim button as integer
Dim identifier$
Dim action as Integer
Dim suppvalue as Integer
Dim months         'List

months="  "+Chr$(9)+"Jan"+Chr$(9)+"Feb"+Chr$(9)+"Mar"+Chr$(9)+"Apr"+Chr$(9)+"May"+Chr$(9)+"Jun"+Chr$(9)+"Jul"+Chr$(9)+"Aug"+Chr$(9)+"Sep"+Chr$(9)+"Oct"+Chr$(9)+"Nov"+Chr$(9)+"Dec"

Begin Dialog dlgPick 50, 50, 430, 270, "Pick List", .FileDlgFunction
    ButtonGroup .ButtonGroup1
    Text 10, 175, 70, 10, "Info changes", .Text35
    DropListBox 70, 173, 33, 120, months, .DropListBox12  'These are 80-84
    DropListBox 105, 173, 33, 120, months, .DropListBox13
    DropListBox 140, 173, 33, 120, months, .DropListBox14
    DropListBox 175, 173, 33, 120, months, .DropListBox15
    DropListBox 210, 173, 33, 120, months, .DropListBox16    
    Text 10, 160, 70, 10, "# per year", .Text36
    Textbox 70, 158, 18, 12, .text#PerYear      'This is 86

    Button 245, 174, 11, 10, "*", .RefreshButton    'This is 96
    OKButton 270, 243, 50, 12
    CancelButton 325, 243, 50, 12
End Dialog

Dim mydialog as dlgPick

nRet = Dialog(mydialog)

select case nRet
    case -1    
        'Click OK and it performs certain actions based on the selections made
    case 0
        exit sub

end select    

End Sub

Any help will be greatly appreciated!
 
If you just want it to change the number of drop-downs based on the number in the box, then you don't need a refresh button. Instead you can use Case 3.

Next thing, it's kind of a pain to call to the items by their number which is the reason why you can include an ID. The ID is case sensative, but use that.

.text#PerYear was causing an error on mine. I don't think you can use # in an ID so I removed it.

Code:
Function FileDlgFunction(identifier$, action, suppvalue)
    Select Case action
    Case 1
    Case 2
    Case 3
        sInfo = DlgText("textPerYear")
        If IsNumeric(sInfo) Then
            iInfo = CInt(sInfo)
        Else
            iInfo = 0
        End If
        j = 0
        For i = DlgControlID("DropListBox12") to DlgControlID("DropListBox16")
            j = j + 1
            DlgVisible i, 1
            If j > iInfo Then DlgVisible i, 0
        Next
    End Select
End Function

Sub Main()

Dim button as integer
Dim identifier$
Dim action as Integer
Dim suppvalue as Integer
Dim months         'List

months="  "+Chr$(9)+"Jan"+Chr$(9)+"Feb"+Chr$(9)+"Mar"+Chr$(9)+"Apr"+Chr$(9)+"May"+Chr$(9)+"Jun"+Chr$(9)+"Jul"+Chr$(9)+"Aug"+Chr$(9)+"Sep"+Chr$(9)+"Oct"+Chr$(9)+"Nov"+Chr$(9)+"Dec"

Begin Dialog dlgPick 50, 50, 430, 270, "Pick List", .FileDlgFunction
    ButtonGroup .ButtonGroup1
    Text 10, 175, 70, 10, "Info changes", .Text35
    DropListBox 70, 173, 33, 120, months, .DropListBox12
    DropListBox 105, 173, 33, 120, months, .DropListBox13
    DropListBox 140, 173, 33, 120, months, .DropListBox14
    DropListBox 175, 173, 33, 120, months, .DropListBox15
    DropListBox 210, 173, 33, 120, months, .DropListBox16    
    Text 10, 160, 70, 10, "# per year", .Text36
    Textbox 70, 158, 18, 12, .textPerYear
    OKButton 270, 243, 50, 12
    CancelButton 325, 243, 50, 12
End Dialog

Dim mydialog as dlgPick

nRet = Dialog(mydialog)
End Sub

Now, if you only want your dialogbox to remain open until the user tells it to close, you can set your function to true. You just have to remember to set it to false when something like OK or cancel is pressed.

Code:
Function FileDlgFunction(identifier$, action, suppvalue)
    FileDlgFunction = True
    Select Case action
    Case 1
    Case 2
        Select Case identifier
        Case "OKBtn","CancelBtn"
            FileDlgFunction = False
        End Select
    Case 3
        sInfo = DlgText("textPerYear")
        If IsNumeric(sInfo) Then
            iInfo = CInt(sInfo)
        Else
            iInfo = 0
        End If
        j = 0
        For i = DlgControlID("DropListBox12") to DlgControlID("DropListBox16")
            j = j + 1
            DlgVisible i, 1
            If j > iInfo Then DlgVisible i, 0
        Next
    End Select
End Function

Sub Main()

Dim button as integer
Dim identifier$
Dim action as Integer
Dim suppvalue as Integer
Dim months         'List

months="  "+Chr$(9)+"Jan"+Chr$(9)+"Feb"+Chr$(9)+"Mar"+Chr$(9)+"Apr"+Chr$(9)+"May"+Chr$(9)+"Jun"+Chr$(9)+"Jul"+Chr$(9)+"Aug"+Chr$(9)+"Sep"+Chr$(9)+"Oct"+Chr$(9)+"Nov"+Chr$(9)+"Dec"

Begin Dialog dlgPick 50, 50, 430, 270, "Pick List", .FileDlgFunction
    ButtonGroup .ButtonGroup1
    Text 10, 175, 70, 10, "Info changes", .Text35
    DropListBox 70, 173, 33, 120, months, .DropListBox12
    DropListBox 105, 173, 33, 120, months, .DropListBox13
    DropListBox 140, 173, 33, 120, months, .DropListBox14
    DropListBox 175, 173, 33, 120, months, .DropListBox15
    DropListBox 210, 173, 33, 120, months, .DropListBox16    
    Text 10, 160, 70, 10, "# per year", .Text36
    Textbox 70, 158, 18, 12, .textPerYear
    Button 245, 174, 11, 10, "*", .RefreshButton
    OKButton 270, 243, 50, 12, .OKBtn
    CancelButton 325, 243, 50, 12, .CancelBtn
End Dialog

Dim mydialog as dlgPick

nRet = Dialog(mydialog)
End Sub
 
Awesome! That was exactly what I needed. As for the ID's, I was able to get it to work with DlgFocus, but others were giving me a problem so I started using the ID's. They are a pain to use and change if you ever add in another line of code. Thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top