Clarion 9.1 - use Variable for Routine Name - clarion

I need to pass the name of a Clarion routine to a Variable and run it.
E.g:
!************************
RoutineName='CalculateSomething'
DO RoutineName
!************************
It does not work in this format so I've also tried other characters (brackets, quotations etc) before and after the variable. No luck.
Please note that the Routine 'CalculateSomething' exists and runs fine with the basic command:
!************************
DO CalculateSomething
!************************

How about using a case statement to do this?
RoutineName='CalculateSomething'
CASE RoutineName
OF 'CalculateSomething'
DO CalculateSomethingRoutine
OF 'SomethingElse'
DO SomethingElseRoutine
ELSE
Stop('Unknown routine named: ' & RoutineName)
END

I think there no option like that on the Clarion programing language.
The only way that I suggest to CASE statement like that:
RoutineName='CalculateSomething'
CASE UPPER(RoutineName)
OF 'CALCULATESOMETHING'
DO CalculateSomething
OF 'CALCULATESOMETHINGELSE'
DO CalculateSomethingElse
OF 'CALCULATENOTHING'
DO CalculateNothing
END

Related

VBA script issue specifying command line

So I'm fairly new to VBA, using it within some spreadsheets so forgive me if this is a super obvious fix, I'm sure it is but have spent hours on with with no success.
The following piece of code will lie inside of an if statement - not sure if thats worth mentioning or not.
I want to simply move, and rename files from one location to the other
It needs to utilize cmd.exe, and use the 'move' argument - the source path and source destinations will be changeable depending on the pc - so it will need to use the '%temp% - as the initial file will be stored in this folder, and %userprofile% for the destination path.
Here is the code so far - I think the issue is just to do with the formatting -
Sub movefile ()
Dim Origpath As String
Dim NewPath As String
OrigPath="%temp%\newfile.txt"
NewPath="%userprofile%`Documents\newfile.vbs"
<<next code inside of an if statement>>
moveFile="C:\windows\system32\cmd.exe /C move " & OrigPath & " " & NewPath
End Sub
Maybe the " and & arent placed correctly? But the code works fine up until the line 'movefile...'
Probably a super easy way of doing it - help please!!
Try using Name:
name OrigPath as NewPath
Alternatively you can use use fdo movefile, as explained in this answer.

Spreadsheet::ParseExcel::SaveParser Issues - Cannot Obtain a Defined Workbook Object

