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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to stop a dialog ( i think dialog box) closing?

Status
Not open for further replies.

smiler44

Technical User
Sep 18, 2009
83
0
0
GB
I have the code below that creates a dialog box, or at least I think its called a dialog box. It has a number of options that the user can select. How do I keep all the options available to the user after they have made a selection and pressed the OK button?
Currently once the user pushes the ok button all the options dissapeer.

thank you in advance
smiler44



sub create()
'''''''''''''''''''''''''''''''''''''''''
w = 183 'width of dialog
h = 400 '75 ' height of dialog

Begin Dialog Userdialog1 w, h, "Choose which note to check"

'Groupbox 5, 4, 97, 47, "" ' this puts a box around all the options
Optiongroup .Optiongroup1
Optionbutton 16,12,46,8,"1st", .OptionButton1
Optionbutton 16,30,67,8,"2nd", .OptionButton2
Optionbutton 16,48,67,8,"3rd", .OptionButton3
Optionbutton 16,66,67,8,"4th", .OptionButton4
Optionbutton 16,84,67,8,"5th", .OptionButton5
okbutton 125, 6, 54, 14
cancelbutton 125, 26, 54, 14

end dialog


dim mydialog1 as userdialog1
on error resume next
dialog mydialog1

if err=102 then
msgbox"macro ended"
exit sub
end if


gotohereOpt = mydialog1.optiongroup1

if gotohereOpt= 0 then
page = firstpagefound
row = firstrowfound
userchoice
exit sub

Elseif gotohereOpt= 1 then
page = secondpagefound
row = secondrowfound
userchoice
exit sub

Elseif gotohereOpt= 2 then
page = thirdpagefound
row = thirdrowfound
userchoice
exit sub

Elseif gotohereOpt= 3 then
page = fourthpagefound
row = fourthrowfound
userchoice
exit sub

Elseif gotohereOpt= 4 then
page = fithpagefound
row = fithtrowfound
userchoice
exit sub

end if

end sub
 
can you explain what you are trying to do?

if the user selects a button, what is supposed to happen next?

 
Hi,

Where do these variables get assignes?

firstpagefound
firstrowfound

And what does this procedure do?

userchoice


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
firstpagefound, secondpagefound etc are variables they will hold the page number and row number that a word has been found on. I have a sub routine that is looking through pages of notes for a word. when it finds the word it updates the variables with what page it found the word was found on and what row on the screen the word is on.
firstpagefound and firstrowfound are the fist time the word is found, secondpagefound and secondrowfound will be the second time the word is found and will be on a different page.
By default the variables are set to "", when the word is found the macro checks to see what the first pair of variables are, if they are "" then it changes the variables to contain the page number and row number.
the second time the word is found the marco checks the first pair if variables, this time they will not be "" and so the second pair of variables are checked as they will be "" these are then changed to contain the page and row of the second time the word is found.

Once the macro has finished it displays 20 options and the user can select which option they want to look at.
userchoice is a sub routine that displays the page associated with the option the user has selected.

once the user makes his choice the options "page" is closing or at least disappearing. This does not allow the user to make any more choices if they wish to look at a different option

hope my explanation makes sence

thanks you for your help
smiler44
 
Sure would be a LOT simpler, at least for me, to code this in Excel, where the form, or even the sheet can contain all this user interface data for future choices. IMNSHO, Extra VB is klunky at best. But then I've got strong opinions about this.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Skip,
if I use VBA from Excel will this mean I have to open an excel file to run the macro?
I am that close to having this run as I want or at least run to an acceptable standard that the user will be more then happy with. My code is long, more like a novel and there may well be a much better way even with Attachmate to do what I want.

If I (You [bigsmile]) can solve this problem I'll all but be there with this

smiler44
 
My experience is with scraping data from the emulator and reporting it to the user. That application is well suited to Excel, and as such, it makes eminent sense to code and run in the Cadillac rather than in the Yugo. Your requirements seem otherwise.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
as i understand it, the user can select more than 1 option. what does the 20 options do?
 
option 1 will take the user to the first instance found, option 20 will take them to the 20th instance found. I may have "solved" the problem or cheated and found a work around, I think. In the code above I call a sub routine userchoice. Once the userchoice sub runs the last line of code is.............create, which is the sub routine above. All the variables have retained their information and so it seems to work and rebuilds the dialog boxes.

I do have another question, I'll ask it while I'm here and will also go away and try to solve it myself
I would like to add 2 extra buttons that the user can press, page forward and page back, how do I do it?
I will try to solve it myself but if you could advise in case I can't it would be of great help.

thank you, I'm feeling pretty chuffed with myself right now for the solution

smiler44
 
From what I understand it is not possible to stop the dialog box closing after an option has been selected and the ok button pushed.
Got to say that's not very smart but all is not lost. I have added a sub routine that recreates the dialog box and in the code above is called from the userchoice routine.

where there's a will, there's a way [bigsmile]

smiler44
 
Hi smiler44,

I have made a simple example of how to 'fake' several pages in a dialog, by letting the dialog stay open when the buttons "Back" and "Forward" are pressed.

Code:
Declare Function DlgFunction(identifier$, action, suppvalue) 'Declare the function

Dim pagenr As Integer

Sub Main

    pagenr = 1

    Begin Dialog userdialog1 183, 100, .DlgFunction 'Set as the dialogs function
        CheckBox      16, 12, 46,  8, "1st",     .Option1 
        CheckBox      16, 30, 67,  8, "2nd",     .Option2
        CheckBox      16, 12, 67,  8, "3rd",     .Option3
        CheckBox      16, 30, 67,  8, "4th",     .Option4
        PushButton     5, 45, 54, 14, "Back",    .buttonBack
        PushButton    70, 45, 54, 14, "Forward", .buttonForward
        OkButton     125,  6, 54, 14 
        CancelButton 125, 26, 54, 14
    End dialog


    Dim mydialog1 As userdialog1
    On Error Resume Next
    Dialog mydialog1

End Sub 

Function DlgFunction(identifier$, action, suppvalue)
    Select Case action
        Case 1 'Initialisation
            DlgVisible("Option3"),0 'Makese the field in the dialog invisible
            DlgVisible("Option4"),0
            
        Case 2 'Button Pushed
        
            Select Case identifier
            
                Case "buttonBack"
                    DlgFunction = True 'Makes the dialog stay open
                    If pagenr = 2 Then
                        DlgVisible("Option1"),1
                        DlgVisible("Option2"),1
                        DlgVisible("Option3"),0
                        DlgVisible("Option4"),0
                        pagenr = pagenr - 1
                    End If
                    
                Case "buttonForward"
                    DlgFunction = True
                    If pagenr = 1 Then
                        DlgVisible("Option1"),0
                        DlgVisible("Option2"),0
                        DlgVisible("Option3"),1
                        DlgVisible("Option4"),1
                        pagenr = pagenr + 1
                    End If
                    
                Case Else
                    DlgFunction = False 'Closes the dialog
                    
            End Select
        Case 3 'Textbox or combobox changed
        Case 4 'Control focus changed
        Case 5 'When mouse i moved
    End Select
End Function

Hope it might help you.

Regards
Lakare
 
Thank you Lakare. I have sent the code to myself via email and will have a play over the coming evenings. I thought it was not possible so had given up trying to keep it open.

smiler44
 
Lakare, brill thank you, this works a treat
smiler44
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top