variante6

i numeri inseriti in label vengono considerati
nella somma con + come stringhe e non numeri
con altri operatori * / - come numeri
usando Val si ottengono valori numerici
chiamata di procedure con passaggio di parametri in modo vario
notare diverso comportamento se si somma entro programma principale
o entro procedure

Private Sub CommandButton1_Click()
Rem i numeri inseriti in textbox vengono considerati tipo Variant
Rem e nella somma con + come stringhe e non numeri
Rem con altri operatori * / - come numeri
Rem usando Val si ottengono valori numerici
Const ke = " esatto "
Const kn = " errato "
Dim a, b, c, d As Integer
Dim e, f, s, t As Integer
Dim x, y, sommaxy As Integer
Dim somma1, somma2, prodotto1, prodotto2 As Integer
Label1.Caption = 5
Label2.Caption = 6

a = Label1.Caption ' considera come stringa per +
b = Label2.Caption ' considera come stringa per +
c = val(a) ' considera valore stringa come numerico
d = val(b) ' considera valore stringa come numerico
e = 8
f = 10

s = e + f ' considerati come numeri
t = val(e) + val(f)
somma1 = a + b ' somma stringhe 56
somma2 = c + d 'somma numeri 11
prodotto1 = a * b ' prodotto numeri 30
prodotto2 = c * d ' prodotto numeri 30
x = 10 ' valore numerico
y = 5 ' valore numerico
sommaxy = x + y ' somma numeri 15
ListBox1.AddItem (" programma principale somma e prodotto")
ListBox1.AddItem (kn & somma1)
ListBox1.AddItem (ke & prodotto1)
ListBox1.AddItem ("---------------")
ListBox1.AddItem (ke & somma2)
ListBox1.AddItem (ke & prodotto2)
ListBox1.AddItem ("---------------")
ListBox1.AddItem ("10+5 " & sommaxy)
ListBox1.AddItem ("---------------")
ListBox1.AddItem ("somma e+f = 8+10 = 18 " & s)
ListBox1.AddItem ("somma val(e)+val(f) = 18 " & t)
ListBox1.AddItem ("---------------")
Call esegue(val(a), val(b), (c), (d))
Call esegue2((x), (y))
Call esegue3((e), (f))
End Sub

Private Sub esegue(p As Integer, q As Integer, r As Integer, s As Integer)
Const ke = " esatto "
Const kn = " errato "
Dim somma1, somma2, prodotto1, prodotto2, sommaxy, prodottoxy As Integer
somma1 = p + q
prodotto1 = p * q
somma2 = r + s
prodotto2 = r * s
ListBox1.AddItem (" procedura esegue :somma e prodotto")
ListBox1.AddItem (ke & somma1)
ListBox1.AddItem (ke & prodotto1)
ListBox1.AddItem (ke & somma2)
ListBox1.AddItem (ke & prodotto2)
ListBox1.AddItem ("******************")
End Sub

Private Sub esegue2(p As Integer, q As Integer)
Const ke = " esatto "
Const kn = " errato "
Dim sommaxy, prodottoxy As Integer
sommaxy = p + q
prodottoxy = p * q
ListBox1.AddItem (" procedura esegue2 con 5+10,5*10 ")
ListBox1.AddItem (ke & sommaxy)
ListBox1.AddItem (ke & prodottoxy)
End Sub

Private Sub esegue3(p As Integer, q As Integer)
Const ke = " esatto "
Const kn = " errato "
Dim somma3, prodotto3 As Integer
somma3 = p + q
prodotto3 = p * q
ListBox1.AddItem (" procedura esegue3 con 8+10, 8*10 ")
ListBox1.AddItem (ke & somma3)
ListBox1.AddItem (ke & prodotto3)
End Sub


Private Sub CommandButton3_Click()
Label1 = ""
Label2 = ""
ListBox1.Clear
End Sub

vedi variante6.ppt