pro10 inizio
sintassi VBA VISUAL stringaV stringaVB
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 |
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 |
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