using REXX to access vm370 disks - rexx

REXX is completely new to me, I like it so far. I am using SixPack running on Hercules. VM/370 is a nice environment, but I am trying to make it user friendly; filling in scripts for everything that works-so as to not need to repeat my steps.
The file attached below was written to search in ISFP, instead I want it to access disks. It searches for a specified file.
I do not know enough to rewrite a REXX program. It stops at strange places saying "found" this or that. Please, give any suggestions.
/* REXX */
ARG PROGNAME
PROGNAME = STRIP(PROGNAME)
ACCESS_TEMPLATE='A2 Y U'
USE VAR ACCESS_TEMPLATE A2 Y U /* NOT PARSE */
VAR1 = A2
VAR2 = Y
VAR3 = U
IF PROGNAME == '' THEN DO
SAY 'ENTER MEMBER NAME'
FULL PROGNAME
PROGNAME = STRIP(PROGNAME)
IF PROGNAME == '' THEN DO
SAY NO MEMBER ENTERED. EXITING THE PROGRAM
EXIT
END
END
SEARCH.1 = PROD1.LIB
SEARCH.2 = PROD2.LIB
SEARCH.3 = PROD3.LIB
CNT = 3
FND = 'N'
DO I = 1 TO CNT
ACCESS 'VAR1' 'VAR2' 'VAR3'
LIB = LIST.I(PROGNAME)
IF SYSDSN('LIB') == OK THEN DO
FND = 'Y'
TYPE('LIB')
END
END
IF FND == 'N'THEN DO
SAY MEMBERS NOT FOUND IN ANY LIBRARIES
SAY PLEASE CHECK THE MEMBER ENTERED
EXIT
END

This is a bit late but it's good advice for novice REXX programmers...
Right near the top of your program put in this:
SIGNAL ON NOVALUE
and then near the every end...
NOVALUE: SAY 'NOVALUE error at line' SIGL
exit 4
Why? REXX has a "feature" in that every undefined variable resolves to its own name in UPPER case, like this:
myvar1='hi there'
mayvar2=', joe'
say myvar1||myvar2
What you probably intended to SAY was
'hi there, joe'
but instead got
'hi thereMYVAR2'
If you had SIGNAL ON NOVALUE it would have given you an error message which is a lot better. I ALWAYS put this into my code.

Related

MATLAB String Input If statment

I'm trying to make a program that asks a yes or no question. Based on that answer the program will continue or terminate. I keep getting an error since the arrays don't have the same dimension. I tried to use strcmp() but failed. I don't understand how true or false will help me discriminate between different words and capitalization. (Do I have to test each letter?) I want the program to continue if the input is any of these words 'yes','YES','Yes','y' and quit if the input is 'no','NO','No','n' I really want to understand, the == feels wrong somehow.
Thank You
ZZ=input('Do you want to know when you''ll turn 100?: ', 's');
NN={'no','NO','No','n'}
YY={'yes','YES','Yes','y'}
XX=strcmp(ZZ(NN),ZZ(YY)); %I thought this line would let MATLAB know everything is ok
if ZZ=='no' || ZZ=='NO' || ZZ=='No' || ZZ=='nO' || ZZ=='n'
disp('Thank You.')
disp('Come again.')
elseif ZZ=='yes' || ZZ=='YES'|| ZZ=='Yes'|| ZZ=='y'
x=input('Enter your age: '); %x is your age.
.....
I think if you need your program to run more than once, you need a for or while loop.
zz = 'yes';
while strcmpi(zz(1),'y')
x = input('Enter your age: ');
zz = input('Do you want to know when you''ll turn 100?: ', 's');
end

LibreOffice Macro always show #NULL! after reopening the file

