W moim programie pewien warunekk się powtwrza 365 razy. a ccilbym to skrócić
ajha i jak wywołac wrunek jeśli dny warunek będzie spelniony?--Delphi 2 , 6 i 5
Ciekawe pomysły i poszukiwanie rozwiązań.
if warunek1 then
if warunek2 then--||===
takaa kombinacja nie dziła
bo if f=28 then
...
to jest w porądku
alke jeśli
if f=29 then
if m=3 then
f:=f+3;
i to już pada, jest niefunkcjonalne
--Delphi 2 , 6 i 5
Ciekawe pomysły i poszukiwanie rozwiązań.
if (warunek1)and(warunek2) then bleble--||===
Warto pamietac o blokach :P
if Warunek1 then
begin
if Warunek2 then
begin
//tu cos gdy oba warunki
end;
end;
czesto cos zle dziala jesli sie tego dobrze nie ustawi ;)--W poszukiwaniu rozwiązania problemu, najbardziej pomocna jest znajomość odpowiedzi.
Napisz osadnik ogolniej o co Ci chodzi, to moze da sie zrobic prosciej. Bo napisac bez bledu if-a zagniezdzonego na 365 poziomow jest raczej nielatwo. A nawet jesli nie bedzie bledu, to nie wiem czy kompilator to lyknie.--Pawel {Delphi 6 Personal}
Po pierwsze: naciśnij F1
pq napisał:
Napisz osadnik ogolniej o co Ci chodzi, to moze da sie zrobic prosciej. Bo napisac bez bledu if-a zagniezdzonego na 365 poziomow jest raczej nielatwo. A nawet jesli nie bedzie bledu, to nie wiem czy kompilator to lyknie.
Łyknie wszystko co mu każesz, tylko czasem trzeba go oszukać :)
Wątpię, byś miał 365 różnych porównać. Na pewno da się to przerobić wykorzystując rekurencję lub iterację i/lub tablice. 365 porównań to morderstwo procesora (zwłaszcza, jeżeli to ma być wykonywane wiele razy). pq ma rację. Napisz dokładnie o co ci chodzi (jak widzę 365 to zapewne potrzebujesz coś z datami :) )--Jest jeszcze jeden błąd ... :)
Apel: Piszcie w tematach o jaki język programowania chodzi np. : [Delphi], [C++], itp.
Przytoczę fragment kodu:
unit glowne;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, inifiles, OleCtrls, SHDocVw;
type
TForm1 = class(TForm)
Button1: TButton;
GroupBox1: TGroupBox;
web: TWebBrowser;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses configs;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
konfig.showmodal;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
INI : TINIFile;
x,y : integer;
h :byte;
xy:string;
f :integer;
r, d, g, m :word;
ms, s, fd :word;
begin
DecodeTime(Time, G, Ms, S, fd);
f:=0;
DecodeDate(date, r, m, d);
x:=19;
y:=13;
{ try
INI := TINIFile.Create((( ExtractFilePath( Application.ExeName ) + 'conf.ini')));
xy := INI.ReadString('Miasto','Warszawa','1913');
INI.Free; }
if m=1 then begin
f:=0+d;
end;
if m=2 then begin
f:=31+d;
end;
if m=3 then begin
f:=59+d;
end;
if m=4 then begin
f:=89+d;
end;
if m=5 then begin
f:=120+d;
end;
if m=6 then begin
f:=151+d;
end;
if m=7 then begin
f:=181+d;
end;
if m=8 then begin
f:=212+d;
end;
if m=9 then begin
f:=242+d;
end;
if m=10 then begin
f:=273+d;
end;
if m=11 then begin
f:=304+d;
end;
if m=12 then begin
f:=334+d;
end;
if g=0 then
h:=00;
if g=1 then
h:=00;
if g=2 then
h:=00;
if g=3 then
h:=00;
if g=4 then
h:=00;
if g=5 then
h:=00;
if g=6 then
h:=06;
if g=7 then
h:=06;
if g=8 then
h:=06;
if g=9 then
h:=06;
if g=10 then
h:=06;
if g=11 then
h:=06;
if g=12 then
h:=12;
if g=13 then
h:=12;
if g=14 then
h:=12;
if g=15 then
h:=12;
if g=16 then
h:=12;
if g=17 then
h:=12;
if g=18 then
h:=18;
if g=19 then
h:=18;
if g=20 then
h:=18;
if g=21 then
h:=18;
if g=22 then
h:=18;
if g=23 then
h:=18;
web.Navigate('E:\Moje dokumenty\Programy\Ja je pisałem\Prognoza pogody\mgram' + (xy) + '.' + inttostr(f) + inttostr(h) + '.gif');
- finally
- ini.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
//WinExec('rundll32.exe rnaui.dll,RnaDial TPSA',sw_show);
end;
end.
A teraz coś rozumiecie???
aha, Potrebne mi są dne do tegu unita:
- dzien roku
- godzina
- a ten xy juz sobie sam robię.
--Delphi 2 , 6 i 5
Ciekawe pomysły i poszukiwanie rozwiązań.
Osadnik napisał:
>Przytoczę fragment kodu:
>>
> if m=1 then begin
> f:=0+d;
> end;
...
...
> if m=12 then begin
> f:=334+d;
> end;
A nie lepiej zrobić tak:
const
Dni: array[1..12] of Byte = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var
i: Byte;
begin
f:=d;
for i:=1 to m - 1 do Inc(f, Dni[i]);
end;
> if g=0 then
> h:=00;
...
> if g=6 then
> h:=06;
...
> if g=12 then
> h:=12;
...
> if g = 18 then
> h:=18;
A tu:
case g of
0..5: h:=0;
6..11: h:=6;
11..18: h:=12;
19..24: h:=18;
end;
>- dzien roku
>- godzina
Time i Date, reszta w helpie.--Vogel [Delphi 6 PE]
I TY możesz nauczyć się grać w bierki!