Script to use user entered date Follow

0
Avatar
David Turner

Howdy, this code nearly works, but still getting errors for some reason.  This isn't my first rodeo - I've worked in VBA for years, but I haven't worked with VBS before.  Working on a Windows 10 64bit desktop linked to Excel as database, printing on Zebra label printers.  All the printing is existing and works as intended. Most of the code below is existing as well.

A print-time field defaults to today's date, and user has option to change.  This is stored in an unprinted object on the label named "DateHelper".  I need the script to test the DateHelper value and add an extra day if it is the sixth day of the week (Friday).  Additionally, it needs to lookup against a database and add the "DAYS" field value.  In quasi:

If DateHelper is a Friday, then return DateHelper + 1 + Field, if not Friday then return DateHelper + Field

'Code:

Dim DHvalue
DHvalue = Format.NamedSubStrings("DateHelper").Value

Dim FreshDays
Dim FreshDaysLong
FreshDays = Field("DAYS")
FreshDaysLong = Field("DAYS") + 1

If Weekday(DHvalue) = 6 Then
    Value = DateAdd("d", FreshDaysLong, DHvalue)
Else
    Value = DateAdd("d", FreshDays, DHvalue)
End If

Most of the above is already working in production.  The only change is using DHvalue to inherit from the field at print-time.  In past the DHvalue predicate and value used Date to use system date.

I get an error as "Invalid procedure call or argument: 'DateAdd'.  I have tested the variable FreshDaysLong and it indeed does return a numeric such as 11.  When I call the DateAdd statement using a numeric, code executes without error.  Why is the variable causing this to throw an error?  Is it a data type issue?  I've experimented with various forces of CDate(DHvalue) as well as CInt(FreshDaysLong) / Cdbl(FreshDaysLong), but I can't find the right combination.

Any advice?  TY - DT

3 comments

0
Avatar
Pete Thane
Comment actions Permalink

It maybe down to when the VB is being processed and whether it is a numeric value at the time.

As you are getting data from a database and also a data entry screen you probably need to make the VB an Event Controlled Script and have it process OnPostPrompt or OnIdenticalCopies so that it triggers after the database and user data has been entered

0
Avatar
David Turner
Comment actions Permalink

Thank you for the reply Pete.  I did take another stab at it the other night, trying with the events as you suggested.

Unfortunately I wasn't able to get it to work as intended, and I did discover something telling in the Bartender documentation.  See URL below.

http://help.seagullscientific.com/2016/en/Subsystems/BTVBScript/Content/sib_intro_document_level_events.htm

It states specifically that it "does not support automation for data entry controls".  And that code will throw an error, etc.  So, I guess that might explain why this is still failing even though testing it in parts appears to work.  I guess I'll have to reassess how to achieve this.

Thanks anyway.

-DT-

0
Avatar
Pete Thane
Comment actions Permalink

Dont do it as a Document Level script but as script in one of the fields on the template itself

Please sign in to leave a comment.