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

Scripting Dialog boxes with default values 1

Status
Not open for further replies.

drlex

Technical User
Jul 3, 2002
3,295
GB
Having spent half a day getting to grips with Dialog boxes to try and get some degree of bullet-proof input to macros, I'd like to "pre-fill" some text boxes with default values.

Now, I can see that ComboBox offers the ability to enter text or select from a list. What I'd like to do is have a default value show first, not in a drop down list.

Hopefully I've overlooked something simple....

thanks,
lex

Disclaimer:I don't have a VB-script background, so my Cognos Scripting is all trial-and-error stuff.

soi la, soi carre
 
Text can be entered into a textbox using the dlgText function.

The Begin Dialog function allows you to set a function to handle interaction with the dialog box

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

Sub main
   Dim cchoices as String
   cchoices="All"+Chr$(9)+"Nothing"
     Begin Dialog UserDialog 180, 95, "CognosScript Dialog Box", .FileDlgFunction
       ButtonGroup .ButtonGroup1
       Text  9, 3, 69, 13, "Test:", .Text1
       TextBox 9, 25, 111, 10, .TextBox1
       OKButton  131, 8, 42, 13
       CancelButton  131, 27, 42, 13
       PushButton 132, 48, 42, 13, "Help", .Push1
    End Dialog
   Dim mydialogbox As UserDialog
   answer= Dialog(mydialogbox)

   Select Case answer
      Case -1
         MsgBox "You pressed OK"
      Case 0
         MsgBox "You pressed Cancel"
      Case 1
         MsgBox "You pressed Help"
   End Select
End Sub

Function FileDlgFunction(identifier$, action, suppvalue)
   If action = 1 Then 'Initialize box
      DlgText 2,"Default"
   End if         
End Function

Hope this gets you on your way



Gary Parker
MIS Data Analyst
Manchester, England
 
Text can be entered into a textbox using the dlgText function.

The Begin Dialog function allows you to set a function to handle interaction with the dialog box

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

Sub main
     Begin Dialog UserDialog 180, 95, "CognosScript Dialog Box", .FileDlgFunction
       ButtonGroup .ButtonGroup1
       Text  9, 3, 69, 13, "Test:", .Text1
       TextBox 9, 25, 111, 10, .TextBox1
       OKButton  131, 8, 42, 13
       CancelButton  131, 27, 42, 13
       PushButton 132, 48, 42, 13, "Help", .Push1
    End Dialog
   Dim mydialogbox As UserDialog
   answer= Dialog(mydialogbox)

   Select Case answer
      Case -1
         MsgBox "You pressed OK"
      Case 0
         MsgBox "You pressed Cancel"
      Case 1
         MsgBox "You pressed Help"
   End Select
End Sub

Function FileDlgFunction(identifier$, action, suppvalue)
   If action = 1 Then 'Initialize box
      DlgText 2,"Default"
   End if         
End Function

Hope this gets you on your way



Gary Parker
MIS Data Analyst
Manchester, England
 
Gary,
thanks for the pointer (your second post) - as you say, it gives me a place to start. I'm obviously not a programmer as it (and the rest of the dialog commands) appear to be counter-logical - give me the BASIC of my youth. [smile]

soi la, soi carre
 
sorry about the duplicated posts, The 1st attempt at submit appeared to have crashed.

Yes I agree with you about the programming logic here (or lack of it) it took me a while to work it out. Let me know if you need any further help.




Gary Parker
MIS Data Analyst
Manchester, England
 
An interesting thing about the dialog function is that you can use it to make the macro seem 'modeless'. Normally the macro execution stops when displaying a dialog box, making it difficult to give a status display to the end user. This is useful for longer macros, as the user may panic and think the macro has stopped working. By placing the entire performance section of the macro within a dialog function call, you can use the dialog to keep the user appraised of the status of the macro by changing the text value of a field within the dialog.

Dave Griffin


The Decision Support Group
Reporting Consulting with Cognos BI Tools
"Magic with Data"
[pc2]
Want good answers? Read FAQ401-2487 first!
 
Good idea Dave, Idon't use macros that much for users at present, but I'll try and remember that one for future reference.



Gary Parker
MIS Data Analyst
Manchester, England
 
Gary,
Got something suitable now, although what with the dialog palaver and the extensive Excel formatting, what was under 50 lines is now over 250! Still, it should survive its annual action without problems now. Have a star for your tip.

Dave,
interesting plan. Might follow it up as I understand the scripts a bit more.

soi la, soi carre
 
Glad I could help

Gary Parker
MIS Data Analyst
Manchester, England
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top