enable/disable button using vbs

Label printing integration (NiceWatch middleware and ActiveX programming interface)

Moderators: Georges, milos, NiceLabel Support Team

Post Reply
Manuel
Enthusiast
Posts: 7
Joined: Tue Oct 10, 2017 4:03 pm

enable/disable button using vbs

Post by Manuel » Tue Oct 10, 2017 4:55 pm

Hello,

i am new to this Forum.
I am using Lighthouse for MAX 6.5 with a CPM-100 for printing and cutting labels.
I am using the printer mainly for printing inspection labels which specify when the last inspection of an equipment has been occured.

Long story short, i am placing cut shapes on the layout as can be seen in the attached image.
There are supposed to be twelve cut shapes, one over each month. All of them are temporarily deactivated. (neither cutting nor printing is enabled for these shapes).
To optimize the cutting process i would like the lighthouse software to automatically determine which cut shape is to be activated when the labels are supposed to be printed. So that the user doesn't have to do this manually to prevent user error.

Now i already found out that VB is supported and i already found the name for the shapes that are used for cutting. (Ellipse1, Ellipse2 etc.)
But i don't actually now how to exactly achieve my goal. Does declaring the Ellipse Shapes as Boolean(True/False) and activating them with currentDate and DateTime go somehwere in the right direction? I am not that comfortable with VB yet, so i dont know if this approach is somewhat correct.

Here is the code that i have written so far:

Code: Select all

Sub setCutShape()
Dim currentDate As DateTime = DateTime.Now
Dim Ellipse1 As Boolean, Ellipse2 As Boolean, Ellipse3 As Boolean, _
    Ellipse4 As Boolean, Ellipse5 As Boolean, Ellipse6 As Boolean, _
    Ellipse7 As Boolean, Ellipse8 As Boolean, Ellipse9 As Boolean, _
    Ellipse10 As Boolean, Ellipse11 As Boolean, Ellipse12 As Boolean
If currentDate.Month = 1 Then
   Ellipse1 = True
End If
If currentDate.Month = 2 Then
   Ellipse1 = True
End If
If currentDate.Month = 3 Then
   Ellipse1 = True
End If
If currentDate.Month = 4 Then
   Ellipse1 = True
End If
If currentDate.Month = 5 Then
   Ellipse1 = True
End If
If currentDate.Month = 6 Then
   Ellipse1 = True
End If
If currentDate.Month = 7 Then
   Ellipse1 = True
End If
If currentDate.Month = 8 Then
   Ellipse1 = True
End If
If currentDate.Month = 9 Then
   Ellipse1 = True
End If
If currentDate.Month = 10 Then
   Ellipse1 = True
End If
If currentDate.Month = 11 Then
   Ellipse1 = True
End If
If currentDate.Month = 12 Then
   Ellipse1 = True
End If
End Sub
I might be totaly of track with this approach, so if anyone with more experience could point me into the right direction, that would be very nice. Also, is there any function library where i can find out how i am supposed to address funtctions like cutting? There are two buttons when i select a shape which determine if a shape is printed, cutted, printed and cutted or neither of the two. So there must be a way to set these buttons via scripting.

I hope my english isn't to bad and anyone can understand what i am trying to do.
I would appreciate any help.
Attachments
cutShape.JPG
One of twelve Cut Shapes to cut the proper month.
cutShape.JPG (59.95 KiB) Viewed 3889 times

Manuel
Enthusiast
Posts: 7
Joined: Tue Oct 10, 2017 4:03 pm

Re: enable/disable button using vbs

Post by Manuel » Fri Oct 20, 2017 8:51 am

Hi i modified the thread Title to better exemplify what i am trying to achieve.

In a Nutshell i am trying to enable/disable the button in the left menu of the software which determins if a placed object will be cut by the printer with the use of a script. (see attached screenshot)

Is there any way to do this or is it simply impossible? If this is not possible, how could i work around this problem to achieve something similar?

I have modified my previous code and i should work as a base from where i can start.

Any suggestions would be appreciated.

Code: Select all

Dim currentDate, Ellipse1, Ellipse2, Ellipse3, Ellipse4, Ellipse5, Ellipse6, _
    Ellipse7, Ellipse8, Ellipse9, Ellipse10, Ellipse11, Ellipse12

currentDate = Month(date)

If currentDate = "1" Then
   Ellipse1 = True
End If

If currentDate = "2" Then
   Ellipse2 = True
End If

If currentDate = "3" Then
   Ellipse3 = True
End If

If currentDate = "4" Then
   Ellipse4 = True
End If

If currentDate = "5" Then
   Ellipse5 = True
End If

If currentDate = "6" Then
   Ellipse6 = True
End If

If currentDate = "7" Then
   Ellipse7 = True
End If

If currentDate = "8" Then
   Ellipse8 = True
End If

If currentDate = "9" Then
   Ellipse9 = True
End If

If currentDate = "10" Then
   Ellipse10 = True
End If

If currentDate = "11" Then
   Ellipse11 = True
End If

