コミュニティ

How do you set an environment variable using a VB Script

Hello,

I am new to the ABBYY Flexicapture 11 product and I am having problems trying to set an environment variable using a VB Script in the AfterBatchCreated event handler.
The purpose of the Script is to change the default batch name to be something like
2016-05-17.0001
2016-05-17.0002
….
With the date changing each day.
When I tried something like:

me.Project.EnvironmentVariables.Set("LastBatchDate", "2016-05-17")

I get the error “Cannot user parentheses when calling a Sub”

I then tried adding the word Call in front and it then passed syntax checker, however still will not work.

Call me.Project.EnvironmentVariables.Set("LastBatchDate", "2016-05-17")

Below is my complete script:
LastBatchDate = me.Project.EnvironmentVariables.Get("LastBatchDate")
LastBatchSeqNumber = me.Project.EnvironmentVariables.Get("LastBatchSeqNumber")

If LastBatchDate = "" then
LastBatchDate = Year(Date) & "-" & Right("0" & Month(Date), 2) & "-" & Right("0" & Day(Date), 2)
LastBatchSeqNumber = 0
End If

If LastBatchDate <> Year(Date) & "-" & Right("0" & Month(Date), 2) & "-" & Right("0" & Day(Date), 2) then
LastBatchDate = Year(Date) & "-" & Right("0" & Month(Date), 2) & "-" & Right("0" & Day(Date), 2)
LastBatchSeqNumber = 0
End If
me.Name = LastBatchDate & Right("0000" & (LastBatchSeqNumber+1),4)

call me.Project.EnvironmentVariables.Set("LastBatchDate", LastBatchDate)
call me.Project.EnvironmentVariables.Set("LastBatchSeqNumber", LastBatchSeqNumber+1)


Thanks
Dirk

この記事は役に立ちましたか?

0人中0人がこの記事が役に立ったと言っています

コメント

3件のコメント

  • Avatar
    Alberto Torino
    Hi Dirk:
    Project.EnvironmentVariables is read only. Check help. You should save your data somewhere else , maybe a file.
    Try this :
    dim fso, fileName, txtFile, SeqNumber

    set fso = CreateObject("Scripting.FileSystemObject")
    if Not IsObject(fso) then
    Processing.ReportError "Error Creating FSO"
    End if
    'Choose you path
    fileName = "c:\temp"& Year(Date) & "-" & Right("0" & Month(Date), 2) & "-" & Right("0" & Day(Date), 2) & ".Txt"
    If fso.FileExists(fileName) then
    set txtFile = fspenTextFile(fileName,1)
    SeqNumber = Cint(txtFile.ReadAll)
    txtFile.Close
    else
    SeqNumber = 1
    End if
    Me.Name = Year(Date) & "-" & Right("0" & Month(Date), 2) & "-" & Right("0" & Day(Date), 2) & "-" & Right("00000" & SeqNumber,6)
    set txtFile = fspenTextFile( fileName, 2,true )
    txtFile.Write SeqNumber + 1
    txtFile.Close
    Set fso = Nothing

    Regards
    0
  • Avatar
    Permanently deleted user
    Atorino,

    Thank you for the information. I had referenced the help, however it was not clear to me. It said to use the IProperties.
    1. Environment variables of any type can be used in scripts. Use the EnviromentVariables property of IProperties, which is available in the IProject interface.
    When I looked at IProperties:

    IProperties

    What it does
    A collection of IProperty objects.

    Methods
    Definition

    Description

    Delete (name : string)
    Deletes the property with the specified name.
    Get (name : string) : string
    Retrieves the property value by the name.
    Has (name : string) : bool
    Checks whether the set contains the property with the specified name.
    Set (name : string, value : string)
    Sets the value of a named property. Creates a property, if it does not exist.
    Note: For information on how to change document state, refer to the ITaskWindow interface.


    It listed the above methods. Based on this I was attempting to used the Set method to set this value.

    Even the context sensitive help in vb shows a set command under Project.EnviromentVariables.





    After reading your post I also looked at IProject which did have the following

    Properties
    Name

    Type

    Access

    Description

    EnvironmentVariables
    IProperties
    Read only
    Returns an array of the environment variables used in the project.


    I am just confused why the Set and Delete methods are listed in the context sensitive help for a read only field.

    Anyway, now that I know I will store this info in a Database or text file as you suggested.

    Thanks again for you help.

    Dirk
    0
  • Avatar
    Alberto Torino
    Hello Dirk,
    Glad to help. You can GET information from environment variables, but seems that setting is not possible.
    I'm attaching help file information , the one i have, about the Project.EnvironmentVariables . I'm currently using Flexicapture 11.4 (StandAlone & Distributed).

    Kind regards,
    0

サインインしてコメントを残してください。