pro18
selezione con IF..THEN...ELSE pascal vba visualbasic excel
PASCAL
program pro18;
(* selezione semplice con unica istruzione *)
uses crt;
var a,b,c:integer;
begin
clrscr;
a:=10;
b:=20;
if a>b then writeln(a*b);
if a<b then writeln(a+b);
(*selezione con varie istruzioni *)
if a<b then
begin
writeln(a+b);
writeln(a*b);
writeln(a-b);
end;
(*soluzione alternativa semplice *)
if a<b then
writeln(a*b)
else
writeln(a+b);
(* soluzione alternativa multipla*)
if a<b then
begin
writeln(a+b);
writeln(a*b);
end
else
begin
writeln(a*10);
writeln(b*100);
end;
readln;
end.
RUN e visualizza
30
30
200
-10
200
30
200
ritorna
VBA per Excel creare pulsante e inserire istruzioni
Private Sub CommandButton1_Click()
Dim a, b, c, d As Integer
a = 100
b = 20
c = 30
d = 40
If a > b Then Cells(1, 1) = a * b
If a < b Then Cells(2, 1) = a + b
If a < b Then
Cells(3, 1) = a + b
Cells(4, 1) = a * b
Cells(5, 1) = a - b
End If
If a < b Then
Cells(6, 1) = a + b
Cells(7, 1) = a * b
Else
Cells(8, 1) = a * 10
Cells(9, 1) = b * 100
End If
End Sub
2000
30
30
200
-10
30
200
1000
2000
ritorna
VISUAL BASIC creare PULSANTE per istruzioni e 9 caselle LABEL
Private Sub CommandButton1_Click()
Dim a, b, c, d As Integer
a = 10
b = 20
c = 30
d = 40
If a > b Then Label1.Caption = a * b
If a < b Then Label2.Caption = a + b
If a < b Then
Label3.Caption = a + b
Label4.Caption = a * b
Label5.Caption = a - b
End If
If a < b Then
Label6.Caption = a + b
Label7.Caption = a * b
Else
Label8.Caption = a * 10
Label9.Caption = b * 100
End If
End Sub
label1 |
label2 |
label3 |
label4 |
label5 |
label6 |
label7 |
label8 |
label9 |
|
label1 |
30...... |
30...... |
200.... |
-10..... |
30...... |
200.... |
label8 |
label9 |
|
ritorna
EXCEL
scrivere valori in celle
A1,B1,C1,D1 e formule in A2..A6
|
A |
B |
C |
D |
E |
1 |
10 |
20 |
30 |
40 |
|
2 |
=SE(A1>B1;a*b;"*") |
|
|
|
|
3 |
=SE(A1<B1;A1+B1;"**") |
|
|
|
|
4 |
=SE(A1<B1;A1+B1;"***") |
|
|
|
|
5 |
=SE(A1<B1;A1*B1;"***") |
|
|
|
|
6 |
=SE(A1<B1;A1-B1;"***") |
|
|
|
|
ritorna
inizio