I wrote a macro in LibreOffice Calc and it is able to run correctly. But if I close the file and reopen, it always show #NULL! instead of the correct value. What am I missing here?
My macro code
Rem Attribute VBA_ModuleType=VBAModule
Option VBASupport 1
Function Calculate(CalType As String) As Double
'
' Calculate Macro
'
Dim i As Integer
Calc = 0
i = 1
Do While Not IsEmpty(Cells(i, 2))
If (Cells(i, 3).Value = CalType And (Cells(i,2) = "A" Or Cells(i,2) = "B")) Then
Calculate = Calculate + Cells(i, 4).Value
ElseIf (Cells(i, 3).Value = CalType And Cells(i,2) = "C") Then
Calculate = Calculate - Cells(i, 4).Value
End If
i = i + 1
Loop
'
End Function
The calling function will be something like =Calculate(J6)
The file is saved as .ods format.
The Cells call did not work at all for me. It is from VBA, not LO Basic. However I do not think that is the main problem.
LibreOffice expects that user-defined functions will be simple, only accessing the cell that contains the formula. Since the spreadsheet has not been fully loaded yet when the function is called, it is not possible to read other cells.
The workaround is to ignore errors and wait until the document is fully loaded before running the function. Take the following code as an example:
Function ReadOtherCell(row, col)
On Error GoTo ErrorHandler
oSheet = ThisComponent.CurrentController.ActiveSheet()
oCell = oSheet.getCellByPosition(row, col)
ReadOtherCell = "value is '" & oCell.getString() & "'"
Exit Function
ErrorHandler:
Reset
End Function
Sub RecalculateAll
' This is for user-defined functions that need to read the spreadsheet.
' Assign it to the "View created" event,
' because before that, the spreadsheet is not fully loaded.
ThisComponent.calculateAll
End Sub
Enter foo in A1, and =ReadOtherCell(0,0) in A2. So far, this has the same problem -- It will fail when the document is first opened.
Now, go to Tools -> Customize. In the Events tab, highlight View created. Press Macro... and find the RecalculateAll function. Then press OK.
Now when the document is closed and reopened, cell A2 should show the result value is 'foo'.
This is derived from B. Marcelly's answer at http://ooo-forums.apache.org/en/forum/viewtopic.php?f=20&t=73090&sid=f92a89d676058ab597b4b4494833b2a0.
I had the same problem.
I noticed that in the module, i had an empty Sub Main
After i 've erased it, the functions started working again

Sub- or Function Procedure not defined

I am writing my first macro for Libre Office right now and I have come into a bit of a problem: My code throws the error: BASIC Runtime error; Sub- or Function procedure not defined.
The line with the "If Cells (RowCnt,ChkCol......) throws the error.
I've looked through other entries on here, but I could not find the error... can anyone help me?
REM ***** BASIC *****
Sub Zeilennausblenden_Nullsummen
BeginRow=4
EndRow = 46
ChkCol= D
For RowCnt = BeginRow To EndRow step 1
If Cells(RowCnt,ChkCol).Value > 1 Then
Cells(RowCnt,ChkCol).EntireRow.Hidden = True
End if
Next
End Sub
PS: The function should hide all rows in which an integer higher than "1" appears in column "D"
Thanks in advance
Here is what the code looks like in LibreOffice Basic (aka StarBasic):
Sub Zeilennausblenden_Nullsummen
BeginRow=4
EndRow = 46
ChkCol= 3
oSheet = ThisComponent.Sheets(0)
For RowCnt = BeginRow To EndRow step 1
oCell = oSheet.getCellByPosition(ChkCol,RowCnt)
If oCell.Value > 1 Then
oRow = oSheet.getRows().getByIndex(RowCnt)
oRow.IsVisible = False
End if
Next
End Sub
I wasn't sure if BeginRow should be 3 or 4, because it's zero-based. You can test it and decide.
Note that a macro is not necessary in order to accomplish this task. The easiest way is to go to Data -> More Filters -> Standard Filter.
That's because CELLS isn't a StarBasic function.
It's VBA (different programming language). Some versions of OpenOffice support the use of it if a statement (Option VBASupport 1) is put in first line of source code.
Check the net for Andrew Pitonyak's "OpenOffice Macros Explained" document - very good for learning and available in German translation, too.

Creating a translator in MatLab

