Howdy, Stranger!

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

Categories

Program Crashes

HabitatHabitat Member Posts: 1
Hi I have to write a small program that creates Acronyms. The program should look for capitals instead of spaces. It should also delete the 1st portion of the phrase to show that balance of the phrase.
I have that pat, no problem there.
My problem is the output. It discards that Capital Letter and the program loops when there are no more Capitals.
Here is my code.
procedure TfrmAcronyms.btnBuildClick(Sender: TObject);

var Word, Sentence, Acronym : String;

begin
Sentence := edtInput.Text;
{Locating the 1st Capital Letter}
Word := Copy(Sentence,1,1);
While (Word < 'A') or (Word > 'Z') do
begin
{Deleting a single character}
Delete (Sentence,1,1);
{Getting the second capital letter}
Word := Copy(Sentence,1,1);
end;
If (Word >= 'A') or (Word <='Z') then
begin
Acronym := Acronym + Word;
Delete (Sentence,1,1);
edtInput.Text := Sentence;
{Display the Acronym}
lblOutput.Caption := Acronym;
Word := Copy(Sentence,1,1);

end
else


end.

Comments

  • zibadianzibadian Member Posts: 6,349
    : Hi I have to write a small program that creates Acronyms. The program should look for capitals instead of spaces. It should also delete the 1st portion of the phrase to show that balance of the phrase.
    : I have that pat, no problem there.
    : My problem is the output. It discards that Capital Letter and the program loops when there are no more Capitals.
    : Here is my code.
    : procedure TfrmAcronyms.btnBuildClick(Sender: TObject);
    :
    : var Word, Sentence, Acronym : String;
    :
    : begin
    : Sentence := edtInput.Text;
    : {Locating the 1st Capital Letter}
    : Word := Copy(Sentence,1,1);
    : While (Word < 'A') or (Word > 'Z') do
    : begin
    : {Deleting a single character}
    : Delete (Sentence,1,1);
    : {Getting the second capital letter}
    : Word := Copy(Sentence,1,1);
    : end;
    : If (Word >= 'A') or (Word <='Z') then
    : begin
    : Acronym := Acronym + Word;
    : Delete (Sentence,1,1);
    : edtInput.Text := Sentence;
    : {Display the Acronym}
    : lblOutput.Caption := Acronym;
    : Word := Copy(Sentence,1,1);
    :
    : end
    : else
    :
    :
    : end.
    :
    I think you also need to check if Word is an empty string.
    On a side note: else is not required after an if-then statement.
  • Chris BrownChris Brown USAMember Posts: 4,624 ✭✭

    _______ // http://forcoder.org // free video tutorials and ebooks about // Visual Basic .NET, Assembly, Visual Basic, PHP, C, Ruby, PL/SQL, Java, Perl, Swift, Scratch, C++, Objective-C, MATLAB, C#, Python, Go, Delphi, R, JavaScript COBOL, Bash, ABAP, ML, Transact-SQL, Alice, Hack, Awk, LabVIEW, Apex, Prolog, FoxPro, Julia, Dart, Ada, Scheme, Crystal, D, F#, Scala, Rust, Logo, Clojure, SAS, Erlang, Lua, Kotlin, Lisp, VBScript, Fortran // ___

Sign In or Register to comment.