UiPath: How to set default values to a String[] variable - c#

I have an exception when I'm trying to launch my workflow. It cames from my array declaration where I apparently don't have the right syntax.
My syntax really looks like the one used in the UiPath tuto I follow :
The tuto syntax:
My syntax:
I don't understand how I'm supposed to write the default values for a simple array of strings...
I'm only trying to pass the values in a Write Line activity, but this shows up when compiling:
If anyone can help, I'm stuck... Thanks
--- EDIT ---
The exception message is the following one:
Message: Compilation failure:
; expected Unvalid expression terms ',' ... many times...
The full results are stored in the Data property of this exception. Correct the errors of the source, then retry the load.

I found the problem: I did not instantiate the array with new String[] at the beginning. I suppose that the tutos are written using VB and not C#, which can explain the difference.

your declaration is correct maybe you have error in the loop here is a working example

Related

C# how to get value from specific cell datagridview

i am working on C# and trying to save my datagridview to xml.
my code as follow :
writer.WriteStartElement("NamaBarang");
writer.WriteString(dgvCart.Rows[i].Cells[1].Value.ToString);
writer.WriteEndElement();
and the error occur at
writer.WriteString(dgvCart.Rows[i].Cells[1].Value.ToString);
Error 2 The best overloaded method match for
'System.Xml.XmlWriter.WriteString(string)' has some invalid
arguments C:\Users\Eric\Desktop\C#\Gridview\Gridview\Form1.cs 59 25 Gridview
and
Error 3 Argument 1: cannot convert from 'method group' to
'string' C:\Users\Eric\Desktop\C#\Gridview\Gridview\Form1.cs 59 44 Gridview
i am previously a vb user so i am having a hard time in c#
please help.
Youve forgotten to put empty brackets () after your ToString
VB isn't bothered about this but c# is- every time you want to call a method that has no arguments, you have to put empty brackets
//this is fine in VB
Dim x as String = y.ToString
//so is this
Dim x as String = y.ToString()
//in c# we insist on brackets when calling a method
string x = y.ToString();
//no brackets means "get the value of the property"
int I = mystring.Length;
Seeing something that looks like a method name, without brackets, usually means it's a property rather than a method. It can occasionally mean that the method itself is being used as an argument - a way of passing a method around as a variable, but that's beyond the scope of what we're discussing here.. Read up on delegates if you're interested.
In short, if you want to call a method in c#, it absolutely must have brackets after the name, whether there are arguments or not
Also handy to remember that when you see the error about "is a method group" it probably means you've tried to call a method but omitted the brackets.
C# is a struggle for VB people because it's essentially way more demanding that the syntax be absolutely right- you'll get used to it though, and it does help eventually!

