Function age
Forums
Hello,
I have a problem with the function @age in Ideascript. When I execute the following code, IDEA crash.
Function DatePiece
Set db = Client.OpenDatabase(dbname)
Set task = db.TableManagement
Set field = db.TableDef.NewField
field.Name = "ECARTDATE"
field.Description = ""
field.Type = WI_VIRT_NUM
Dim a As String
a = "@age(" & Chr(34) & exercice & Chr(34) & ";PIECEDATE)"
field.Equation = a
field.Decimals = 0
task.AppendField field
task.PerformTask
Set task = Nothing
Set db = Nothing
Set field = Nothing
End Function
The variable "exercice" is a string value : 2081231
The field PIECEDATE is a date value (format "YYYYMMDD")
The recording macro is :
Set db = Client.OpenDatabase("444274732FEC20160331.IMD")
Set task = db.TableManagement
Set field = db.TableDef.NewField
field.Name = "ECARTDATE"
field.Description = ""
field.Type = WI_VIRT_NUM
field.Equation = "@age(""20181231"";PIECEDATE)"
field.Decimals = 0
task.AppendField field
task.PerformTask
Set task = Nothing
Set db = Nothing
Set field = Nothing
Anybody has an idea ?
Thank you !
Benoit
After several hours, I found
After several hours of research, I found my mystake !
I souldn't wrote "exercice = Mid(nomfichier,13,8)" because NomFichier is a function !
Function NomFichier
Dim temp_length As String, a As Integer, i As Integer
sfilename2 = sfilename
temp_length = Len(sFilename2 )
For i = temp_length To 1 Step -1
If Mid(sfilename2,i,1) = "\" Then Exit For
Next
For a = temp_length To 1 Step -1
If Mid(sfilename2,a,1) = "." Then Exit For
Next
NOMFICHIER = Mid(sfilename2,i+1,a-i-1)
exercice = Mid(nomfichier,13,8)
End Function
it crash again.
it crash again.
I wrote :
newFieldName = checkIfFieldNameExists("ECARTDATES", dbname)
field.Name = newFieldName
the internal error focuses on the instruction "field.Name = newFieldName"