: my knowledge of pascal doesn't amount to much. i'm doing a coursework project for school. its kinda pressing on time, which is why i've turned to the net.
:
: question1) how do i make a file, write into it, delete/edit stuff from it ? this meaning i want to make a text/dat file into a specified path (eg, C:\windows\desktop\test.txt)
:
: i know its got something to do with 'reset', and 'rewrite' procedures. but i have no clue as to how to actually use them. i need to know how to make, write into, overwrite, delete, edit the file and its contents.
Here is a small sample code to create and read a textfile:
var
f: text;
begin
Assign(f, 'Somefilename.txt'); // Link the file variable to a filename
Rewrite(f); // Create or overwrite the file
writeln(f, 'A line'); // write a whole line
write(f, 'A word '); // write part of a line
writeln(f, 'continuing the line'); // finish the line
Close(f); // close the file again
end;
{ reading: this code dumps the whole file on a console-screen }
var
f: text;
s: string;
begin
Assign(f, 'Somefilename.txt'); // Link the file variable to a filename
Reset(f); // Create or overwrite the file
while not eof(f) do
begin
readln(f, s);
write(s);
end;
Close(f); // close the file again
end;
You cannot directly edit or delete (parts of) lines in a text file. To delete a line you need to copy the file except the lines you want to delete. The same goes for editing lines.
:
: question2) how do i print?
: i know its got to do with the uses commands. i use wincrt. teacher tells me i need to figure out some other 'win*' thingy that will allow me to communicate with the printer.
:
: so what is the syntax to print stuff?
:
: in both cases, a short sample program would be greatly appreciated.
:
In Borland's Pascal (Turbo or Delphi) you can use the AssignPrn() to open a "text-file" to the printer. Then you can write text to the paper. For a code see above.
:
: some side questions, not of as great an importance;
: question3)
: how do i make sounds? is it..
:
: program makeSound;
: uses wincrt;
:
: begin
: sound(##) {where ## = integer}
: end.
:
: ?
: and if i'm right, then wat is the number for middle C? does increasing the number by 1 increase the note by semitone(C to C#) or whole tone?(C to D, skipping C#)
:
The Sound() function takes the frequency of the tone. I know that the middle A is 44 kHz. You can find the others on the internet or a good music book. It is also possible to calcuate the other tones, but I don't know the formula of that calculation.
:
: question4)
: how do i stop for a specified period of time? halt(##) {where ## = number of seconds) ? or stop(##) ? what is the syntax for that?
: thanks.
: -kimk
:
Halt() completely terminates the program and gives the errorcode ## to the OS. You need to use the Delay() function for that. See the help files for more information on that function and other functions you mentioned.