pro10

sintassi PASCAL VBA VISUAL EXCEL stringaP stringaV stringaVB



PASCAL
tipi
INTERI		INTEGER...LONGINT..SHORTINT...BYTE...WORD
DECIMALI	REAL
CARATTERE	CHAR
STRINGA		STRING
BOLEANI		TRUE,FALSE
INDICIZZATE     

operazioni	
addizione	+		a+b		interi-reali
sottrazione	-		a-b		interi-reali
moltiplicazione	*		a*b		interi-reali
divisione	DIV     	a DIV b		interi
resto		MOD 		a MOD b		interi
divisione	/		a/b		reali

funzioni particolari(interi e reali)
assoluto	abs(x)
quadrato	sqr(x)
radice quadrata	sqrt(x)
esponenziale	exp(x)
arrotondamento	round(x)
troncamento	trunc(x)
intero		int(x)

ASSEGNAZIONE valore x:=valore

OPERATORI vari AND,OR,NOT,>,<,<>...
DICHIARAZIONE con Var nome:tipo;

assoluto abs(x)
intero int(x)
troncato trunc(x)
arrotondato round(x)
quadrato sqr(x)
radice quadrata sqrt(x)
casuale random(1)
quoziente x div y
resto x mod y
esponenziale exp(x)
logaritmo n. ln(x)
logaritmo d. ln(x)/ln(10)
seno sin(x)
coseno cos(x)

program pro5;
uses crt;
var x,y:integer;
    r:real;
begin
clrscr;
writeln(abs(-5));
writeln(int(5.23));
writeln(trunc(5.26));
writeln(round(7.8));
writeln(sqr(5));
writeln(sqrt(100));
writeln(random(1));
writeln(100 div 20);
writeln(100 mod 12);
writeln(exp(3));
writeln(ln(100));
writeln(ln(100)/ln(10));
writeln(sin(30*PI/180));
writeln(cos(30*PI/180));
readln;
end.
BOOLEAN
program pro3;
uses crt;
var a,b,c,d:integer;
    conferma:boolean;
begin
clrscr;
a:=10;
b:=50;
c:=100;
d:=200;
(*variabili boolean *)
if a>b then writeln(a-b);
if a<b then writeln(b-a);
if a>b then writeln(a-b)
 else writeln(b-a);
 if a>=b then writeln(a+b)
  else writeln(b-a);
if ((b<a) or ( c<d)) then writeln(a+b)
 else writeln(a*b);
 if ((a<b) and (c>d)) then writeln(a+b)
 else writeln(a*b);
if not a>b then writeln(b-a)
 else writeln(a-b);
 (* uso di True e di False nei test di controllo *)
conferma:=false;
if a<b then conferma:=true;
if conferma then writeln(a*10);
conferma:=false;
if a>b then  conferma:=true;
begin
if conferma then writeln(a*1)
else
writeln(b*5);
end;
readln;
end.
RUN e visualizza

40
40
40
60
500
-40
100
250
ritorna

VISUAL BASIC e VBA
TIPI
INTERI		INTEGER...LONG
DECIMALI	SINGLE....DOUBLE..CURRENCY
STRINGA		STRING
BOLEANI		TRUE,FALSE
DATE
VARIANT
UTENTE
INDICIZZATE


ASSEGNAZIONE valore x=dato

OPERATORI vari AND,OR,NOT,>,<,<>...

DICHIARAZIONE con DIM nome e tipo
dim x as integer
dim a,b,c as integer
dim a as integer,b as integer
dim a as integer,x as string
assoluto abs(x)
segno sgn(x)
intero int(x)
quadrato sqr(x)
casuale rnd()
esponenziale exp(x)
logaritmo n. log(x)
logaritmo d. log(x)/log(10)
potenza x^n
seno sin(x)
coseno cos(x)
tangente tan(x)
arcotangente atn(x)

Private Sub CommandButton1_Click()
Cells(1, 1) = Abs(-5)
Cells(2, 1) = Sgn(-5)
Cells(3, 1) = Int(-5)
Cells(4, 1) = Rnd()
Cells(5, 1) = Sqr(4)
Cells(7, 1) = Exp(2)
Cells(8, 1) = Log(100)
Cells(9, 1) = Log(100) / Log(10)
Cells(10, 1) = Sin(30 * 3.14 / 180)
Cells(11, 1) = Cos(30 * 3.14 / 180)
Cells(12, 1) = Tan(30 * 3.14 / 180)
Cells(13, 1) = Atn(2)
Cells(14, 1) = 10 ^ 3
Cells(15, 1) = 10 Mod 3

