Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Pascal - MessageBox
Forum - Pascal - MessageBox

Avatar
mirco95 (Normal User)
Newbie


Messaggi: 13
Iscritto: 27/01/2012

Segnala al moderatore
Postato alle 11:04
Lunedì, 21/05/2012
Ciao vorrei sapere se tramite il seguente codice
Codice sorgente - presumibilmente Pascal

  1. uses crt,windows;
  2. begin
  3. MessageBox (50, 'bhkb jkn' , 'm', 100);
  4. readkey;
  5. end.



Vorrei sapere se è possibile fare un codice, che quando clicco su <<Si>> fa una determinata cosa, e se ammacco no un altra cosa... Io avevo provato a fare:

Codice sorgente - presumibilmente Delphi

  1. uses crt,windows;
  2. begin
  3. MessageBox (50, 'bhkb jkn' , 'm', 100);
  4. if yes then writeln('ciap');
  5. else writeln('saddd');
  6. readkey;
  7. end.




Grazie in anticipo ..

PM Quote
Avatar
Goblin (Member)
Expert


Messaggi: 375
Iscritto: 02/02/2011

Segnala al moderatore
Postato alle 11:50
Lunedì, 21/05/2012
La funzione MessaBox ha un ritorno (se apri la unit windows vedi i valori):
  IDOK = 1;          ID_OK = IDOK;
  IDCANCEL = 2;      ID_CANCEL = IDCANCEL;
  IDABORT = 3;       ID_ABORT = IDABORT;
  IDRETRY = 4;       ID_RETRY = IDRETRY;
  IDIGNORE = 5;      ID_IGNORE = IDIGNORE;
  IDYES = 6;         ID_YES = IDYES;
  IDNO = 7;          ID_NO = IDNO;
  IDCLOSE = 8;       ID_CLOSE = IDCLOSE;
  IDHELP = 9;        ID_HELP = IDHELP;
  IDTRYAGAIN = 10;
  IDCONTINUE = 11;

Dunque il tuo sorgente deve essere modificato
uses crt,windows;
begin
  if MessageBox (50, 'bhkb jkn' , 'm', 100)=IDYES then
    writeln('ciap')
  else
    writeln('saddd');
  readkey;
end.


Ibis redibis non morieris in bello
PM Quote
Avatar
mirco95 (Normal User)
Newbie


Messaggi: 13
Iscritto: 27/01/2012

Segnala al moderatore
Postato alle 13:59
Lunedì, 21/05/2012
Goblin ti ringrazio di cuore.
Finche uso dei WriteLn va tutto ok pero se voglio fare una cosa del genere mi da errore :
Codice sorgente - presumibilmente Delphi

  1. uses crt,windows,dos;
  2. begin
  3.   if MessageBox (50, 'bhkb jkn' , 'm', 100)=IDYES then
  4. Exec('C:\Windows\system32\mspaint.exe','D:\Users\Mirco\Pictures\atlantis_by_flewdesigns-d4zdcgn.jpg');
  5.   else
  6.     writeln('saddd');
  7.   readkey;
  8. end.



Errore
Codice sorgente - presumibilmente Pascal

  1. 5 / 3 untitl~1.pas
  2.  Fatal: Syntax error, ; expected but ELSE found





Dopo questo vorrei fare un altra domanda.. Queste cose

IDOK = 1;          ID_OK = IDOK;
  IDCANCEL = 2;      ID_CANCEL = IDCANCEL;
  IDABORT = 3;       ID_ABORT = IDABORT;
  IDRETRY = 4;       ID_RETRY = IDRETRY;
  IDIGNORE = 5;      ID_IGNORE = IDIGNORE;
  IDYES = 6;         ID_YES = IDYES;
  IDNO = 7;          ID_NO = IDNO;
  IDCLOSE = 8;       ID_CLOSE = IDCLOSE;
  IDHELP = 9;        ID_HELP = IDHELP;
  IDTRYAGAIN = 10;
  IDCONTINUE = 11;

a cosa servono..? :D So che sono domande molto furbe ahah ..
Grazie mille ancora:)



Edit:
Alla prima mio primo problema ho risolto.. Non avevo fatto caso al << ; >> che avevo messo ...
Edit2:
Ok sono riuscito a capire da solo a cosa servono. Grazie comunque

Ultima modifica effettuata da mirco95 il 21/05/2012 alle 15:34
PM Quote
Avatar
mirco95 (Normal User)
Newbie


Messaggi: 13
Iscritto: 27/01/2012

Segnala al moderatore
Postato alle 8:50
Giovedì, 24/05/2012
Un altra informazione.

se io faccio il seguente codice:

Codice sorgente - presumibilmente Delphi

  1. uses crt,windows;
  2. begin
  3. writeln('attendere...');
  4. delay(600);
  5. if MessageBox (50, 'bhkb jkn' , 'm', 100)=IDYES then
  6. Writeln('primo valore');
  7. readln(a);
  8. writeln('secondo valore');
  9. readln(b);
  10. c:=a+b;
  11. writeln('il totale e ',c);
  12. readkey;
  13.  
  14. else
  15.  
  16. Writeln('primo valore');
  17. readln(a);
  18. writeln('secondo valore');
  19. readln(b);
  20. c:=a-b;
  21. writeln('il totale e ',c);
  22. readkey;
  23.  
  24.  
  25.  
  26. end.



Con il seguente codice mi da errore di compilazione dandomi errore il <<;>>.
Pur levando TUTTI gli <<;>> mi da sempre lo stesso errore.
Ho provato pure a creare per ogni richiesta un begin cioe;

Codice sorgente - presumibilmente Pascal

  1. Begin
  2. Writeln('primo valore');
  3. readln(a);
  4. writeln('secondo valore');
  5. readln(b);
  6. c:=a-b;
  7. writeln('il totale e ',c);
  8. readkey;
  9. end;


Mi da sempre errore, grazie ancora

PM Quote
Avatar
Goblin (Member)
Expert


Messaggi: 375
Iscritto: 02/02/2011

Segnala al moderatore
Postato alle 13:47
Giovedì, 24/05/2012
mmm qui mancano proprio le basi .....
allora
tutto il tuo programmino si può concentrare nella metà delle righe

Codice sorgente - presumibilmente Delphi

  1. uses crt,windows;
  2. var a,b,c: Integer;
  3. begin
  4.   writeln('attendere...');
  5.   delay(600);
  6.   Writeln('primo valore');
  7.   readln(a);
  8.   writeln('secondo valore');
  9.   readln(b);
  10.  
  11.   if MessageBox (50, 'bhkb jkn' , 'm', 100)=IDYES then
  12.     c:=a+b
  13.   else
  14.     c:=a-b;
  15.   writeln('il totale e ',c);
  16.   readkey;
  17. end.



1) Cerca di non duplicare il codice, il codice duplicato è frutto di bachi, e la sua manutenzione diventa difficile.
2) in pascal il costrutto if..then..else si forma così:
if <Condizione> then
begin
  <Istruzione1>;
  <Istruzione2>;
end
else
begin
  <Istruzione3>;
  <Istruzione4>;
end;

notare che dopo il primo "end" non c'e' il ";"
oppure

if <Condizione> then
  <Istruzione2>
else
  <Istruzione4>;

G.


Ibis redibis non morieris in bello
PM Quote