If currentDate = "12" Then
   Ellipse12 = True
End If

Attachments
screenshot.JPG
screenshot.JPG (119 KiB) Viewed 3842 times

User avatar
jure
NiceLabel
NiceLabel
Posts: 186
Joined: Fri Apr 18, 2014 2:04 pm
Location: NiceLabel HQ
Contact:

Re: enable/disable button using vbs

Post by jure » Fri Oct 20, 2017 10:46 am

Hi,

You actually want to control the object visibility with the VBScript. We have a knowledge base article explaining how to achieve this: https://www.nicelabel.com/support/knowl ... al-objects

So basically you would place all the needed Ellipses on your label, and set them to "cut". Then you will control with the VBScript which of the ellipses should be "visible" (which essentially means active) and which not.
There is no place like 127.0.0.1

Manuel
Enthusiast
Posts: 7
Joined: Tue Oct 10, 2017 4:03 pm

Re: enable/disable button using vbs

Post by Manuel » Fri Oct 20, 2017 5:33 pm

Hi,

thanks for the reply.
Yes, i have already recieved an email from you, where you told me about this article.

I tried to use the code example in this article and modify it to my needs.
but i ran into the following error using this code:

Code: Select all

If currentDate = "10" Then
   Ellipse10 = label.SetObjectVisible(True)
End If
This is the error message:

Code: Select all

Error ID: 150603
Error description: 'The syntax validation of the script failed.'
Detailed information: 'Script error:
Argument is not optional.: 'label.SetObjectVisible'
Line number: 43'
Possible solution: ''
Severity ID: 3
Severity name: 'Error'
Available actions: OK 
Default action: OK
Group ID: 17
Type ID: 2
Can disable dialog: NO
Anyone having an idea why this is happening?

User avatar
jure
NiceLabel
NiceLabel
Posts: 186
Joined: Fri Apr 18, 2014 2:04 pm
Location: NiceLabel HQ
Contact:

Re: enable/disable button using vbs

Post by jure » Fri Oct 20, 2017 8:46 pm

Hi,

You need to correct your VBScript. You need to define the object element name inside SetObjectVisible method. And since you will want to control more objects with just one script, I would use something like this:

Code: Select all

Dim a
if currentDate ="10" then
  a = label.SetObjectVisible("Ellipse10",True)
  a = label.SetObjectVisible("Ellipse9",False)
  a = label.SetObjectVisible("Ellipse8",False)
  ...
elseif currentDate = "9" then
  a = label.SetObjectVisible("Ellipse10",False)
  a = label.SetObjectVisible("Ellipse9",True)
  a = label.SetObjectVisible("Ellipse8",False)
  ...
elseif currentDate = "8" then
  a = label.SetObjectVisible("Ellipse10",False)
  a = label.SetObjectVisible("Ellipse9",False)
  a = label.SetObjectVisible("Ellipse8",True)
  ...
elseif
...
else
end if 
As you can see each "if statement" will need to enable one object and disable all other, so you will need to type a quite big script, but since it is not very complicated, I believe this should be fairly easy task now.

Do not forget: When you are finished, the script provides output variable. Put this variable somewhere on the label, as otherwise, the script will not execute on print/preview.

One more thing: Do not verify the script while you are in the script editor because "label" object cannot be found in the script editor, as this is an internal NiceLabel object. When you will close the script editor, you can verify the script in the function editor, and there you should get no errors if the script will be correct.

Please let us know if you need more help.

Best regards,
Jure
There is no place like 127.0.0.1

Manuel
Enthusiast
Posts: 7
Joined: Tue Oct 10, 2017 4:03 pm

Re: enable/disable button using vbs

Post by Manuel » Mon Oct 23, 2017 7:34 am

Hello,

thanks for the reply.
Ok that makes perfect sense. I edited the script so it matches your guideline.
I checked the script and it gave me no errors. So hopefully it will work now.

I have one further question regarding this topic.
You wrote that i need to place the output variable somewhere on the label.
How can i achieve that?
I tried placing an object on the label and attach the variable to it.
But that doesn't seem to work.

User avatar
jure
NiceLabel
NiceLabel
Posts: 186
Joined: Fri Apr 18, 2014 2:04 pm
Location: NiceLabel HQ
Contact:

Re: enable/disable button using vbs

Post by jure » Mon Oct 23, 2017 8:38 am

Hi,

so when you create a function, you also can name an output variable of this function:
outputVar.jpg
outputVar.jpg (71.42 KiB) Viewed 3817 times
You simply need to place this output variable to the label as a text object for example:
outputVarObject.jpg
outputVarObject.jpg (48.96 KiB) Viewed 3817 times
This will ensure that the script will be executed on each print/preview.
There is no place like 127.0.0.1

Manuel
Enthusiast
Posts: 7
Joined: Tue Oct 10, 2017 4:03 pm

Re: enable/disable button using vbs

Post by Manuel » Mon Oct 23, 2017 4:19 pm

Ah ok awesome!
I got it working now. thanks a lot for your help!

Post Reply