Skip to main content

Function age

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

BENOIT Tue, 03/12/2019 - 13:26

it crash again.
I wrote :
    newFieldName = checkIfFieldNameExists("ECARTDATES", dbname)
    field.Name =  newFieldName
the internal error focuses on the instruction "field.Name =  newFieldName"

Brian Element Tue, 03/12/2019 - 13:48

In reply to by BENOIT

Sometimes you just have to delete a portion of script and just rewriting it, looks like this is what is happening here.  Make sure that field has been properly dimensioned and there is no other variables or functions that could be screwing up that section.

BENOIT Wed, 03/13/2019 - 05:31

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