End Sub
Private Sub CommandButton1_Click()
Dim g As Double
g = 30 * 3.14 / 180
Cells(1, 1) = Abs(5)
Cells(2, 1) = Sgn(5)
Cells(3, 1) = Int(5.42)
Cells(4, 1) = Sqr(5)
Cells(5, 1) = Rnd(5)
Cells(6, 1) = Exp(2)
Cells(7, 1) = Log(100)
Cells(8, 1) = Log(100) / Log(10)
Cells(9, 1) = 5 ^ 3
Cells(10, 1) = Sin(g)
Cells(11, 1) = Cos(g)
Cells(12, 1) = Tan(g)
Cells(13, 1) = Atn(2)
End Sub
Private Sub CommandButton1_Click()
Cells(1, 1) = Abs(-5)
Cells(2, 1) = Sgn(-5)
Cells(3, 1) = Int(-5)
Cells(4, 1) = Rnd()
Cells(5, 1) = Sqr(4)
Cells(7, 1) = Exp(2)
Cells(8, 1) = Log(100)
Cells(9, 1) = Log(100) / Log(10)
Cells(10, 1) = Sin(30 * 3.14 / 180)
Cells(11, 1) = Cos(30 * 3.14 / 180)
Cells(12, 1) = Tan(30 * 3.14 / 180)
Cells(13, 1) = Atn(2)
Cells(14, 1) = 10 ^ 3
Cells(15, 1) = 10 Mod 3

End Sub


5
1
5
2,236067977
0,705547512
7,389056099
4,605170186
2
125
0,499770103
0,866158094
0,5769964
1,107148718

funzioni e operazioni eseguibili cfr.pascal e altra pagina
boolean
End SubPrivate Sub CommandButton1_Click()
Dim a, b, c, d As Integer
Dim conferma As Boolean
a = Cells(1, 1)
b = Cells(1, 2)
c = Cells(1, 3)
d = Cells(1, 4)
If a > b Then
Cells(2, 1) = a - b
End If
If a < b Then
Cells(2, 2) = b - a
End If
If a >= b Then
Cells(2, 3) = a - b
End If
If a > b Then
Cells(3, 1) = a - b
 Else
  Cells(3, 2) = b - a
  End If
If a < b And c < d Then
Cells(4, 1) = a * 10
 Else
  Cells(4, 2) = a * 100
  End If
If a < b Or c > d Then
Cells(5, 1) = a * 5
 Else
  Cells(5, 2) = a * 8
  End If
conferma = False
If a < b Then
conferma = True
If conferma Then
Cells(6, 1) = a * a
End If
End If
conferma = False
If a > b Then
conferma = True
If conferma Then
Cells(7, 1) = a * a
End If
Else
Cells(7, 2) = b * a
End If

end sub
  A B C D
1 10 50 100 200
2   40    
3   40    
4 100      
5 50      
6 100      
7   500    
8        

ritorna

VISUAL BASIC boolean

Private Sub CommandButton1_Click()
Dim a, b, c, d As Integer
Dim conferma As Boolean
a = 10
b = 50
c = 100
d = 200

Label1.Caption = a
Label2.Caption = b
Label3.Caption = c
Label4.Caption = d

If a > b Then
Label5.Caption = a - b
End If
If a < b Then
Label6.Caption = b - a
End If
If a >= b Then
Label7.Caption = a - b
End If
If a > b Then
Label8.Caption = a - b
 Else
  Label9.Caption = b - a
  End If
If a < b And c < d Then
Label10.Caption = a * 10
 Else
  Label11.Caption = a * 100
  End If
If a < b Or c > d Then
Label12.Caption = a * 5
 Else
  Label13.Caption = a * 8
  End If
conferma = False
If a < b Then
conferma = True
If conferma Then
Label14.Caption = a * a
End If
End If
conferma = False
If a > b Then
conferma = True
If conferma Then
Label15.Caption = a * a
End If
Else
Label16.Caption = b * a
End If

