Easytrieve – Variable declaration

This post will help you to understand the dataypes and how to declare a variable in Easytrieve (which is the first step in learning any new language. believe me, Easytrieve is the simplest language that you can learn in a day).

First, we will see the different datatypes available.

Datatypes

Alphanumeric A
Numeric N Maximum length 18
Binary (Comp) B Maximum length 8. i e upto 18 digits
Packed (COMP-3) Define as P 0 Maximum length 9. i e upto 18 digits

A – Alphanumeric – can be used for variables containing Alphabets, numbers, special characters or any data. This is similar to PIC X(nn) in Cobol.

N – Numeric – can be used to have unpacked signed (or unsigned) numbers. This is similar to PIC S9(nn) in Cobol.

B- Binary – can be used to store signed (or unsigned) numbers in binary format. Length of this must be either 2 or 4 or 8 bytes. (similar to PIC S9(nn) COMP in Cobol)

P – Packed – for Packed numeric variables (similar to PIC S9(nn) COMP-3 in Cobol)

Declaring a working storage variable

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 WS-VAR1 W 8 A 
 WS-VAR2 W 8 A VALUE 'KARTHIK ' 
 WS-VAR2 W 9 N VALUE ZEROES 
 WS-VAR3 W 7 N 2 
 WS-VAR4 W 9 P 0 
 WS-VAR5 W 9 P 2

Variable declaration  statement has 4 mandatory parts

1. Variable name

2. Start position of the variable (should be given as W for Working storage variables; in File layouts, use the starting position – no need to add 4 for VB files, start with 1)

3. Number of bytes the variable occupies (note that this is not number of digits but number of bytes)

4. The datatype – A (Alpha), N (Numeric), B (Binary) or P (Packed)

For binary and packed variables if you want to have an implied decimal point (say for two digits), that number of digits should immediately follow the character P (packed), B for Binary.

For eg, the below variable WS-VAR4 is a binary, occupies 4 bytes (total) and has 3 digits (not bytes) after the implied decimal point. and the Packed variable WS-VAR5 occupies 9 bytes (total) and has 2 digits (not bytes) after the implied decimal point.

 WS-VAR4 W 4 B 3 
 WS-VAR5 W 9 P 2

Important note: For Packed variables, even if you don’t want to use any decimal, please declare as P 0 (meaning 0 digits after decimal). If you don’t do that, you may possibly get some error.

 WS-VAR6 W 9 P 0 

Declaring Group variables

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 WS-GROUP W 15 A 
 WS-GR1 WS-GROUP 5 A 
 WS-GR2 WS-GROUP +5 10 A 

Declaring a Group variable is easy – just use the High lever variable (+ offset) as the starting position for the variables that come under the group. Hope the above example helps you to understand.

Using indexed variables

In the below example, you can see an array WS-ALP-ARR with 26 items in it. In addition, it also redefines WS-ALPHA which is of 26 bytes length. We are also using an index ALPHA-NDX for the array WS-ALP-ARR. (We don’t have to declare the index variable)

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 LIST ON 
 FILE INFILE 
 WS-ALPHA W 26 A VALUE 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 
 WS-ALP-ARR WS-ALPHA 1 A OCCURS 26 INDEX ALPHA-NDX 
* 
 JOB INPUT NULL 
* PRINT 16TH ALPHABET 
 ALPHA-NDX = 15 
 DISPLAY '16TH ALPHABET IS ' WS-ALP-ARR 
 STOP. 

Using arrays/tables

In the above example, we saw an array with Index. Below is a simple array with no index. Hope this example is self explanatory.

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 LIST ON 
 FILE INFILE 
 WS-DAYS-OF-WEEK W 10 A OCCURS 7 
* 
 JOB INPUT NULL 
 MOVE 'SUNDAY' TO WS-DAYS-OF-WEEK(1) 
 MOVE 'MONDAY' TO WS-DAYS-OF-WEEK(2) 
 MOVE 'TUESDAY' TO WS-DAYS-OF-WEEK(3) 
 MOVE 'WEDNESDAY' TO WS-DAYS-OF-WEEK(4) 
 MOVE 'THURSDAY' TO WS-DAYS-OF-WEEK(5) 
 MOVE 'FRIDAY' TO WS-DAYS-OF-WEEK(6) 
 MOVE 'SATURDAY' TO WS-DAYS-OF-WEEK(7) 
 DISPLAY '4 TH DAY IS ' WS-DAYS-OF-WEEK(4) 
 STOP 

