Forum > Audio and Video

What is wrong with this code

(1/2) > >>

Ten_Mile_Hike:
Win 11  Lazarus 3.0

Why do I get only a single "chirp" with the code below???
I have tried adding a multitude of Sleep() and application.processmessages
throughout without any change in the chirp only outcome.


 
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Procedure L();Begin  beep(1000,400);  end; Procedure S();Begin   beep(1000,100);    end; procedure morse(ch:char);begin  Case ch of  'A': Begin S;L;     End;  'B': Begin L;S;S;S; End;  'C': Begin L;S;L;S; End;  'D': Begin L;S;S;   End;  'E': Begin S;       End;  'F': Begin S;S;L;S; End;  'G': Begin L;L;S;   End;  'H': Begin S;S;S;S; End;  'I': Begin S;S;     End;  'J': Begin S;L;L;L; End;  'K': Begin L;S;L;   End;  'L': Begin S;L;S;S; End;  'M': Begin L;L;     End;  'N': Begin L;S;     End;  'O': Begin L;L;L;   End;  'P': Begin S;L;L;S; End;  'Q': Begin L;L;S;L; End;  'R': Begin S;L;S;   End;  'S': Begin S;S;S;   End;  'T': Begin L;       End;  'U': Begin S;S;L;   End;  'V': Begin S;S;S;L; End;  'W': Begin S;L;L;   End;  'X': Begin L;S;S;L; End;  'Y': Begin L;S;L;L; End;  'Z': Begin L;L;S;S; End;  end;end; procedure TF1.Button1Click(Sender: TObject);var x:integer;Begin  For x:= 1 to Length(Edit1.Text) Do Morse(Edit1.text[x]);end;end.                                              

RayoGlauco:
This code works ok for me:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program Project1; {$mode objfpc}{$H+} uses  {$IFDEF UNIX}  cthreads,  {$ENDIF}  Classes  ,sysutils  ,windows  { you can add units after this }; Procedure L();Begin  windows.beep(1000,400);  sysutils.sleep(100);  end; Procedure S();Begin   windows.beep(1000,100);   sysutils.sleep(100);end; procedure morse(ch:char);begin  Case ch of  'A': Begin S;L;     End;  'B': Begin L;S;S;S; End;  'C': Begin L;S;L;S; End;  'D': Begin L;S;S;   End;  'E': Begin S;       End;  'F': Begin S;S;L;S; End;  'G': Begin L;L;S;   End;  'H': Begin S;S;S;S; End;  'I': Begin S;S;     End;  'J': Begin S;L;L;L; End;  'K': Begin L;S;L;   End;  'L': Begin S;L;S;S; End;  'M': Begin L;L;     End;  'N': Begin L;S;     End;  'O': Begin L;L;L;   End;  'P': Begin S;L;L;S; End;  'Q': Begin L;L;S;L; End;  'R': Begin S;L;S;   End;  'S': Begin S;S;S;   End;  'T': Begin L;       End;  'U': Begin S;S;L;   End;  'V': Begin S;S;S;L; End;  'W': Begin S;L;L;   End;  'X': Begin L;S;S;L; End;  'Y': Begin L;S;L;L; End;  'Z': Begin L;L;S;S; End;  end;end; var x:integer;Begin  For x:= 1 to Length('HOLA KE ASE GUAPO') Do Morse('HOLA KE ASE GUAPO'[x]);end. 

Thaddy:
You only have to use sysutils.beep. This also works on many unixes, but e.g. KDE plays dirty. Works for Ubuntu and windows and Debian.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program morsetest;{$mode objfpc}{$H-}uses windows; Procedure L();Begin  beep(1000,400);  end; Procedure S();Begin   beep(1000,100);   end; procedure morse(const ch:char);begin  Case upcase(ch)of  'A': Begin S;L;     End;  'B': Begin L;S;S;S; End;  'C': Begin L;S;L;S; End;  'D': Begin L;S;S;   End;  'E': Begin S;       End;  'F': Begin S;S;L;S; End;  'G': Begin L;L;S;   End;  'H': Begin S;S;S;S; End;  'I': Begin S;S;     End;  'J': Begin S;L;L;L; End;  'K': Begin L;S;L;   End;  'L': Begin S;L;S;S; End;  'M': Begin L;L;     End;  'N': Begin L;S;     End;  'O': Begin L;L;L;   End;  'P': Begin S;L;L;S; End;  'Q': Begin L;L;S;L; End;  'R': Begin S;L;S;   End;  'S': Begin S;S;S;   End;  'T': Begin L;       End;  'U': Begin S;S;L;   End;  'V': Begin S;S;S;L; End;  'W': Begin S;L;L;   End;  'X': Begin L;S;S;L; End;  'Y': Begin L;S;L;L; End;  'Z': Begin L;L;S;S; End;  else     sleep(200)  end;end; var   x:integer;  ss:string ='I am in distress';Begin  For x := 1 to length(ss) do Morse(ss[x]);  readln;end.

Thaddy:
@RayoGlauco
Don't edit your post after I gave an answer. Post your solution in a new post.

RayoGlauco:
@Thaddy
I think I didn't edit my previous post. When a post is edited, this fact is displayed at the end of the message.
In any case, I think both your proposal and mine work as intended.

edit: edited just to check if edit time is shown

Navigation

[0] Message Index

[#] Next page

Go to full version