End Sub

label1 label2 label3 label4 label5 label6
label7 label8 label9 label10 label1 label12
label13 label14 label15 label16   PULSANTE

ritorna

funzioni stringa con PASCAL
program pro5a;
uses crt;
var x:integer  ;
    a,b,c,d:string  ;
    s1,s2,unire:string;
begin
clrscr;
s1:='maria';
s2:='rosa';
a:='laudare';
(* lunghezza stringa *)
x:=length(a);
writeln(x);
(* copia caratteri da inizio a lunghezza-3....radice*)
b:=copy(a,1,x-3);
writeln(b);
(*copia tutta la stringa meno ultimo carattere*)
c:=copy(a,1,x-1);
writeln(c);
(*copia n caratteri da punto indicato...desinenza *)
d:=copy(a,x-2,3);
writeln(d);
(* copia unione stringhe *)
writeln(s1+s2);
unire:=concat(s1,s2);
writeln(unire);
readln;
end.
RUN per visualizzare 

7
laud
laudar
are
mariarosa
mariarosa
ritorna

VBA con EXCEL
right$(testo,n).......n caratteri da destra
left$(testo,n)........n caratteri da sinistra
len(testo)............lunghezza testo
mid$(testo,p,n).......n caratteri da p
testo1 & testo2.......unione testi
testo1+testo2.........unione testi
"testo1"+"testo2".....unione testi
"testo1"&"testo2".....unione testi

Private Sub CommandButton1_Click()
Dim a, b, c As String
Dim x As Integer
b = "maria"
c = "rosa"
a = "laudare"
Cells(1, 1) = Len(a)
x = Len(a)
Cells(2, 1) = Right$(a, x - 3)
Cells(3, 1) = Left$(a, x - 1)
Cells(4, 1) = Mid$(a, 2, 2)
Cells(5, 1) = "maria" + "rosa"
Cells(6, 1) = b + c
Cells(7, 1) = b & c
End Sub


7
dare
laudar
au
mariarosa
mariarosa
mariarosa
ritorna

VISUAL BASIC

Private Sub CommandButton1_Click()
Dim a, b, c As String
Dim x As Integer
b = "maria"
c = "rosa"
a = "laudare"
Label1.Caption = Len(a)
x = Len(a)
Label2.Caption = Right$(a, x - 3)
Label3.Caption = Left$(a, x - 1)
Label4.Caption = Mid$(a, 2, 2)
Label5.Caption = "maria" + "rosa"
Label6.Caption = b + c
Label7.Caption = b & c
End Sub
7
dare
laudar
au
mariarosa
mariarosa
mariarosa
ritorna

EXCEL
=ASS(-5)
=SEGNO(5)
=INT(5,43)
=TRONCA(123,56)
=ARROTONDA(123,456;2)
=POTENZA(10;2)
=RADQ(100)
=CASUALE()
=RESTO(10;4)
=EXP(3)
=FATTORIALE(5)
=LN(100)
=LOG(100;2)
=LOG10(100)
=PARI(123,34)
=PI.GRECO()
=PRODOTTO(3;4;5)
=SEN(1)
=COS(1)
=DISPARI(123,45)
=SOMMA(2;3;4)
=TAN(1)
=ARCCOS(1)
=ARCSEN(1)
=ARCTAN(1)
=MAX(20;3)
=MIN(30;3)
=SINISTRA("laudare";3)
=LUNGHEZZA("laudare")
=CONCATENA("maria";"rosa")
=STRINGA.ESTRAI("laudare";3;2)
=DESTRA("laudare";3)
Booleani
10	50	100	200
=SE(A1>B1;A1-B1;B1-A1)			
=SE(A1<B1;B1-A1;"")			
=SE(A1>=B1;A1-B1;B1-A1)			
=SE(A1>B1;A1-B1;B1-A1)			
=SE(E(A1<B1;C1<D1;A1*10);A1*100)			
=SE(O(A1<B1;C1>D1);A1*5;A1*8)			
=E(A1<B1;C1<D1)			
=E(A1>B1;C1<D1)			
=NON(A1<B1)			
=NON(A1>B1)			
=SE(A11;1;0)			
=SE(A10;1;0)		
	
			
			

ritorna

inizio