Hi,
I am trying to automate some analysis and I don't know how to fix the following code in order to include the field as variant because I have several fields in where I need to adjust the format. Can someone help me to insert the variable field in my equation editor? This is where my code stop working, I have copied it here! Thanks
Function ModifyAllDateField (DateField, WorkingDatabase) As Variant
Dim db As Object
Dim task As Object
Dim field As Object
Set db = Client.OpenDatabase(WorkingDatabase)
Set task = db.TableManagement
Set field = db.TableDef.NewField
'Users DateField variable passed to the function to set which field is checked
field.Name = DateField
' Checks if the field is already a date field, if it is, do nothing
' If the field is not a date field, then change it to a date field (saves processing time)
If field.IsDate Then
Set Task = Nothing
Set db = Nothing
Set field = Nothing
Else
field.Name = DateField & "_CORRECT"
field.Description = ""
field.Type = WI_VIRT_DATE
field.Equation = "@ctod(DateField, ""DD/MM/YYYY"")"
task.AppendField field
task.PerformTask
Set task = Nothing
Set db = Nothing
Set field = Nothing
End If
End Function
giorgia.basso
Offline
Last seen: 6 years 1 month ago
Joined: 02/26/2016 - 13:56
Hi Giorgia and welcome to the site.
I made some modification to your function. I added comments to the parts that I changed. So these are the following changes I made:
Hopefully this helps you out.
Thanks
Brian
Hi Brian,
thanks a lot for your answer and nice to meet you! :-)
The code works but only if I keep the function variants.
I like how you created the forum.
Giorgia
That is very strange that you need the variant to work. How are you calling the function?
here is the name of my function
Function ModifyAllDateField (DateField, WorkingDatabase) As Variant
Hi Giorgia,
What I was looking for is how are you calling the function, do you have:
call ModifyAllDateField(DateField, WorkingDatabase) or do you have a variable equal to it?
Thanks
Brian
Hi Brian,
here is my option explicit and my sub main.
Let me know if this help.
Thanks,
Giorgia
Option Explicit
Dim VMFileName, EmployeeFileName, BillsFileName, BillsDetailsFileName, POFileName, PODetailsFileName, dbNetSuite, dbWorkday As String
Dim Result As Long
Sub Main
Client.ManagedProject = "LOC-0001 Procurement"
Call FileBrowser() 'Call GetFileNames()
Call VMImport() ' Import the VMF Input file
Call EmployeeInfoImport() ' Import the Employee Input file
Call BillsImport() ' Import the account #20000 transactions - main line
Call BillsDetailsImport() ' Import the account #20000 transactions - expense line file
Call POImport() ' Import the PO main line file
Call PODetailsImport() ' Import the PO details file
Call PassVMFields()
Call PassBillsFields()
Call PassBillsDetailsFields()
Call PRO_003_01()
Client.CloseAll
End Sub
Hi Giorgia,
Sorry I missed your reponse. What I am looking for exactly is the line that is calling the function that wants to be a variant.
Thanks
Brian
Hello Brian,
Let's say the variable is of type String. And I want to write an equation that checks a string field
Dim code as String
Sub main()
code = "271"
...
...
equation = "BRA_CODE = " & code
...
...
End sub
The problem is that the equation variable reads it as :
"BRA_CODE = 271"
but I want it to read it as
"BRA_CODE = "271""
Please can you help?
Hi Oseroke,
You have to include the double quotes (") around the variable so your equation could be:
equation = "BRA_CODE = """ & code & """"
So when you have "" (two double quotes) IDEAScript will insert a single " instead of closing the string. So in this case the equation editor would see the equation as: equation = "BRA_CODE = "271"
You can also write it like this:
equation = "BRA_CODE = " & chr(34) & code & chr(34)
The chr(34) inserts a double quote.
Another option is to create a variable or constant to hold the double quote:
Const dblQuote = chr(34)
equation = "BRA_CODE = " & dblQuote & code & dblQuote
All of these should work assuming I didn't make a typo.
Brian
Hello i want to make my equation works using variant:
My i get a help what is the correct syntax:
Function criterio
MsgBox ("TRANSFORMACION CARACTER")
MsgBox (sDate)
Set db = Client.OpenDatabase("A_DLPMT.IMD")
Set task = db.TableManagement
Set field = db.TableDef.NewField
field.Name = "MIN"
field.Description = ""
field.Type = WI_VIRT_NUM
field.Equation = "@If(FECHA_PAGAR<=sDate;@Age(FECHA_PAGAR;sDate);0)"
field.Decimals = 0
task.AppendField field
task.PerformTask
Set task = Nothing
Set db = Nothing
Set field = Nothing
MsgBox ("Fin Criterio")
End Function
Regards
Pages