Actuateclub.com

 

  About Actuate   |   Forums   |   Message Board  |   FAQ   |   Jobs    |   Actuate 100   |   Guest Book  |   Feedback  |   Sitemap   |   Home

Techieindex

 
Reading from the flat files
In this report we will be opening and reading data from a Flat File.
Description
In this report the data reading from a Flat File. As in all languages we have to open a file before we can read from it. Actuate uses file numbers to identify a file. To get the next unused system file number, we use FreeFile function. The value returned by the FreeFile function is Integer. Its value is not changed until you actually open the file. So it is always returns the current file number
In the Content Slot place Report Section from Structure Palette.

In DataStream slot place Query component and double click on it.

In Component change the super class of class as AcDataSource and create two class variables. 
1) Write the name as filehandle set the storage as static and also  set the visibility as Parameter
2) Write the name as filename set the storage as static and also set the visibility as Public
In DataRow slot place DataRow from Data Palette and double click on it. 
In component variable create class variable as var1, var2, var3, var4. 
Drag a frame to the Content Slot. 
Place a 4-text control in frame and set ValueExp to var1, var2, var3, var4.
Place Pagelist Control into Pagelist Slot and select AcSimplePageList. Pagelist defines the page layout of the report. There are 3 types of pagelayouts. AcLeftRightPageList, AcSimplePageList, AcTitlBodyPageList. AcLeftRightPageList is used when you need different layouts for left and right pages. AcTitlBodyPageList is used when you need different layouts for Title and Body pages. 
In pagestyle put page control. 
Put flow into content slot.
In View menu selects parameters and enter the fully qualified filename .
Double click the Query component and select the start () function from method tab and click Override button.
Type the remaining lines to the function after Start = Super::Start()                    
 filehandle=FreeFile() 
 Open filename for Input as filehandle 
Select the Fetch () function from method tab and click Override button.
Type the remaining lines to the function after Set Fetch = Super::Fetch( )

Dim drow as DataRow

                     Set drow=new DataRow

                     If EOF (filehandle) Then

                     Exit function

                     End If

                     Input #filehandle,drow.var1,drow.var2, 
      drow.var3,drow.var4,drow.var5

                     Set Fetch=drow

                     AddRow(Fetch) 

           Fetch ():  This function is used to 
fetches a row from the data source

 


Select the Finish () function from the Method tab and override the function
Type the remaining lines to the function after Super::Finish( ) 

  Close #filehandle  
Finish ():This function contains the coding for completing an object.
The value returned by the FreeFile function is Integer. Its value is not changed until you actually open  the file. So it is always returns the current filenumber.

Example:

intAFileNumber = FreeFile
This statement assigns the next file number to intAFileNumber.
The next step is to open the file. This is done by

Example:
         intAFileNumber = FreeFile

This statement assigns the next file number to intAFileNumber.  
The next step is to open the file. This is done by
Open statement  

Syntax:
 

Open <file name> [For <mode>] [Access <permissions>] [<lock>] As [#]<file number> [Len = <record or buffer size>]
This syntax using for reading and writing--input and output (I/O)--to a file.


File name (
<file name>)  
In this we declare the name of target file.The File name should  be declare  with in the double quotes.


Example:

Open” c:\myreport\hrm.txt ” As#1  

Mode (For <mode>)  
This specifies the file mode. This is useful  when it is opened for Append, Binary, Output, or Random modes. This mainly using for how to read from the file and write to a file.  
<mode> may be Append, Binary, Input, Output, or Random.

Example: 
          
         Open " c:\myreport\hrm.txt " For Input As #1

Random:  

This specifies random-access file mode. This allow Actuate Basic to make three  attempts to open the file .

·          Read and write.

·          Write-only.

·           Read-only.

Binary:

This specifies binary file mode .You can read and write information to any byte position in the file.

Input:

This specifies sequential input mode .

·            In this <file name> must exist.

Output:

  This specifies sequential output mode.

·           If  <file name> does not exist, it is created, then opened.

Append:

This specifies sequential output mode, and sets the file pointer to the end of the file.

·          If <file name> does not exist it is created, then opened.

Permission (Access <permissions>)

This specifies what operations this process is permitted to perform on <file name>.      <permissions> keyword are: Read, Write, or Read Write

Example: 
Open " c:\myreport\hrm.txt " For Input Access Read As #1

Access <permissions> Rules are:

·    Error will occur when another process already opened the file and made  <permissions> unavailable to others

·   To enable locking operations .you must first run SHARE.EXE before you run your Actuate Basic program

Read:
This Keyword using to open the file for a reading process only.  

W
rite:
This Keyword using to open the file for a writing process only.  

R
ead Write:
This Keyword using to open the file for both reading and writing processes.

Lock (<lock>)
Keyword or set of keywords that specifies what operations other processes are permitted to perform on <file name>. In a multiuser environment , <lock> restricts access by other processes or users.
The <lock> keyword are: Shared, Lock Read, Lock Write, or Lock Read Write

Example:

Open " c:\myreport\hrm.txt " For Binary As #1 Shared

Shared:
This Keyword tells that any process   has permission to read from or write to <file name> while this Open is in effect.  
 Lock Read:
This Keyword tells that no other process has permission to read <file name> while this Open is in effect.  
 Lock Write:
This Keyword tells that no other process has permission to write to @
<file name> while this Open is in effect.  
 Lock Read Write:
 This Keyword indicating that no other process has permission to read from  or write to <file name> while this Open is in effect.  

File number (As [#]<file number>)

This assigns a number to the open file. I/O statements can then use <file number> to refer to the file. File number specifies the number associated with the file that remains open.
<file number>: Must be between 1 and 255

Example:  

Open " c:\myreport\hrm.txt " For Input As #1

Len = <buffer or record size>

This specifies how much information to take from the file into the buffer. <record or buffer size>is the integer expression that indicates either the record length or buffer size depending on <mode>.This must be positive and less than or equal to 32,767 bytes.

Examples:

Open " c:\myreport\hrm.txt " For Input As #1 Len = 423

 

 

 

 

 

 

Copyright © 2008 Techieindex