Link to home
Start Free TrialLog in
Avatar of tambrosi

asked on

Bartender Label Software

I am going to try on Expert Exchange for an answer, I am using Bartender software and using the scripting feature, my input is .dat file and the file has a date field in the format
"06/22/2012",  I need to add 740 days to it.  

I use this method to try to change to a date and I get a type mismatch
MyShortDate = CDate(MyDate)
Avatar of Bill Prew
Bill Prew

Bartender from ISD?

Avatar of tambrosi


Seagull Scientific
In Bartender, how do you define the MyDate variable?  I assume it's mapped to a position or field in the data file, but is it always a character data type, or do you define it as a date there, or a number, etc?  As long as it's a string type, then I think this should work:

MyShortDate = DateAdd("d", 720, CDate(MyDate))

If it's already a date type, then you should be able to do:

MyShortDate = DateAdd("d", 720, MyDate)

I tried both statements:

data comes in as "06/04/2012"

value = DateAdd("d", 720, ("BarTag.Field 30")  *  Type mismatch string BarTag.field 30"]

'value = DateAdd("d", 720, CDate(("BarTag.Field 30")))  ****  Type mismatch 'Cdate"

If I hardcode a string as "06/04/2012"   and use this
NewDate = DateAdd("d", 720, "04-Jun-12")   works  

Tried to use the mid function to break it up and bring it back together
'value1 =  Mid(Field("BarTag.Field 30"),1,2)  
'value2 =  Mid(Field("BarTag.Field 30"),4,2)
'value3 =  Mid(Field("BarTag.Field 30"),9,2)

Any ideas would sure be appreciated.
The script does not know what "BarTag.Field 30" is, you would need to find the field "BarTag.Field 30" and assign that into a variable to insert into value = DateAdd("d", 720, %myvar%)

Set objFS = CreateObject("Scripting.FileSystemObject")
'File to scan
strFile = "c:\test\file.dat"
'Pattern to search for, eg BarTag.Field 30
strPattern = "BarTag.Field 30"
Set objFile = objFS.OpenTextFile(strFile)
Do Until objFile.AtEndOfStream
    strLine = objFile.ReadLine  
    If InStr(strLine,strPattern)>0 Then
        WScript.Echo strLine
    End If  
Wscript.Echo H

value = DateAdd("d", 720, ("H")

Wscript.Echo value
Ok That makes sense from what I have been seeing,   I apologize on this scripting stuff, I got thrown into a problem to solve.  

But how can you scan for changing date field.  Here is part of the .dat file   The .dat file has no headers.  

82294,"TEST3","06/22/2012","Home Enterprises Inc","894751 \ GV 48OZ HOME VANILLA",

I need to get the value of 06/22/2012  

I really appreciate the help!!!!!
How about batch, problem is that many days in future would be hard to script due to months having different number of days and leap year.

FOR /F "delims=, tokens=1-6" %%a IN (file.dat) do (echo %%c)
You can try something like this which will add a rough two years which is close to 740 days

@echo off
FOR /F "delims=, tokens=3" %%a IN (file.dat) do (call :subroutine %%a)
pause && goto :eof
setlocal enabledelayedexpansion

for /f "tokens=1-3 delims=/" %%a in ("%*") do (

	set /a yearStart=%%c - 1
	set "startdate=%%a-%%b-!yearStart!"
	set /a yearFinish=!yearStart! + 2
	set "finishDate=%%a-%%b-!yearFinish!"
	set "startdate=!startdate:"=!
	set "finishDate=!finishDate:"=!
echo Start : !startdate!
echo Finish : !finishDate!
goto :eof

Open in new window

Here is a new one for you, it actually adds 740 days to your "date"
With some help from
as you can see on the bottom of the script I have it output the future date to newfile.dat


FOR /F "delims=, tokens=3" %%a IN (file.dat) do (call :subroutine %%a)
pause && goto :eof
set datevar=%*

setlocal enabledelayedexpansion

set "newdate=!datevar:"=!
set datevar=!newdate!

:: Strip the day of the week from the current date
FOR %%A IN (%datevar%) DO SET Today=%%A
:: Parse the date, prefix day and month with an extra leading zero
FOR /F "tokens=1-3 delims=/" %%A IN ("%Today%") DO (
    SET Day=0%%B
    SET Month=0%%A
    SET Year=%%C
:: Remove excess leading zeroes
SET Day=%Day:~-2%
SET Month=%Month:~-2%
:: Display the results
SET Month
SET Year
:: Convert to Julian date
CALL :JDate %Year% %Month% %Day%
:: Display the result
:: Add 740 days
SET /A JPast = JDate + 740
:: Display the result
:: Convert back to "normal" date again
CALL :GDate %JPast%
:: Display the result

:: Convert date to Julian
:: Arguments : YYYY MM DD
:: Returns   : Julian date
:: First strip leading zeroes
IF %MM:~0,1% EQU 0 SET MM=%MM:~1%
IF %DD:~0,1% EQU 0 SET DD=%DD:~1%
:: Algorithm based on Fliegel-Van Flandern
:: algorithm from the Astronomical Almanac,
:: provided by Doctor Fenton on the Math Forum
:: (,
:: and converted to batch code by Ron Bakowski.
SET /A Month1 = ( %MM% - 14 ) / 12
SET /A Year1  = %1 + 4800
SET /A JDate  = 1461 * ( %Year1% + %Month1% ) / 4 + 367 * ( %MM% - 2 -12 * %Month1% ) / 12 - ( 3 * ( ( %Year1% + %Month1% + 100 ) / 100 ) ) / 4 + %DD% - 32075
SET Month1=
SET Year1=

:: Convert Julian date back to "normal" Gregorian date
:: Argument : Julian date
:: Returns  : YYYY MM DD
:: Algorithm based on Fliegel-Van Flandern
:: algorithm from the Astronomical Almanac,
:: provided by Doctor Fenton on the Math Forum
:: (,
:: and converted to batch code by Ron Bakowski.
SET /A P      = %1 + 68569
SET /A Q      = 4 * %P% / 146097
SET /A R      = %P% - ( 146097 * %Q% +3 ) / 4
SET /A S      = 4000 * ( %R% + 1 ) / 1461001
SET /A T      = %R% - 1461 * %S% / 4 + 31
SET /A U      = 80 * %T% / 2447
SET /A V      = %U% / 11
SET /A GYear  = 100 * ( %Q% - 49 ) + %S% + %V%
SET /A GMonth = %U% + 2 - 12 * %V%
SET /A GDay   = %T% - 2447 * %U% / 80
:: Clean up the mess
FOR %%A IN (P Q R S T U V) DO SET %%A=
:: Add leading zeroes
IF 1%GMonth% LSS 20 SET GMonth=0%GMonth%
IF 1%GDay%   LSS 20 SET GDay=0%GDay%
:: Return value
SET GDate=%GMonth%/%GDay%/%GYear%
ECHO %GDate% > newfile.dat

Open in new window

What a brain scratcher!
I'm a little confused, can we take a step back.  I was under the impression you were writing some "script" code in the "VB" scripting language that Bartender supports.  Is that not the case?

Can you share a little more on where the code you are trying to execute exists, and how it gets executed please.

Yes I am trying to use the VB scripting language to do the date calc.  I see I have no other way to deal with it.  

Please see attached.  
I also screen copied the help that comes with the product.
Avatar of Bill Prew
Bill Prew

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I tried that earlier.   Same results.    I attached the output.  

Can you share the help screen from the CDATE funtion?

Does the script run within the program or are you just updating the .dat file?

   I just might of got this to work.   I need to run some more tests with production data yet.  

   This got me thru along with some other things.  
    value = DateAdd("d", 720, CDate(Field("BarTag.Field 30")))

   but the processing logic Bartender uses with VB might of been throwing me for a loop.  It states a "script error", but still runs the script.   After I get thru my testing, I will let you know.  

You do not know how much I appreciated the help.!!!!
Glad to hear you are making some progress, keep me posted.

~bp,   thanks for sticking with me on this item.  Between your response(s) and the process I received from another forum, I was able to get what I needed,