Pass a date in a dialog box

7 posts / 0 new
Last post
rehumah
Offline
Joined: 08/11/2017 - 04:25
Pass a date in a dialog box

I have been trying to use this date type var in a dialog box but it is giving me an error
 
Dim StartDate, EndDate As Date
 
Sub Main
StartDate = dlgEnable.TextBox2
EndDate = dlgEnable.TextBox3
Call DirectMCINTExtraction()                
End sub
Function DirectMCINTExtraction
Set db = Client.OpenDatabase(InputFile)
Set task = db.Extraction
task.IncludeAllFields
dbName = FileName +"_INTL.IMD"
task.AddExtraction dbName, "", "@Right(RECON_CURR_CODE,3) == ""USD""  .AND. @Betweendate(TRANS_DATE, @ctod(StartDate,""YYYY-MM-DD""), @ctod(EndDate,""YYYY-MM-DD""))"
task.CreateVirtualDatabase = False
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

Hi rehumah,

Try changing the varaible type to String instead of Date as even though you are getting date information it needs to be in a string format to obtain it from the dialog and use it in the extraction equation.

One other thing, there is a bug in IDEAScript when declaring variables and you can only decare one variable per line.  So in your example the StartDate has actually been defined as a variant instead of a date.  You can use the VarType to see this.  So you should define the StartDate and EndDate as string and each one on a separate line.

Brian

rehumah
Offline
Joined: 08/11/2017 - 04:25

Hi Brian
Thanks for the response.
But what i am actually trying to do is, i am using a dialog box to get two date inputs which I am passing to a function via some variables to extract some data within that date range. 
 Note: StartDate and EndDate are two string variables holding the dates that are entered into the dialog

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

Hi rehumah,

I took your code and modified it a bit so hopefully it will work for you.  I have also attached the script as this doesn't show the dialog box.

So I did the following things:

1. I changed the StartDate and EndDate variable to a string.  Dialogs return strings and equations use string so even though this is a date it needs to be in a string format to work.

2. For your dialog I added a date format.

3. For the equation I modified it as the variables have to be outside the double quotes, it it is within the double quotes the equation will be looking for StartDate literally instead of what the variable holds.  As I don't have your database I couldn't run the function so I can't be sure that the equation is good but it looks good.

Hopefully this will help you out.

Brian


Option Explicit

Dim StartDate As String
Dim EndDate As String
Dim InputFile As String
Dim FileName As String

Sub Main
	Dim dlgEnable As NewDialog
	Dim button As String
	dlgEnable.TextBox2 = "YYYY-MM-DD"
	dlgEnable.TextBox3 = "YYYY-MM-DD"
	button = Dialog(dlgEnable)
	If button <> 0 Then 'not cancelled
		StartDate = dlgEnable.TextBox2
		EndDate = dlgEnable.TextBox3
		Call DirectMCINTExtraction()     
	End If           
End Sub

Function DirectMCINTExtraction
	Dim db As database
	Dim task As task
	Dim dbName As String
	
	Set db = Client.OpenDatabase(InputFile)
		Set task = db.Extraction
			task.IncludeAllFields
			dbName = FileName +"_INTL.IMD"
			task.AddExtraction dbName, "", "@Right(RECON_CURR_CODE,3) == ""USD""  .AND. @Betweendate(TRANS_DATE, @ctod(""" & StartDate & """,""YYYY-MM-DD""), @ctod(""" & EndDate & """,""YYYY-MM-DD""))"
			task.CreateVirtualDatabase = False
			task.PerformTask 1, db.Count
		Set task = Nothing
	Set db = Nothing
	Client.OpenDatabase (dbName)
End Function
rehumah
Offline
Joined: 08/11/2017 - 04:25

Thank you

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

Glad to help.

rehumah
Offline
Joined: 08/11/2017 - 04:25

Check the file i have uploaded