I am trying to use the Spreadsheet::ParseExcel::SaveParser plugin using example code at both metacpan.org and on SO and I cannot define the template (workbook).
I have played around with variations on the new statement, quotes, file parh, etc - nothing works. I put a die after the template statement and it prints the error message. Without that I have either a $template->worksheet() or worksheets() statement and if I skip the die I get a different message. I confirmed that the path to the Excel file is correct. I also new()'ed Spreadsheet::ParseXLSX instead and the code got past the template undefined problem - of course it crashed when I tried to do an AddCell.
use Spreadsheet::ParseExcel;
use Spreadsheet::ParseExcel::SaveParser;
my $saveParser = Spreadsheet::ParseExcel::SaveParser->new();
my $template = $saveParser->Parse("some Excel file verified to exist");
die "Error! Template not defined!\n" if (!defined($template));
dies
use Spreadsheet::ParseExcel;
use Spreadsheet::ParseExcel::SaveParser;
my $saveParser = Spreadsheet::ParseExcel::SaveParser->new();
my $template = $saveParser->Parse("some Excel file verified to exist");
my $worksheet = $template->worksheet(0);
Can't call method "worksheet" on an undefined value at ../bin/update_tp.pl line nnn. It also errors out if I use the worksheet name instead of number.
Obviously I expect the $saveParser->Parse command to return a valid object so I can work with it - it doesn't. FYI all modules I'm using are at the current rev of 0.65 except WriteExcel (which isn't relevant yet), which is 2.4.
Think you'd want to track down what error-handling is available for the Parse() function by reading the CPAN page for this module. Find and adapt that error-handling to give you an inkling of why Parse() would be failing. Your error about "worksheet on an undefined value" is indicative of that call failing. Could be you're not escaping file paths, maybe you don't have read permissions on the file, lots of other reasons Parse() could be failing. Eww, just went and looked myself, and there's fairly inadequate error-handling documented for that function. Maybe try die'ing with some error-handling variables? See https://perldoc.perl.org/perlvar.html#Error-Variables

Vala TextBuffer backspace() SIGSEG

In order to practice writing on Vala I decided to make a virtual keyboard. Everything works, except Backspace(SIGSEG if press).
https://developer.gnome.org/pygtk/stable/class-gtktextbuffer.html#method-gtktextbuffer--end-user-action
I have not found any example of using this function in Vala.
source
I don't know why, but it works if you replace
Sas.end.backward_chars (Sas.input.buffer.cursor_position);
with
Sas.input.buffer.get_iter_at_offset(out Sas.end,Sas.input.buffer.cursor_position);
SIGSEG was on line:
Sas.input.buffer.backspace(Sas.end,true,true);
P.S. input - TextView, end - TextIter.

Equivalent of String.Format in a Chef/Bash Recipe

looking for something similar to .Net string format in a chef recipe ie.
string phone = String.format("phone: {0}",_phone);
I have a Chef recipe where I need to build up a command string with 30 of these params so hoping for a tidy way to build the string, in principle Im doing this
a=node['some_var'].to_s
ruby_block "run command" do
block do
cmd = shell_out!("node mycommand.js #{a}; exit 2;")
end
end
When I try this I get the error
Arguments to path.join must be strings any tips appreciated
Chef runs in two phases:
Compile and Execute (see https://www.chef.io/blog/2013/09/04/demystifying-common-idioms-in-chef-recipes/ for more details).
Your variable assignment to a happens at compile time, e.g. when chef loads all recipes. The ruby block will be execute in execution mode at converge time and cannot access the variable a.
So the easiest solution might be putting the attribute into the ruby block:
ruby_block "run command with argument #{node['some_var']}" do
block do
shell_out!("node mycommand.js #{node['some_var']}")
end
end
However:
If you don't need to execute Ruby code, consider using the execute or bash resource instead.
Keep in mind, that you must have a unique resource name, if you're building some kind of loop around it. An easy way is to put something unique into the name ruby_block "something unique per loop iteration" do ... end
What I really don't understand is your exit code 2. This is an error code. It will make chef throw an exception each time. (shell_out! throws an exception if exit code != 0, see https://github.com/chef/chef/blob/master/lib/chef/mixin/shell_out.rb#L24-L28)
The resource will be executed on each chef run. This is probably not in your interest. Consider adding a guard (test), to prevent unnecessary execution, see https://docs.chef.io/resource_common.html#guards

Is it good practice to leave "Debug.Print" instructions in code that goes in "production"?

In Excel VBA, is it good practice to leave Debug.Print instructions in code that goes in "production" ? That is quite useful to debug the sheets realtime at the user's machine when something goes wrong. Does it affect performance when Visual Studio is closed ? If not, what would you advise ?
Debug.Print instruction DO have a small performance cost. So I would avoid them in loops that are executed a zillion times. Except for those cases, I think it's ok to keep them.
You could also use conditional compilation directives (#if) in combination with a compiler constant (#const) to enable/disable them globally without performance impact.
#CONST developMode = True
sub Xyz
#If developMode Then
Debug.Print "something"
#End If
End Sub
I usually have two versions; prod without debugging, and prod with debugging. That, combined with the catchall error handler logging, means that if a user experiences issues, I can deploy the debug version to them and they can run that up.
I have a macro that I run that comments out the debug.print statements, so it's not a real maintenance overhead.
The problem with running a debug version all the time (and, with Excel VBA it's not usually a performance thing) is that your app is constantly emitting information that it doesn't need too. In an environment with controlled spreadsheets, for example, this can be seen as a bad thing.
In terms of global error handling, you still need the On Error GoTo statement for every function you want error handling in. You can, however, pipe these to a common function:
Public Function HandleTheNastyErrors(E As ErrObject, ByVal writeLog As Boolean = True)
Select Case E.Number
Case xxx
...specific error handling...
Case Else
... Display a message to the user about how you dont know what happened....
End Select
If writeLog Then
...Log Writing Code...
End If
End Function
And then, OnError:
ErrorHandler:
Call HandleTheNastyErrors(Err, True)
Show do the trick

Resources