Skip to main content

Search

Search

Custom Date End Of Month

Comments

6 comments

  • Avatar
    Legacy Poster

    Hi,

     

    I can't offer a true-and-tested method, but maybe this will help:

    When you look at the properties of an object on your label, there is a "data source" entry, which represents a substring - or, in layman's terms, the actual content that will be printed for that object. Now, you can change the data source type on the right (default is "Embedded Data"). Change it to "Visual Basic Script", then select "Event Control Scripts" for the script type. Click "Edit with Script Assistant...", then on the left, click the OnAutoSelectedEvent entry in the list. Here, you can enter your code.

     

    To get the result of your code to display in the object, you need to assign the result to the variable "Value", at the end of your script, like this:

    Value = your_result
    

    To go into your actual request: I did a quick Google search which brought up an MSDN page suggesting the use of the DateSerial function. For the function to work, you need to pass it a year, a month and a day. If you enter 0 for the day, the function will use "the previous day" and calculate a new date. So if we tell it to use the year 2015, month 9 and day 0, it will yield the last day of August, the 31st.

     

    This is how the code looks like with the above mentioned parameters:

    DateSerial(2015, 9, 0)
    

    Now, that's quite static. It'll always yield 31st of August 2015.

    So I'll assume you want it to show the last day of whichever month the label is printed in. To do this, we can use additional functions and implement them into DateSerial:

    Value = DateSerial(Year(Date()), Month(Date())+1, 0)
    

    Date() yields the current system date. Year() and Month() yield the year and month of Date(), respectively. We add +1 to that month, and enter 0 for the day, so DateSerial() takes the "previous day of the first day of the next month", which is equivalent to the last day of the current month. Then we assign the result of DateSerial() to Value.

    0
  • Avatar
    Legacy Poster
    1. YES!!!  Thanks for breaking it down for me. I really appreciate that!

    Thank you! :D

    0
  • Avatar
    Lukasz Cichon

    Hi

    I am new to the Bartender & have found above tips very helpful.

    Above script is "pulling" information from "computer calendar" and i need to get something what will do same job, but based on the date from "Database Sources".

     

    Is it possible to achieve it on Bartender version 10.1 SR4?

    Thank you in advance :D

    0
  • Avatar
    Jasper Wen
    Moderator

    Sure, if you would like to reference values from a database field in vbscript, the syntax would something like Field("insert field name here"). This will pull value for that field from your connect database set in BarTender.

    0
  • Avatar
    Lukasz Cichon

    Apology.

    I think I was not clear enough with my intention.

    I need to be able to choose a date from my database (eg. 01.01.2016)

    and based on that I need bartender to create a barcode lets say 9 mths from above and default it to end of month (eg. 30.09.2016)

     

    Thank you in advance

    0
  • Avatar
    Lukasz Cichon

    Hi

    How can I change:

    Value = DateSerial(Year(Date()), Month(Date())+1, 0) (which is defaulting date into end of month based on system calendar)

    into the same result (so it will return end of month date), but based on "Object Value" (which is named Text 9).

     

    I am really struggling to get this sorted...

     

    Thank you for any help you can give me :D

     

    1

Please sign in to leave a comment.