How to save data to file.txt not VisualG?

Personnel need to make a registration system in Portugol for a college job. However, I want the data to be saved for a possible query.

There is the possibility of saving data to a file .txt not VisualG?

(i searched found the command "file" but did not understand how to use)

Thank you!

Author: YODA, 2017-10-22

1 answers

There is the possibility to save data to an em file .txt not VisualG! VisuAlg allows data to be stored in a text file, obtaining the data from it when executing the leia commands.

This feature works as follows:

(second this source )

  1. if the file with the specified name does not exist, VisuAlg will make a reading data by typing, storing the data read in this file, in the order in which are provided.
  2. if the file exists, VisuAlg will get the data from this file until it arrives to its end. From then on, it will do the data readings by typing.
  3. only one file command can be employed in each pseudocode, and it it should be in the statements section (depending on the" success " of this feature, in future versions it can be improved...).
  4. if a path is not provided, VisuAlg will search for this file in the folder of current job (usually, it is the folder where the program VISUALG.EXE is). This command does not provide for a default extension; therefore, the specification of the file name must be complete, including with its extension (for example .txt, .dat, etc.).

The syntax of the command is:

arquivo < nome-de-arquivo >

<nome-de-arquivo> it is a constant character (in double quotes). See the following example:

  algoritmo "lendo do arquivo"
  arquivo "teste.txt"
  var x,y: inteiro
  inicio
  para x de 1 ate 5 faca
  leia (y)
  fimpara
  fimalgoritmo

EXTRA

Your variables can also be stored in an array of type character and test it in the query and implement the code with a menu.(With registration and consultation)

   algoritmo "lendo do arquivo"
   arquivo "teste.txt"
   var x,y,i,j: inteiro
   char opcao
    vetor mat[5][5]
   inicio
   repita
   escreval("MENU")
   escreval("A- GRAVAR ARQUIVOS")
   escreval("B- PROCURAR ARQUIVOS")
   escreval("s-Sair")
   escolha(opcao)
   caso 'A'
   escreval("Leia matriz:")
   para i de 1 ate 5 faca
   para j de 1 ate 5 faca
   leia(m[i][j])
   fimpara
   fimpara


   caso 'B'
   // compare com a variável que quiser 
   leia(x)
   para i de 1 ate 5 faca
   para j de 1 ate 5 faca
   se(x=m[i][j]) entao
   ...
   fimse
   fimpara
   fimpara
   ate(opcao='s')
   fimescolha
   fimalgoritmo

You can use the file command, but it may not be the best option.

Because every command leia() that VisuAlg finds, it will be reading this file and playing in the variable that is in leia(). Translate... As long as it does not reach the end of the file, all leia() will be directed to the file... it will not be possible to read any user data via keyboard until the file is finish.

If you are implementing with file, always remember the command limpatela may be useful.

 3
Author: YODA, 2017-10-23 01:02:23