Add a user prompt for criteria?

4 posts / 0 new
Last post
mcgrooty
Offline
Joined: 02/19/2014 - 15:54
Add a user prompt for criteria?

Hi all, I am very new to IDEAScript/Caseware and I searched the forums before posting this question:
For the following code I want a dialog box that will pop up to ask the user for the dates rather than having to manually change it in the code; how to go about that?
 
Function DirectExtraction
Set db = Client.OpenDatabase("PY_POPSDATA2.IDM")
Set task = db.Extraction
task.IncludeAllFields
dbName = "PY_POPSDATA.IDM"
task.AddExtraction dbName, "", " PYRPOPS_STATUS_IND == ""T"" .AND. PYRPOPS_DATE_TO_BE__DATE >=""20130501"" .AND. PYRPOPS_DATE_TO_BE__DATE <""20140201"""
task.PerformTask 1, db.Count
Set task = Nothing
Set db = Nothing
Client.OpenDatabase (dbName)
End Function

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hello and welcome to the site.

I put together some code for you with a basic dialog (I have attached the script) what will ask for two dates, the code will then verify that they are in the proper date format and if not give a message of the error and allow you to reenter the dates in the proper formats.  I then have inserted the dates into your code.  Hopefully this will give you an idea of how to use the dialog.  I also have a series of videos that will walk you through creating a script and adding a dialog, you can find it here.  So let me know if this helps you out or if you are looking for something else.

Thanks

Begin Dialog dlgEnterDates 50,48,176,116,"Enter Dates", .NewDialog
  Text 18,12,40,14, "Date 1", .Text1
  TextBox 70,13,50,14, .txtDate1
  Text 18,37,40,14, "Date 2", .Text2
  TextBox 70,35,50,13, .txtDate2
  OKButton 23,68,40,14, "OK", .OKButton1
  CancelButton 83,68,40,14, "Cancel", .CancelButton1
End Dialog
'****************************************************************************************************
'* Script:		InputDateTestScript.iss
'* Author:	Brian Element - brian.element@ideascripting.com
'* Date:		Feb 19, 2014
'* Purpose:	Demo script to show how to capture dates through a basic dialog
'* This script is provided without any warranty or guarantee.  Anybody using this script
'* is encouraged to validate the effectiveness and reliability on their own.
'****************************************************************************************************
Option Explicit
Dim sDate1 As String
Dim sDate2 As String
Dim exitScript As Boolean

Sub Main
	Call menu()
	'if user has not selected cancel run the script
	If Not exitScript Then
		Call DirecExtraction()
	End If
End Sub

Function DirectExtraction()
	Dim db As database
	Dim task As task
	Dim dbName As String
	
	Set db = Client.OpenDatabase("PY_POPSDATA2.IDM")
	Set task = db.Extraction
	task.IncludeAllFields
	dbName = "PY_POPSDATA.IDM"
	task.AddExtraction dbName, "", " PYRPOPS_STATUS_IND == ""T"" .AND. PYRPOPS_DATE_TO_BE__DATE >=""" & sDate1 & """ .AND. PYRPOPS_DATE_TO_BE__DATE <"""  & sDate2 &  """"
	task.PerformTask 1, db.Count
	Set task = Nothing
	Set db = Nothing
	Client.OpenDatabase (dbName)
End Function

Function menu()
	Dim dlg As dlgEnterDates
	Dim button As Integer
	Dim bError As Boolean
	
	'supply mask for text boxes
	dlg.txtDate1 = "YYYY/MM/DD"
	dlg.txtDate2 = "YYYY/MM/DD"
mainMenu:	
	'open dialog box
	bError = false 'set-up a variable to flag if the dates are in the incorrect format
	button = Dialog(dlg)
	
	Select Case button
		Case -1 'ok button selected
			sDate1 = dlg.txtDate1
			sDate2 = dlg.txtDate2
			
			'validate that it is a valid date
			If Not IsDate(sDate1) Then
				MsgBox "Date 1 is in the incorrect format please enter again using YYYY/MM/DD"
				bError = true
			End If
			If Not IsDate(sDate2) Then
				MsgBox "Date 2 is in the incorrect format please enter again using YYYY/MM/DD"
				bError = true
			End If
		Case 0 'cancel button selected
			exitScript = True
	End Select
	If bError Then 
		GoTo mainMenu 'if there is a date error loop back and show the menu again
	Else
		'remove the slashes from the dates as IDEA date does not use them
		sDate1 = iRemove(sDate1, "/") 'using the @remove date function and replace the slashes whith a blank
		sDate2 = iRemove(sDate2, "/") 'using the @remove date function and replace the slashes whith a blank
	End If
End Function

 

alifer13
Offline
Joined: 02/02/2017 - 08:13

i have a problem.
Error 101. el sistema no puede encontrar la ruta especificada.
but it exist.
Function TextImportUSR50001     Set task = Client.GetImportTask("ImportExcel")     dbName = "C:\AreaTrabajoIDEA\_FicherosBase\MU-total-usuarios.xlsx"     task.FileToImport = dbName     task.SheetToImport = "500UsuariosIMP"     task.OutputFilePrefix = "MU"     task.FirstRowIsFieldName = "TRUE"     task.EmptyNumericFieldAsZero = "FALSE"     task.PerformTask     dbName = task.OutputFilePath("500UsuariosIMP")     Set task = Nothing'     Client.OpenDatabase(dbName)End Function

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi Alicia,

Any chance the file was open when you tried to do the import.  The excel file must be closed when doing an import.

Brian