C# Code:The output is as follows: "Not advised -> Depname: DEP01 username 1: -2147483638" the "GetProjectUserName" function is called in a VSTA Macro on runtime startup. The variable which is not found is "DEP01.TextString". I made sure that the variable is linked to the screen on startup: It has also been set to DDE active: Here i have my AUTOSTART sequence for my project: The screen switch where DEP01.TextString is included, is called before the VSTA Macro which calls "GetProjcetUserName". However the variable gets advised if i call "MessageBox.Show" Before reading the value:
public string GetProjectUserName(zenOn.IProject globalProj, string depName) { using (System.IO.StreamWriter w = System.IO.File.AppendText(@"C:\Senmatic\log2.txt")) { var userNameVar = globalProj.Variables().Item(depName + ".TextString"); if (userNameVar != null) { var valu = userNameVar.get_Value(1); if (userNameVar.IsOnline()) { Log("Advised -> " + "Depname: " + depName + " username 1: " + valu, w); } else { Log("Not advised -> " + "Depname: " + depName + " username 1: " + valu, w); } var val = (string)userNameVar.get_Value(1); return val; } } return null; }
C# Code:Output: "Advised -> Depname: DEP01 username 1: " I have been struggling with this issue for a while. I'm not sure if i have a threading issue or something else. Why do the variable doesn't get advised even tho it's linked to a screen and DDE is active?
public string GetProjectUserName(zenOn.IProject globalProj, string depName) { using (System.IO.StreamWriter w = System.IO.File.AppendText(@"C:\Senmatic\log2.txt")) { var userNameVar = globalProj.Variables().Item(depName + ".TextString"); if (userNameVar != null) { //The variable gets advised if i call this MessageBox MessageBox.Show("Test"); var valu = userNameVar.get_Value(1); if (userNameVar.IsOnline()) { Log("Advised -> " + "Depname: " + depName + " username 1: " + valu, w); } else { Log("Not advised -> " + "Depname: " + depName + " username 1: " + valu, w); } var val = (string)userNameVar.get_Value(1); return val; } } return null; }
This document governs the use of our Community Forum. By registering and using the platform, you accept these conditions.
The COPA-DATA Community Forum serves to encourage the exchange of information and experience about the zenon software between forum users respectively zenon users.
Please mind that any published information on the Community Forum is the subjective opinion and view based on the experience and the level of knowledge of the author. COPA-DATA does not overtake any responsibility for the content and the accuracy of the shared information.
Users of the Community Forum are encouraged to share only well-founded experiences and to point out any risks associated with the implementation of proposed solutions to problems. COPA-DATA at its absolute discretion, reserves the right to moderate the forum. In this connection COPA-DATA may remove any information containing false facts, potentially dangerous solutions, bad language or content that may insult, degrade or discriminate others. COPA-DATA may block a non-complying user from forum access if the user violated this provision.
COPA-DATA reserves the right to change this document from time to time at own discretion.
Ing. Punzenberger COPA-DATA GmbH
Karolingerstraße 7b · 5020 Salzburg · Austria
www.copadata.com