Variable read issue on VSTA
A variable shows the value -2147483638 when read by a VSTA even if it linked to a screen and DDE is set to active.
I have this following C# snippet:
C# Code:
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;
}
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:
C# Code:
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;
}
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?
This is a migrated post! Originally posted on 26.02.2020 by user MOSA_SENMATIC. Please be aware that information can be outdated.