VB in WinCC

userxyz

Member
Join Date
May 2002
Location
any
Posts
2,768
I have a tag called Resetbel. I want to make this boolean tag high while pressing a key...

So I made a button...

Then on press I want VB code.

I tried this:

Dim reset
reset = true
HMIRuntime.Tags("Resetbel").value = reset


but offcourse, this isn't good, any help how to link a bool ?
 
your code is totally messing up.I've ever use VB code,unfortunely I've forgot syntax(I always use help for syntax).

If you just want to make a pushbutton why you have to use VB code.
I think C script or normal WinCC fucntion is much easier.

If you want deep detail,plese give more detail 'bout your purposal

^_^
 
Combo said:
I have a tag called Resetbel. I want to make this boolean tag high while pressing a key...

So I made a button...

Then on press I want VB code.

I tried this:

Dim reset
reset = true
HMIRuntime.Tags("Resetbel").value = reset


but offcourse, this isn't good, any help how to link a bool ?

Your problem is the "=" sign.
Try:

Dim reset
reset = true
HMIRuntime.Tags("Resetbel").value reset

This should work.
 
no

no doesn't work.

What I need is:

Make a bit high while button is pressed.

If u use direct connection, than you can write the value 1 to a tag, but, in the PLC, the bit remains high, I want a bit that is high while pressed. And no, I will not use reset in the PLC, that's not clean.

About C scripting, ... maybe an example ? I don't know C and therefor prefere VB
 
C scripting this is very simple.

Just to set the bit high:
On your button->mouse click event->C Action

SetTagBit("Resetbel",1); //Insert this text in replacement of blue text in function



If you want to toggle this bit on each click try something like this

int x;
x =GetTagBit("Resetbel");
SetTagBit("Resetbel",x);
 
C scripting this is very simple.

Just to set the bit high:
On your button->mouse click event->C Action

SetTagBit("Resetbel",1); //Insert this text in replacement of blue
//text in function



If you want to toggle this bit on each click try something like this

int x;
x =GetTagBit("Resetbel");
SetTagBit("Resetbel",x);

If you have any problems with this let me know
 
Combo said:
I have a tag called Resetbel. I want to make this boolean tag high while pressing a key...

I don't have WinCC in front of me, so I didn't test this. You need to create two scripts. One for the mouse down event and one for the mouse up event for your screen object (button). You need to declare your tags first (please refer to the WinCC documentation CD it is quite good.) then write the value.

On a "press left" event, use something like this:

const YOUR_TAG = "ResetBel"
const BIT_ON_VALUE = 1
const BIT_OFF_VALUE = 0
dim oYourTag
set oYourTag = hmiruntime.tags(YOUR_TAG)
oYourTag.write = BIT_ON_VALUE

Then for the "release left" event you could use the opposite:

const YOUR_TAG = "ResetBel"
const BIT_ON_VALUE = 1
const BIT_OFF_VALUE = 0
dim oYourTag
set oYourTag = hmiruntime.tags(YOUR_TAG)
oYourTag.write = BIT_OFF_VALUE

You could perform a .read first before the .write to check for errors. Constants can be declared for the entire picture so you'll only need to do that once. (I consider a boolean tag a waste of an expensive tag so I would use 8-bit integers with bit filtering.)

Depending on what this function is for, why would you not set the bit and let the PLC handle the reset to ensure the request is seen by the PLC?
 
And no, I will not use reset in the PLC, that's not clean.

why would you not set the bit and let the PLC handle the reset to ensure the request is seen by the PLC?

I'm with stplanken (and Jesper, if I remember correctly) on this one. On the systems I'm cleaning up at the moment the OPs have been programmed using mouse down and mouse up to set and clear Marker Bits. Net result, on those stations where the cycle time is creeping up to around 40 ms or more, the operators tap a button to start a process then turn away to continue something else. A short time later they notice that the process they thought they had started isn't running. Once this happens a few times they can get quite upset.

By setting the Bit from the OP and clearing it in the PLC, you ensure that the Bit is always seen.
 
djeez

djeez... :)

The write thing is something from VB script, Am I right ?




stplanken said:
I don't have WinCC in front of me, so I didn't test this. You need to create two scripts. One for the mouse down event and one for the mouse up event for your screen object (button). You need to declare your tags first (please refer to the WinCC documentation CD it is quite good.) then write the value.

On a "press left" event, use something like this:



Then for the "release left" event you could use the opposite:



You could perform a .read first before the .write to check for errors. Constants can be declared for the entire picture so you'll only need to do that once. (I consider a boolean tag a waste of an expensive tag so I would use 8-bit integers with bit filtering.)

Depending on what this function is for, why would you not set the bit and let the PLC handle the reset to ensure the request is seen by the PLC?
 
Combo said:
The write thing is something from VB script, Am I right ?

I'm not sure I understand what you're asking. Yes, the example I gave you is true VBScript. Place the scripts in the object's mouse events for left press and left release. Right click the button object, choose properties, choose the events tab and right-click the press/release mouse events and select the VBScript option in the gaphics designer. In the editor ou can add the CONST declarations in the picture global section so it is available for all VBScripting for all objects in the picture.
 
actually VB script isn't suit for simple action like changing tag data for a pushbutton.It's suit for do link other applications (excel,access,etc) or some action that C script can't do.

I quit sure that's very easy for you to use C code,if you can use VB.
 
Nuuinc12 said:
actually VB script isn't suit for simple action like changing tag data

Combo clearly stated he wanted a VBS solution. The fact that you need to create an object is the way VB/VBScript works, nothing wrong with that. VBScripting in WinCC is very forgiving and solution-oriented, unlike that silly ANSI C that instantly crashes your server if you forget to allocate sufficient memory for a text string. We are getting off topic.
 
Correct me if I'm wrong, but:

When I create a button using WinCC and go to Object properties > Events, I have the choice of:
-Action
-Press Left
-Release left
-Press right
-Release right

Now why not set the bit with the Press Left action (using direct connection) and resetting the bit with the Release Left action?
This should work and needs no scripting and should work faster than running a script each time.(at least thats what the siemens-trainer told me.....)
 
1st, I am with Jeebs, why use scripts to solve something that you can do without scripts ?

2nd, even if you can do it with or without scripts, like Roy says, no matter if you do it like this, it has its clear disadvantages.
And it is much worse than the 40ms cycle time Roy mentions, he probably means the cycle time in the PLC, but what about the tag update time in WinCC ? A mouseclick only lasts a few milliseconds, and a typical tag update time is 1 second (400 ms if you have set it up to be fast). So for it to work the operator has to force himself to hold the button pressed for a little while in an unnatural way.
Add to that there are many things that can go wrong, so you risk that the bit never gets reset.
I have gone away from that because I have been burned.
 

Similar Topics

Greetings I have a problem, my system is the following: wincc v8.0 (demo), logo8.3, abb m2m analyzer. I created some pages to display the...
Replies
0
Views
48
Hi, We have upgraded our laptop which includes Windows 11. It appears that WinCC flexible 2008 advanced does not support Windows 11. What...
Replies
11
Views
247
In our production plant we have multiple different networks (subnets). IT dept have setup routing between them so different subnets can...
Replies
0
Views
81
Is it possible to connect a PC with running WinCC Advanced or Unified to a siemens PLC such as S7-1200 across different subnets? The computers can...
Replies
0
Views
66
We are using wincc scada WinCC system software V7.5 SP2 , connected to few plc . Past 3 weeks we getting this alarm continously when we checked...
Replies
0
Views
75
Back
Top Bottom