VBScript help Custom Date variable Follow

0
Avatar
Zach Taylor

Trying to return the date 10 Months from the previous Monday's date. I know this function works in other vbscript editors as I have been able to get it to compile and run. However when adding this to a multi-line on open script I am given the error expected end of statment on line 1: Dim monday As Date = Date.Today. Is there some formatting that I am missing the BarTender needs to be able to use a custom variable?

 

 

Dim monday As Date = Date.Today

While (monday.DayOfWeek <> DayOfWeek.Monday)
monday = monday.AddDays(-1)
Wend
'Add the 10 Months
monday = DateAdd("m",10,monday)
'Grab the Monday from that given week
While (monday.DayOfWeek <> DayOfWeek.Monday)
monday = monday.AddDays(-1)
Wend
'Format the dateString to look the way it will look on the label
dim dateString as string = monday.day & "-" & monthname(monday.month,true) & "-" & monday.year
'This is where your named datasource will go
Value = dateString

3 comments

0
Avatar
Pete Thane
Comment actions Permalink

Sorry very rusty on VB and so all my stuff is quite rusty and basic and I have never trued an While and Wend statement. I suppose I could have use a dim statement for the day of the week adjustment but this is what I have used. 

The first line is referencing a Named Data Source on my label called DateChosen and I had linked this to a Data Picker on a Data Entry Form so I could test it. I used a VB Event Controlled Script > OnIdenticalCopies option to add in the VB routine.

Value = Format.NamedSubStrings("DateChosen").Value

Value1 = Weekday(Value)

If Value1 = 0 then
Value = DateAdd("d",-5,Value)

elseif Value1 = 1 then
Value = DateAdd("d",-6,Value)

elseif Value1 = 2 then
Value = Value

elseif Value1 = 3 then
Value = DateAdd("d",-1,Value)

elseif Value1 = 4 then
Value = DateAdd("d",-2,Value)

elseif Value1 = 5 then
Value = DateAdd("d",-3,Value)

elseif Value1 = 6 then
Value = DateAdd("d",-4,Value)

elseif Value1 = 7 then
Value = DateAdd("d",-5,Value)

end if

Value = DateAdd("M",10,Value)

 

0
Avatar
Oly S
Comment actions Permalink

Hello 

maybe want to give it a try... 

regards

Oly

rem get current day of week, based on monday is 1st day of the week
dayofweek = DatePart("w", Date, 2)

rem get moday's date
monday=DateAdd("d", 1-dayofweek, Date)

rem add 10 month
monday=DateAdd("m", 10, Date)

value=monday



 

0
Avatar
Zach Taylor
Comment actions Permalink

I will be trying both of these this week. I'm fairly new to how BarTender does the vbscript but will use these to see what I get will keep in touch.

Please sign in to leave a comment.