operazione con If..Select case con VBA
ritorna con
variavba.htm


ciclo4.ppt

attivazione di Select Case multipla

Option Explicit
Rem uso di case multipli
Private Sub CommandButton1_Click()
Dim numero As Integer
numero = TextBox1.Text
Select Case numero
Rem numero 1
Case 1
ListBox1.AddItem (numero & " " & numero)
ListBox1.AddItem ("-------")
Rem numero tra 2,3,4,5
Case 2, 3, 4, 5
ListBox1.AddItem (numero & " " & numero + numero)
ListBox1.AddItem ("-------")
Rem numero tra 6 e 10
Case 6 To 10
ListBox1.AddItem (numero & " " & numero * numero)
ListBox1.AddItem ("-------")
Rem numero maggiore di 100
Case Is > 100
ListBox1.AddItem (numero & " " & numero * 3)
ListBox1.AddItem ("-------")
Rem numero 11 o tra 12 e 15 o maggiore di 20
Case 11, 12 To 15, Is > 20
ListBox1.AddItem (numero & " " & numero - 1)
ListBox1.AddItem ("-------")
End Select
End Sub

Private Sub UserForm_Click()

End Sub


ciclo11.ppt
attivazione di Select Case semplice e chiamata di procedura

Option Explicit
Rem uso di case multipli
Private Sub CommandButton1_Click()
Dim numero As Integer
numero = TextBox1.Text
Select Case numero
Rem numero 1
Case 1
Call foto1
Case 2
Call foto2
Case 3
Call foto3
End Select
End Sub

Private Sub foto1()
Image1.Visible = "true"
Image2.Visible = True
Image3.Visible = True
End Sub
Private Sub foto2()
Image4.Visible = "true"
Image5.Visible = True
End Sub
Private Sub foto3()
Image6.Visible = "true"
Image7.Visible = True
Image8.Visible = "true"
Image9.Visible = True
Image10.Visible = "true"

End Sub


Private Sub UserForm_Click()
Image1.Visible = False
Image2.Visible = False
Image3.Visible = False
Image4.Visible = False
Image5.Visible = False
Image6.Visible = False
Image7.Visible = False
Image8.Visible = False
Image9.Visible = False
Image10.Visible = False



End Sub


ciclo12.ppt
attivazione di Select Case multipla e chiamata di procedura

Option Explicit
Rem uso di case multipli
Private Sub CommandButton1_Click()
Dim numero As Integer
numero = TextBox1.Text
Select Case numero
Rem numero 1
Case 1
Rem docenti
Call pro1
Case 2 To 4
Rem studenti
Call pro2
Case 5
Rem impiegati
Call pro3
Case Is > 5
Rem genitori
Call pro4
End Select

End Sub

Private Sub CommandButton2_Click()
TextBox1 = ""
TextBox1.SetFocus
ListBox2.Visible = False
ListBox3.Visible = False
ListBox4.Visible = False
ListBox5.Visible = False
ListBox2.Clear
ListBox3.Clear
ListBox4.Clear
ListBox5.Clear
End Sub



Private Sub pro1()
ListBox2.Visible = True

ListBox2.AddItem ("llsta docenti")
End Sub

Private Sub pro2()
ListBox3.Visible = True

ListBox3.AddItem ("lista studenti")
End Sub
Private Sub pro3()
ListBox4.Visible = True

ListBox4.AddItem ("lista impiegati")
End Sub

Private Sub pro4()
ListBox5.Visible = True

ListBox5.AddItem ("lista genitori")
End Sub


ifthen1.ppt

controllo condizione con If...then...Else..End If

Option Explicit

Private Sub CommandButton1_Click()
'esegue prodotto solo per numeri positivi
Dim a, b, somma As Integer
a = TextBox1
b = TextBox2
If a <= 0 Or b <= 0 Then
ListBox1.AddItem ("solo numeri positivi")
Else
ListBox1.AddItem ("prodotto a*b = " & a * b)
End If
ListBox1.AddItem ("--------")
End Sub

Private Sub UserForm_Click()

End Sub


ifthen2.ppt

controllo condizione con If...then multipli...Else e dati assegnati

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 c < d Then
Label6.Caption = c + d
Label7.Caption = c * d
Else

Label8.Caption = c * 10
Label9.Caption = d * 100
End If
End Sub


ifthen3.ppt
controllo condizione con
If...then multipli...Else e dati da tastiera

Private Sub CommandButton1_Click()
Dim a, b, c, d As Integer
a = TextBox1.Text
b = TextBox2.Text
c = TextBox3.Text
d = TextBox4.Text
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 c < d Then
Label6.Caption = c + d
Label7.Caption = c * d
Else
Label8.Caption = c * 10
Label9.Caption = d * 100
End If
End Sub

Private Sub CommandButton2_Click()
Label1 = ""
Label2 = ""
Label3 = ""
Label4 = ""
Label5 = ""
Label6 = ""
Label7 = ""
Label8 = ""
Label9 = ""
TextBox1 = ""
TextBox2 = ""
TextBox3 = ""
TextBox4 = ""
End Sub


Private Sub UserForm_Click()

End Sub


casek1.ppt
seleziona con
Select case k


Private Sub CommandButton1_click()
Dim a, b, c, d, k As Integer
a = 10
b = 20
c = 30
d = 40
k = TextBox1.Text

Select Case k
Case 1
Label1.Caption = a * b
Label2.Caption = a * b * c
Case 2, 3, 4
Label3.Caption = c + d
Case 5
Label4.Caption = c - d
End Select

End Sub

Private Sub CommandButton2_Click()
Label1 = ""
Label2 = ""
Label3 = ""
Label4 = ""

TextBox1 = ""

End Sub



Private Sub UserForm_Click()

End Sub