WinCC V6 VBS Issue (Not Flex)

OzRoo

Member
Join Date
Dec 2013
Location
Brisbane
Posts
19
Hi,

First post for me, although I've lurked here a bit over the years, I've searched for more info in Seimens help, website and here for around 12 hours to get this far, Most of the info about seems to be dead links or WinCC Flex.

I'm trying to get a DINT to display in a Static Text box as Hex, most of the project is in C but it doesn't have a Hex conversion function AFAIK, so I'm tryng to get it to work in VBS, my first VBS script ever.

If I replace HexString in the Text statement to "Test1" it displays ok, but if I set HexString to "Test1" it doesn't work for some reason, So I'm thinking I'm setting varibale types wrong somehow but can't see any issues in Help & the scripts I've checked against.

Code:
Function Text_Trigger(ByVal Item)
 
Dim ObjName, DINTTag, HexValue, HexString, HexTag
 
 Set ObjName = ScreenItems("PunchCodeHex1")
 Set DINTTag = HMIRuntime.Tags("BNDDoors_SERVERPC::Panel00PunchCode")
 Set HexTag = HMIRuntime.Tags("BNDDoors_SERVERPC::Panel00PunchCodesHex")
 
 DINTTag.Read
 Set HexValue = Hex(DINTTag)
 Set HexString = CStr(HexValue)
 
 HexTag.Write HexString
 ObjName.Text HexString
 
End Function
 
Hmm no help on this still?
I believe I'm doing something simple wrong or not setting the varible types correctly somehow, as if I do ObjName.Text "Test123" it shows just fine
 
I cant give much help as I only have flex myself but a few points.

First, you can use C for this:

char s[5]; // 4 chars + '\0'
int x = 4660; // stand in for your data
sprintf(s, "%04X", x); // s is the char array that will contain the hex value. x is the int data.

Be sure to surround the above with code to prevent a out of range value from being evaluated. The above code is good up to 65535 decimal value.
Also remember that the version of sprintf that comes with WinCC can only process 360 characters.

Refering to using VBS:
Second, unless the version of Hex() that is included with WinCC is different from the standard version the Hex() function returns a string value. There should be no need to convert it again.

Third, if you don't already have one get a script debugger and set breakpoints to allow you to see what the values are as the script runs. You can get a free one from http://www.microsoft.com/en-us/download/details.aspx?id=22185 .

To answer your primary question:

Set HexString = CStr(HexValue) and Set HexString = "Test1"

both don't work (and probably Set HexValue = Hex(DINTTag) as well) because "Set" is used to create an object reference and all you need on these lines is to assign a value to the variable.

HexValue = Hex(DINTTag)
HexString = CStr(HexValue)

These should work better but get a debugger and step through looking at the data as it changes.

Hope this helps.
 
Thanks for the help & effort of your reply, we had a go at your solutions, but no win on this for whatever weird Siemens reasoning, we ended up doing the hex in the PLC and sending it as a string instead of an integer.
 

Similar Topics

Hello, I just started learning WinCC V8.0 3 days ago, so I'm still new to how everything works in this program. I've created a pop-up with a...
Replies
2
Views
638
Hello everyone. I'm trying to export data to excel from Wincc. My code is global action that executed every second that create excel filer per...
Replies
0
Views
5,611
Hello all, I have written a VBS script to read a group of tags, and put the values and tag name etc into a text file when I press a button on one...
Replies
1
Views
1,862
Hi, In my Plant i have PCS7 (WinCC V6.0+SP4) System.( one ES/OS and One OS )... I need Shift Report (every 8 Hours ) using VBS script or Default...
Replies
1
Views
2,214
Hi I am trying to vary the number of decimal places via a script (MP377) Dim obj Set obj =...
Replies
0
Views
1,302
Back
Top Bottom