Alos, read about REDEFINES in Easytrieve.

Input fields in Java Swing

Including a JButton:

 

// Name of this file should be simplejbutton.java
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class simplejbutton extends JApplet
{
JButton B = new JButton(“Click”);

public void init()
{
Container cp = getContentPane();
cp.setLayout(null);

cp.add(B);
B.setBounds(10,10,100,20);
B.setActionCommand(“B”);
B.addActionListener(mylistener);
}
// ActionListener for Button
private ActionListener mylistener = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand() == “B”)
B.setText(“Clicked”);
}
};// End of ActionListener
} // End of the Class

Including a JLabel:

 

// This file should have name simplejlabel.java
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class simplejlabel extends JApplet
{
JLabel L = new JLabel(“Label”);
JButton B = new JButton(“Click”);

public void init()
{
Container cp = getContentPane();
cp.setLayout(null);

cp.add(L);
L.setBounds(10,10,100,20);

cp.add(B);
B.setBounds(120,10,100,20);
B.setActionCommand(“B”);
B.addActionListener(mylistener);
}
// ActionListener for Button
private ActionListener mylistener = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand() == “B”)
L.setText(“Clicked”);
}
};// End of ActionListener
} // End of the Class

Including a JTextField

// This file should have name simplejtext.java
// Type something in Text Box and press Enter
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class simplejtext extends JApplet
{
JTextField T = new JTextField(“”);
JLabel L = new JLabel(“Label”);

public void init()
{
Container cp = getContentPane();
cp.setLayout(null);

cp.add(T);
T.setBounds(10,10,100,20);
T.setActionCommand(“T”);
T.addActionListener(mylistener);

cp.add(L);
L.setBounds(120,10,100,20);

}
// ActionListener for Button
private ActionListener mylistener = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand()==”T”)
L.setText(T.getText());
}
};// End of ActionListener
} // End of the Class

Including a JCheckBox:

// This file should have name simplejcheckbox.java
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class simplejcheckbox extends JApplet {

JCheckBox C = new JCheckBox(“Click”);
JLabel L = new JLabel(“Label”);

public void init()
{
Container cp = getContentPane();
cp.setLayout(null);

cp.add(C);
C.setBounds(10,10,100,20);
C.setActionCommand(“C”);
C.addActionListener(mylistener);

cp.add(L);
L.setBounds(120,10,100,20);

}
// ActionListener for Button
private ActionListener mylistener = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand()==”C”)
{
if (C.isSelected() == true)
L.setText(“True”);
else
L.setText(“False”);
}
}
};// End of ActionListener
} // End of the Class

The above code is highlighted using Google Code Prettify.

Files in a Folder (VBA)

This Excel sheet can be used to get a list of files in a folder into a column of the Excel sheet.

Preview:

You just need to give the path of the folder in the text box and press enter. This works as simple as a browser.

Download:

Code for getting the file and folder names into excel cells is below:


Dim fs, f, f1, ffiles, ffolds
Set fs = CreateObject(“Scripting.FileSystemObject“)

If fs.folderexists(TextBox1.Text) Then
Else

a = MsgBox(“Folder Does not Exist“, , “Give Valid Path“)
GoTo ending

End If

Set f = fs.GetFolder(TextBox1.Text)
Set ffiles = f.Files
Set ffolds = f.subfolders

‘ Adding files to the column
For Each f1 In ffiles

Sheet1.Cells(i, 4).Value = f1.Name
Sheet1.Cells(i, 5).Value = “Go

With Sheet1

.Hyperlinks.Add .Range(Sheet1.Cells(i, 5).Address()), TextBox1.Text + “” + f1.Name

End With
i = i + 1

Next
j = 6

‘ Adding folders to the column
For Each f1 In ffolds

Sheet1.Cells(j, 7).Value = f1.Name
Sheet1.Cells(j, 8).Value = “Go
With Sheet1

.Hyperlinks.Add .Range(Sheet1.Cells(j, 8).Address()), TextBox1.Text + “” + f1.Name
End With
j = j + 1

Next


Creating a File System object:

Dim fs

Set fs = CreateObject(“Scripting.FileSystemObject“)


Operations with the file system object:

Opening an existing file:

Dim a, ForAppending=8

a = fs.OpenTextFile(“c:testfile.txt“, ForAppending, false);

This will open the file c:testfile.txt (Which is already existing) into the object “a” for Appending.

The second parameter to OpenTextFile method can be 1(ForReading), 2(ForWriting) or 8(ForAppending)