Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

hi, i'm new here, with several questions about pascal (windows pascal)

kimkkimk Posts: 1Member
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:windowsdesktop est.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.

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.


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#)


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

Comments

  • zibadianzibadian Posts: 6,349Member
    : 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:windowsdesktop est.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:
    [code]
    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;
    [/code]
    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.
  • netgertnetgert Posts: 331Member
    : 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#)
    :
    :
    : 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
    :
    a3)
    yes u use sound() but u need to figure out the frequcy of that tone. i can tell u the different between full tones is 440 (Hz) but i dont know where it starts from (that's up to you to figure out, consult your music instructor)
    a4)
    u pause with delay(milliseconds). make sound, pause, and then make another sound or stop sound with nosound; (i might be wrong too, i havent done sounds very much)
    [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]

  • Johnny13Johnny13 Posts: 128Member
    : u pause with delay(milliseconds). make sound, pause, and then make another sound or stop sound with nosound; (i might be wrong too, i havent done sounds very much)
    :
    :
    but it seems if you use any functions in the CRT unit
    (sound,nosound,delay,readkey..) you will get a stupid "Runtime error 200" :p
    another way is to rewrite these functions in asm..
  • zibadianzibadian Posts: 6,349Member
    : : u pause with delay(milliseconds). make sound, pause, and then make another sound or stop sound with nosound; (i might be wrong too, i havent done sounds very much)
    : :
    : :
    : but it seems if you use any functions in the CRT unit
    : (sound,nosound,delay,readkey..) you will get a stupid "Runtime error 200" :p
    : another way is to rewrite these functions in asm..
    :
    Or download them from the internet, for those of us who cannot code in asm.
Sign In or Register to comment.