Reputation: 197
All, I am writing a c# script where I want to check if a windows pop-up titled "Script Error" is visible and return True or False. To do this I have had to use static extern which I believe I am using incorrectly but not sure how to correct.
Please can someone advise how to resolve the error I am seeing:
Error Message - Type Or namespace definition or end of file expected
**Please note the parenthesis which are causing the issue I have labelled Error Parethesis however I am not entirely sure these are causing the overall issue.
Please see full code below:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Xml;
namespace Dynamic.Script_8D737880D773F26
{ **Error Parathesis
// Script generated by Pega Robotics Studio 8.0.2032.0
// Please use caution when modifying class name, namespace or attributes
[OpenSpan.TypeManagement.DynamicTypeAttribute()]
[OpenSpan.Design.ComponentIdentityAttribute("Script-8D737880D773F26")]
public sealed class Script
{
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern IntPtr FindWindowByCaption(IntPtr zeroOnly, string lpWindowName);
}
{
public bool ScriptErrorVisible()
{
if (FindWindowByCaption(IntPtr.Zero, "Script Error") != IntPtr.Zero)
{
return true;
}
else
{
return false;
}
}
}
} **Error Parenthesis
Upvotes: 0
Views: 234
Reputation: 1181
As the others have said, a good place to start would be to indent properly. To actually explain your issue rather than just post the answer, see the below explanation:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Xml;
namespace Dynamic.Script_8D737880D773F26
{
// Script generated by Pega Robotics Studio 8.0.2032.0
// Please use caution when modifying class name, namespace or attributes
[OpenSpan.TypeManagement.DynamicTypeAttribute()]
[OpenSpan.Design.ComponentIdentityAttribute("Script-8D737880D773F26")]
public sealed class Script
{
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern IntPtr FindWindowByCaption(IntPtr zeroOnly, string lpWindowName);
} // << Your class ends here
{ // << Opened brackets without declaring a class
public bool ScriptErrorVisible()
{
if (FindWindowByCaption(IntPtr.Zero, "Script Error") != IntPtr.Zero)
{
return true;
}
else
{
return false;
}
}
} // << This would close the class, but you haven't declared one
} // << This ends the namespace
So this is the answer:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Xml;
namespace Dynamic.Script_8D737880D773F26
{
// Script generated by Pega Robotics Studio 8.0.2032.0
// Please use caution when modifying class name, namespace or attributes
[OpenSpan.TypeManagement.DynamicTypeAttribute()]
[OpenSpan.Design.ComponentIdentityAttribute("Script-8D737880D773F26")]
public sealed class Script
{
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern IntPtr FindWindowByCaption(IntPtr zeroOnly, string lpWindowName);
public bool ScriptErrorVisible()
{
if (FindWindowByCaption(IntPtr.Zero, "Script Error") != IntPtr.Zero)
{
return true;
}
else
{
return false;
}
} // << Closes the ScriptErrorVisible method
} // << Closes the Script class
} // << Closes the Dynamic.Script_8D737880D773F26 namespace
Upvotes: 2
Reputation: 563
It looks like you had a couple of hanging brackets. Try this.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Xml;
namespace Dynamic.Script_8D737880D773F26
{
// Script generated by Pega Robotics Studio 8.0.2032.0
// Please use caution when modifying class name, namespace or attributes
[OpenSpan.TypeManagement.DynamicTypeAttribute()]
[OpenSpan.Design.ComponentIdentityAttribute("Script-8D737880D773F26")]
public sealed class Script
{
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern IntPtr FindWindowByCaption(IntPtr zeroOnly, string lpWindowName);
public bool ScriptErrorVisible()
{
if (FindWindowByCaption(IntPtr.Zero, "Script Error") != IntPtr.Zero)
{
return true;
}
else
{
return false;
}
}
}
}
Upvotes: 3