creating array of text files with FPS - arrays

Is it possible that FPS program read user input and then creates a file with a name of that input and that read another input and so on and on..?
I have tried to create array of text file but got some problems.
First of all an error occurred that (some) access was denied and secondly, how to create a result file where variable is in the middle of the text file name (I've tried assign (Df,'rezult',i,'.txt'); i - here is changing variable, but in this way program does not work.
P.S. Sorry for my English language skills...
This is what I have tried:
program testing;
var
Df : text;
i:integer;
SomeUserInput:integer;
begin
for i:=1 to 10 do
begin
Assign(Df,'rez.txt'); Rewrite(Df);
Read(SomeUserInput);
WriteLn(Df,'some words + ',SomeUserInput);
Close(Df);
end;
Readln;
end.
(fixed the problem that first comment suggest, but now only last thing is written in my file, I wish to create 10 or more files)

If I understand correctly, you want to number the filename with your loop var.
This should work:
program testing;
Uses
SysUtils;
var
Df : text;
i:integer;
SomeUserInput:integer;
begin
for i:=1 to 10 do
begin
Assign(Df,'rez'+IntToStr(i)+'.txt');
Rewrite(Df);
ReadLn(SomeUserInput);
WriteLn(Df,'some words + ',SomeUserInput);
Close(Df);
end;
Readln;
end.

Related

Saving text file from code

I have made this code:
Program Pzim ;
var
i:integer;
vect:array[1..1001] of integer;
Begin
i:=1;
for i:= 1 to 999 do
vect[i]:=i+1;
for i:= 1 to 999 do
writeln (vect[i]);
readln;
End.
The program print a number sequence.
I want to save in a text file what is printed.
it could be made using the Pascal yet or even using another source? Notepad++ maybe?
Of course you can write to a text file in Pascal.
Program Pascal ;
var
i:integer;
vect:array[1..1001] of integer;
Myfile: text;
begin
i:=1;
for i:= 1 to 999 do
vect[i]:=i+1;
Assign(Myfile, 'Myfile.txt');
Rewrite(MyFile);
for i:= 1 to 999 do
begin
WriteLn (vect[i]);
WriteLn(Myfile, vect[i]);
end;
Close(Myfile);
ReadLn;
end.
It may depend on which version of Pascal you are using, but in many versions this will work.
In the var section, add
f : textfile; // f can be any variable name
After the vect[i]:=i+1 line, insert
assign( f, 'c:\path\filename.txt'; // where path and filename are what you want.
rewrite( f);
then change the write statement to writeln( f, ...) where f is the name used above. And before the end statement, insert closefile( f); (or close(f) in some versions).

Error for Associative Array : Missing IN OUT Parameter

I'm learning about Collections and trying out Associative Arrays in Oracle 11g. I'm using SQL Developer to write and test my code below and I am getting the error which I can't troubleshoot :
Error Report
Missing IN OUT Parameter at index ::1
Code I have written is as follows:
---SIMPLE collections EXAMPLE
DECLARE
TYPE prospect_towns IS TABLE OF VARCHAR2 (25)
INDEX BY PLS_INTEGER;
a_big_towns prospect_towns; -- associative array
i PLS_INTEGER := 1; -- index for the array
v_counter NUMBER;
v_town VARCHAR2(25);
BEGIN
a_big_towns(1):='Birmingham';
a_big_towns(2):='London':
a_big_towns(3):='Manchester';
-- v_counter := 1;
FOR i IN 1..a_big_towns.COUNT
LOOP <<big towns>>
--v_town := a_big_towns(i);
DBMS_OUTPUT.PUT_LINE('Inside Loop, town is '||a_big_towns(i));
i= a_big_towns.next:
END LOOP<<big towns>>
END;
/
Any ideas what's wrong ?
The second of these lines:
a_big_towns(1):='Birmingham';
a_big_towns(2):='London':
a_big_towns(3):='Manchester';
... has a colon at the end, instead of a semicolon. That's causing the following a_big_towns to be interpreted as a bind variable name by the parser. So it should be:
a_big_towns(2):='London';
Once you get past that, this line isn't needed, and would need := instead of = if it was, and also has a colon instead of a semicolon at the end:
i= a_big_towns.next:
... so remove that completely.
I'm not sure the labels are really adding anything here, but if you do have a label it doesn't need to be repeated at the end, and the name can't have a space in it, so make it:
<<big_towns>>
FOR i IN 1..a_big_towns.COUNT LOOP
And this needs a semicolon at the dned:
END LOOP;
This SQL Fiddle compiles.

Reading different data on a single line from file in VHDL

Supposing I've got a file filled with data separated by a tabulation (in this format):
1 2
3 4
5 6
and I'd like to read these data in pairs from a single line, so that result would be as follows:
var1=1;
var2=2;
var1=3;
var2=4;
var1=5;
var2=6;
How am I supposed to work? Right now my code works for a single data on a single line (see following):
read_from_file: process(clk)
variable input_data: natural;
variable ILine: line;
begin
for i in 0 to NSAMPLES-1 loop
readline (input_vectors, ILine);
read(ILine, input_data);
end loop;
end process;
Thank you for helping!
You should be able to call the read function again.
For example:
read_from_file: process(clk)
variable input_data_column1: natural;
variable input_data_column2: natural;
variable ILine: line;
begin
for i in 0 to NSAMPLES-1 loop
readline (input_vectors, ILine);
read(ILine, input_data_column1);
read(ILine, input_data_column2);
-- Now you can do things like conv_std_logic_vector(input_data_column1, bitwidth) etc
end loop;
end process;
Note: I am not positive if any whitespace will be accepted. Spaces have worked for me.

FOR loop Netezza issue

I'm working with stored procedures in netezza.
I want to loop over a range of values.
The upper bound on the loop is passed as a variable into the sproc by the user.
i.e. EXECUTE SPROC(12);
so problem is that Netezza (aginity workbench) won't accept this input variable as the upper bound on the loop.
i.e.
DECLARE
x alias as $1.
begin
for i in 1..x loop
...do stufff...
end loop;
end;
I know that this can be solved using loop and exit style loop but It's eating me up as to why i can't do the above given that the documentation suggests that it's possible to do so.
Anyone know why this doesn't work or how to make it work?
Thanks.
Clancy.
Please find below working example -
CREATE OR REPLACE PROCEDURE generateTime(integer)
LANGUAGE NZPLSQL RETURNS varchar(255) AS
BEGIN_PROC
DECLARE
p_abc integer;
p_bcd integer;
p_var1 ALIAS FOR $1;
BEGIN
p_bcd := ISNULL(p_var1, 10);
raise notice 'p_bcd=%',p_bcd;
FOR p_abc in 0..(p_bcd)
LOOP
raise notice 'Hello World %', p_abc;
END LOOP;
END;
END_PROC;
Hope this will help.

Free Pascal keep numbers in array

i don't know how to do this:
I want to do a program in pascal in which the user have to insert 90 numbers introduced by console and separated by a blank and keep them in a bidimensional array (10x9). Anyone knows how to implement this?
Thanks a lot.
var the_array:array[1..10] of array[1..9] of integer;
var i:integer; var j:integer;
...
i:=1; j:=1;
while i<=10 do begin
while j<=9 do begin
read(the_array[i,j]);
inc(j);
end;
j:=1;
inc(i);
end;
You just use two indices to iterate through an array while filling it from calling read().
You wrote that you use FreePascal, so you can make use of SScanF here.
This program lets you enter some lines of numbers that are separated by spaces.
After it's done, it prints the numbers.
I would not ever hand something like this over to end users though. Why not provide a graphical user interface instead?
program Project1;
uses
SysUtils;
const
Lines = 10;
type
TNumberArray = array[0..Lines-1,0..9] of integer;
procedure GetNumbers(var nums:TNumberArray);
var Line:Integer; s:String;
begin
for Line := Low(nums) to high(nums) do
begin
Write('Enter line ',Line, ': ');
ReadLn(S);
SScanf(s,'%d %d %d %d %d %d %d %d %d %d',
[
#nums[Line,0],
#nums[Line,1],
#nums[Line,2],
#nums[Line,3],
#nums[Line,4],
#nums[Line,5],
#nums[Line,6],
#nums[Line,7],
#nums[Line,8],
#nums[Line,9]
]
);
end;
end;
procedure ShowNumbers(nums:TNumberArray);
var Line,Col:Integer;
begin
for Line := Low(nums) to high(nums) do
begin
for Col:=Low(nums[Line]) to High(nums[Line]) do
Write(nums[Line,Col], ' ');
WriteLn;
end;
end;
var
Numbers: TNumberArray;
begin
WriteLn('Enter 10 numbers');
GetNumbers(Numbers);
ShowNumbers(Numbers);
WriteLn('Done. Press a key to continue.');
ReadLn;
end.
It's cleaner to parse the line using a TStringList, so that you don't have to hard-code the number of columns, but this should work.

Resources