As mentioned in past threads, when the error message, “This location is marked as const, so its value cannot be modified”, is encountered, it is due to a Read-Only variable attempting to be modified.
I noticed that I am also having problems when I try to use it on assignment to local variables. Why can I not set the initial value of a non-Read-Only local variable to a read only variable?
This is kind of goofy logic you’re trying to use here. You don’t set one variable to true and another to false and then check against those variables. True and false are values themselves, you don’t need them in variables. You’re making extra work for yourself.
Directory.Exists() returns boolean, so you can just do…
If for some reason you want to use the Path Exists activity, the result is that its output variable (pathExists, or whatever you named it) has a value of true or false, so you can just do…
Again, though, that’s extra work because you’re creating variables and splitting it into multiple steps/activities, when you can just directly use the Directory.Exists() method in one step.
The variable DoesNotExist is intended to act as a constant that avoids “Imaginary Boolean” values. So there is not a question on what the boolean value False actually represents. By setting it to a constant, the constant describes False.
The Path Exists activity could be removed entirely, as you recommend, as it does not seem too cluttered. I would probably want to put the string path in a constant variable to avoid a magic string.
The single variable conditions on the Boolean seem appropriate to me, however, I’ve seen single variable Boolean values that did not adequately describe the condition. When applied with constants they add additional context to the condition.
I appreciate the possible clean up of code, however, I’m still inquiring about the Read-Only variables being assigned to non-Read-Only variables.
The screenshots are still valid above. As mentioned some of the code could be refactored, however, a variable that is intended to be a read-only constant cannot be used for initialization.
In your example, you mentioned assigning a variable of 2 and then checking again later if it is 2. The number 2 could be added to a constant that describes 2, so we know more about what 2 represents. That way when our business logic executes, and possibly changes the value of myVar to 3, we know it no longer represents the condition that our read-only constant (of 2) describes. It also works well for reusability, if the constant should need to be referenced again later. However, in the current state of things, the constant could not be used for initialization before the bulk of the business logic is performed on it.
Sorry for the delay. The ValidateEnvironment workflow highlight above is using the DoesNoteExist read-only variable to initialize the non-read-only variable directoryExists. Also, I wasn’t stating that the read-only variable cannot be used for initialization as fact, but only that it cannot in my current configuration.
Somewhere you’ve designated directoryExists as read only. Use the universal search to see if maybe you accidentally defined that variable more than once. If not, try deleting and redoing the Assign activity. Sometimes it gets “stuck” and you have to redo it.
I performed the following, but I am still encountering the mentioned output. Also, just a FYI, I am using UiStudio 2022.4.5, RE Framework version 22.4.11.
Did a search on the local variable to examine if the same name was used in multiple scopes with one being read only. I found none.
I deleted the assign activity, and recreated it.
I deleted the entire workflow file, and created a new one in the same project.
I created a new project w/ the mentioned RE Framework template.
I created a new process project. When the read only variable is not defined, the process executes. As soon as the read only variable is defined, the mentioned output occurs.
I created a read-only in my current project, and even gave it a value in Default, and it worked fine.
What Arguments are you using, since these are invoked files? The error may be related to the Arguments, that’s why it always appears to be the first activity that faults.
For the project that is just a process, there are no arguments.
For the question on if the project is in a zip file, no we are not opening these files in a zip file. We store our code in source control (DevOps) and pull it down for modifications.
Based on above, it doesn’t matter if the project is using the RE Framework or not. A simple project (Compatibility = Windows; Language = VB) with a single process will produce the exception for me. I did a few more tests.
When the project was first created, I added a sequence to the main process. I defined a read only variable in the scope of the sequence, and ran the project. No exception was thrown.
I added a single WriteLine activity, with the text “test”, into the sequence. No exception was thrown.
I then added an assign activity after the WriteLine activity. I tried to assign a string variable the value of “test”. The exception was thrown.
I captured a few more, possibly relevant snippets.
(Also, as a recap, this is for VB - Windows Compatibility)
I found that if only string constants are used in the process, this issue does not popup. As soon as a Boolean constant or Int32 constant is defined, the error is trigger.