I am trying to create a simple program in Matlab where the user can input a string (such as "A", "B", "AB" or "A B") and the program will output a word corresponding to my letter.
Input | Output
A Hello
B Hola
AB HelloHola
A B Hello Hola
This is my code:
A='Hello'; B='Hola';
userText = input('What is your message: ', 's');
userText = upper(userText);
for ind = 1:length(userText)
current = userText(ind);
X = ['The output is ', current];
disp(X);
end
Currently I don't get my desired results. I instead get this:
Input | Output
A The output is A
B The output is B
I'm not totally sure why X = ['The output is ', current]; evaluates to The output is A instead of The output is Hello.
Edit:
How would this program be able to handle numbers... such as 1 = "Goodbye"
What's going on:
%// intput text
userText = input('What is your message: ', 's');
%// ...and some lines later
X = ['The output is ', userText];
You never map what you type to what is contained by the variables A and B.
The fact that they are called A and B has nothing to do with what you type. You could call them C and blargh and still get the same result.
Now, you could use eval, but that's really not advisable here. In this case, using eval would force the one typing in the strings to know the exact names of your variables...that's a portability, maintainability, security, etc. disaster waiting to happen.
There are better solutions possible, for instance, create a simple map:
map = {
'A' 'Hello'
'B' 'Hola'
'1' 'Goodbye'
};
userText = input('What is your message: ', 's');
str = map{strcmpi(map(:,1), userText), 2};
disp(['The output is ', str]);
I would recommend using a map object to contain what you want. This will circumvent the eval function (which I suggest avoiding like the plague). This is pretty simple to read and understand, and is pretty efficient especially in the case of a long input string.
translation = containers.Map()
translation('A') = 'Hola';
translation('B') = 'Hello';
translation('1') = 'Goodbye';
inputString = 'ABA1BA1B11ABBA';
resultString = '';
for i = 1:length(inputString)
if translation.isKey(inputString(i))
% get mapped string if it exists
resultString = [resultString,translation(inputString(i))];
else
% if mapping does not exist, simply put the input string in (covers space case)
resultString = [resultString,inputString(i)];
end
end
Take a look at the command eval. Currently, you are displaying the name of the variable that contains the string you want. eval will help you in actually accessing and printing it.
What you need to do it :
X = ['The output is ', eval(current)];
Here the documentation : eval

'Undefined function or variable' in Matlab

Here is my code:
function [im,sindx,end1]=alln(im,i,j,secret,sindx,end1)
slen=length(secret);
p=im(i,j);
neigh= [im(i-1,j) im(i+1,j) im(i,j-1) im(i,j+1) im(i-1,j-1) im(i+1,j-1) im(i-1,j+1) im(i+1,j+1)];
minpix = min (neigh)
maxpix = max (neigh)
if minpix < p < maxpix
lowlim = minpix+1;
highlim = maxpix-1;
range = highlim-lowlim+1;
nbits=floor(log2(abs(range)));
if sindx+nbits-1>slen
end1=1;
return
end
for k=1:nbits
bin(k)=secret(sindx+k-1);
end
b = bin2dec(bin);
newvalue1 = abs (minpix + b);
newvalue2 = abs (maxpix - b);
if abs(p-newvalue1)<= abs(p-newvalue2)
im(i,j) = newvalue1;
else
im(i,j) = newvalue2;
end
sindx=sindx+nbits;
end
end
My main program calls this function. When I run the program, I get the following error message:
??? Undefined function or variable "bin".
Error in ==> alln at 34
b = bin2dec(bin);
I know there are many experts for whom this is not a problem at all. I am new to MATLAB. Please guys, show me the way, which type of modification in the code can overcome this problem?
First of all, are there some lines missing from the file? Perhaps you've stripped some comments from the top? Because the error message says that
b = bin2dec(bin);
is line 34, but it's line 22 in the code you present.
OK, that aside...
The error message says that 'bin' isn't defined, but I see that it's being set on the line...
bin(k)=secret(sindx+k-1);
That suggests to me that THAT line isn't being run.
I see that that bin = ... line is inside of a 'for' loop, so I suspect that the for loop is run zero times, meaning that 'bin' never gets defined. What is nbits? Is it 1, or perhaps less than 1? THAT would prevent the loop from running at all.
Try removing the semicolon from the end of the
nbits=floor(log2(abs(range)));
line and run your code again.
Leaving off the semicolon will force the value of nbits to be printed in the Command Window. I bet you'll find that it's 1 or less. If that's the case, then start looking at HOW nbits is calculated, and I bet you'll find the problem.
At what input arguments to the function alln, are you getting the error?
Lets suppose that nbits is 0, then the following loop will not run:
for k=1:nbits
bin(k)=secret(sindx+k-1);
end
So, bin will be undefined. So, the error happens. This is one of the cases where the error can happen. There are many such possible cases.