setgraphicsAPIs is Overloaded Method match (C# Unity)

Can someone help me
PlayerSettings.SetGraphicsAPIs (BuildTarget.Android, TargetGlesGraphics.OpenGLES_2_0);
gives me this compile error :
Assets/_Developer/JEONG/Editor/BuildEditor.cs(776,18): error CS1502:
The best overloaded method match for
`UnityEditor.PlayerSettings.SetGraphicsAPIs(UnityEditor.Buil‌​dTarget,
UnityEngine.Rendering.GraphicsDeviceType[])' has some invalid
arguments
I don't know why but i follow the documentation in Unity
You should call it like that :
PlayerSettings.SetGraphicsAPIs (BuildTarget.Android, new [] { GraphicsDeviceType.OpenGLES3 });
As per the error message, the function is expecting an array of GraphicsDeviceType. Since you want only one device type, you still have to provide an array where there is one element.
Also, the value is GraphicsDeviceType.OpenGLES3 (full name with namespace : UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3 ), and not TargetGlesGraphics.Whatever .
You can see in error message that it expects a value as an array of GraphicsDeviceType, so I searched the unity doc to find this :
https://docs.unity3d.com/ScriptReference/Rendering.GraphicsDeviceType.html
Thank you sir Pac but i tried this one
PlayerSettings.SetGraphicsAPIs (BuildTarget.Android, new [] {UnityEngine.Rendering.GraphicsDeviceType.OpenGLES2});
and it works . Thank you also to everyone that help me. Sorry for my bad english

How to throw exception in epicor C#

What is the equivalent to &THROW_PUBLIC in C# or what does &THROW_PUBLIC mean is ABL? I don't know much about ABL but need to convert it to C#.
Code Snip from a Data Directive in Epicor 9.05
If ttPart.ProdCode = '' then do:
If lookup(SUBSTRING(ttPart.PartNum,1,3),'12-,13-,14-,15-',',') <> 0 then do:
{lib\PublishEx.i &ExMsg = "'Please select a Product Group for this Part'"}
{&THROW_PUBLIC}.
End.
End.
&THROW_PUBLIC is not a Progress ABL keyword or any standard feature at all. Most likely it's something specific to Epicor.
For better understanding of the problem perhaps you should post more code!
However: beginning with an ampersand might be a clue to it being a preprocessor. A preprocessor can be defined with GLOBAL-DEFINE or SCOPED-DEFINE - look for that in your code.
When the program is compiled any reference to the preprocessor (written like {&name-of-preprocesor} will be replaced with it's definition. Certain limited checks can be done (like for instance what OS is used for compiling).
Here's an example of two preprocessors being defined and used.
&GLOBAL-DEFINE THROW_PUBLIC1 MESSAGE "HELLO 1".
&SCOPED-DEFINE THROW_PUBLIC2 MESSAGE "HELLO 2".
{&THROW_PUBLIC1}
{&THROW_PUBLIC2}
After the precompiler the program will simply look like this:
MESSAGE "HELLO 1".
MESSAGE "HELLO 2".
The THROW part might indicate some kind of error handling being used like a THROW-CATCH-situation or similar. They are written something like this:
BLOCK-LEVEL ON ERROR UNDO, THROW.
DEFINE VARIABLE i AS INTEGER NO-UNDO.
ASSIGN
i = INTEGER("hello").
CATCH err AS Progress.Lang.Error:
MESSAGE "Error is caught here" VIEW-AS ALERT-BOX.
END.
FINALLY:
MESSAGE "This is run in the end" VIEW-AS ALERT-BOX.
END.
{&THROW_PUBLIC}. is defined in the Epicor include file manager\Exception.i (this is probably xcoded so you can't read it). This basically skips to the end of the {&TRY_PUBLIC} / {&CATCH_PUBLIC} block and publishes an exception.
In c# it is much easier:
throw new Ice.BLException("Please select a Product Group for this Part");
You can use a standard System.Exception but Ice.BLException (defined in Epicor.ServiceModel.dll) has some overloads to record extra information which other parts of the framework can display/log.

HtmlAgilityPack Issue in reading html

I am reading websites in C# and get contents as string....there are some sites which do not have well formed html structure.
I am using HtmlAgilityPack which give me issue in that case.
Can you people suggest me what to use so that it can read whole string and i can get useful informations?
Here is my code
htmlDoc.LoadHtml(s);
if (htmlDoc.ParseErrors != null && htmlDoc.ParseErrors.Count() > 0)
Why this IF Condition is true for my case
What is the error you're getting? Is it throwing an exception or are you just wanting to see the error? Hard to tell what your actual question is.
You can see the markup errors in the HTML by using the HtmlDoc.ParseErrors property and iterate though them. This will give you the line number, code and type of error.
You can see more info about this property here
https://stackoverflow.com/a/5367455/235644
Edit
Ok so you've updated your question since my reply. You can see the specific error that's returning true in your IF statement by looping through the .ParseErrors are described above.
Second Edit
You can loop though the errors like so:
foreach (var error in htmlDoc.ParseErrors)
{
Debug.WriteLine(error.Line);
Debug.WriteLine(error.Reason);
}
You have to fix the bug in your HTML, and after it is valid you can go on.
Here is the same problem:
Invalid HTML in AgilityPack
If your html is external and you can't fix it, you can first run it through a cleanup preprocessor, then parse it with HtmlAgilityPack.
This will attempt to fix as many issues as possible automatically before HtmlAgilityPack gets to see it. The most popular HTML cleanup tool is Tidy. See the .NET version here:
http://sourceforge.net/projects/tidynet/

C# How can I get from CompilerError instance exact text which caused the error

Could you please tell me how can I get from CompilerError instance exact text which caused the error.
Edited:
What about using
compilerError.FileName
and reading the file with text reader? I am trying to do so but it seems that Compiler doesn't create cs file that doesn't pass the compilation any suggestions?
This CompilerError? : http://msdn.microsoft.com/en-us/library/system.codedom.compiler.compilererror.aspx
There are FileName and Line properties, that's the best you can get.
What are you compiling - is it entirely in-memory (CodeDOM)?
If so you can add code-line pragmas to your object model: http://msdn.microsoft.com/en-us/library/system.codedom.codelinepragma.aspx then you'll be able to link an error to a DOM element.
Or, you can compile from source, then you'll have the source code itself and can get the text from the line number.
The best your going to get is the line number.

Categories