1 / 21

Somma = A + B

Sub SOMMA( ) Dim A, B as Integer A = InputBox ("Immetti un numero") B = InputBox (“Immetti un secondo numero”) Somma = A+B Print Somma End Sub. start. stop. Leggi A,B. Somma = A + B. Stampa Somma. Prova. OK. Sub Command1_Click() Dim A, B as Integer A = InputBox(“Leggi A")

ernst
Télécharger la présentation

Somma = A + B

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SubSOMMA( ) • DimA, Bas Integer • A =InputBox("Immetti un numero") • B =InputBox(“Immetti un secondo numero”) • Somma = A+B • PrintSomma End Sub start stop Leggi A,B Somma = A + B Stampa Somma

  2. Prova OK Sub Command1_Click() Dim A, B as Integer A = InputBox(“Leggi A") B = InputBox(“Leggi B”) Somma = A+B Print Somma End Sub Proprieta’ Caption

  3. Funzioni di Input/Output • InputBox serve a prendere i dati da input. • MsgBox serve a mandare messaggi in output. • Print serve a “stampare” il risultato in output.

  4. F T condizione Diagramma 1 Diagramma 2 BLOCCHI DI FLUSSO:BLOCCO CONDIZIONALE

  5. Enunciato if (1) Serve ad effettuare operazioni alternative: If condizione Then Blocco istruzioni Else Blocco istruzioni End if

  6. ESEMPIO DI TRADUZIONE Dim A, B, X as Integer ……. If A = B Then X = 1 Else X = 2 Endif …….

  7. ESEMPIO 1.1 Se le vendite sono maggiori di 10000 e le ore lavorative maggiori di 40 assegna un bonus di 100. Private Sub Command1_Click() Dim vendite, bonusas Integer vendite = InputBox("Immetti il totale delle vendite") If vendite> 10000Then bonus =100 Else msgbox(“lavora di più!!!”) End if End Sub

  8. Enunciato if (2) If condizione1 And condizione2 Then Blocco istruzioni Else Blocco istruzioni End if N.B.Si possono mettere in And anche più di 2 condizioni.

  9. Enunciato if (3) If condizione1 Or condizione2 Then Blocco istruzioni Else Blocco istruzioni End if N.B.Si possono mettere in Or anche più di 2 condizioni

  10. Annidare enunciati if (1) If condizione1 Then if condizione2Then Blocco istruzioni Else Blocco istruzioni End if Else Blocco istruzioni End if If condizione Then Blocco di uno o più enunciati Visual Basic Else Blocco di uno o più enunciati Visual Basic End if

  11. ESEMPIO 1.2 Se le vendite sono maggiori di 10000 e le ore lavorative maggiori di 40 assegna un bonus di 100, altrimenti se le ore sono meno di 40, assegna metà bonus (50). Private Sub Command1_Click() Dimvendite, bonus, oreLavoroasInteger vendite = InputBox("Immetti il totale delle vendite") oreLavoro = InputBox("Immetti ore lavorative") Ifvendite> 10000Then IforeLavoro> 40Then bonus =100 Text1.text = bonus Else bonus = 50 Text1.text = bonus End if End if

  12. Annidare enunciati if (2) If condizione1 Then Blocco di uno o più enunciati Visual Basic Elseifcondizione2Then Blocco di uno o più enunciati Visual Basic End if

  13. ESEMPIO 2 Dire se un triangolo è equilatero, isoscele o scaleno Private Sub Command1_Click() Dim A, B, C AsInteger A = InputBox("Inserisci il lato A") B = InputBox("Inserisci il lato B") C = InputBox("Inserisci il lato C") If A = B And B = C Then Print "Triangolo Equilatero" ElseIf A = B Or B = C Or A = C Then Print "Triangolo Isoscele" End If End Sub

  14. F condizione T Diagramma 1 BLOCCHI DI FLUSSO:BLOCCO DI RIPETIZIONE

  15. Ciclo While Serve a ripetere un’istruzione (o un blocco di istruzioni) fino a quando una certa condizione rimane vera. Il numero di volte che l’istruzione viene ripetuta non è noto a priori, ma dipende dalla condizione. Do Whilecondizione Blocco di uno o più enunciati Loop

  16. ESEMPIO 3 Contare per quanti giorni la temperatura è stata superiore ai 30 gradi Private Sub Command1_Click() Dim Conta, Temperatura As Integer Conta = 0 Temperatura = 0 Print "Inserisci una serie di temperature quotidiane (terminata da -400)" DoWhile Temperatura <> -400 Temperatura = InputBox("Dammi un valore di temperatura") If Temperatura > 30 Then Conta = Conta + 1 End If Loop Print "Il numero totale di giorni afosi è "; Conta EndSub

  17. Cicli For Serve a ripetere un’istruzione (o un blocco di istruzioni) un numero x di volte, dove x è un numero noto a priori. For intContatore = intInizio to intFine [Step intIncremento] Blocco di una o più istruzioni Next Es. ForintContatore = 0 to 6 Step 2 Next

  18. ESEMPIO 4 Calcolare la media dei propri voti Private Sub Command1_Click() Dim Voto, NumeroEsami, Somma, i asInteger Dim Media as Double Print “Inserisci i tuoi voti” Somma = 0 numeroEsami=inputBox(“Inserisci numero esami”) For i=1 toNumeroEsami Voto = InputBox (“Inserisci un voto ”) Somma = Somma + Voto Next Media = Somma/NumeroEsami Print “La tua media è”; Media EndSub

  19. ESEMPIO 5 Calcolare se un certo anno sarà bisestile Private Sub Command1_Click() Dim Anno As Integer Anno = InputBox("Inserisci l'anno") If Anno Mod 4 = 0 Then If Anno Mod 100 = 0 And Anno Mod 400 <> 0 Then Print "Anno Non Bisestile" Else Print "Anno bisestile" End If Else Print "Anno Non bisestile" End If End Sub Esercizio: riscrivere il Programma facendo uso di un unico IF

  20. Esercizio da svolgere • Si scriva un programma in Visual Basic che letti da input l’area e l’altezza di un rettangolo, calcoli il triplo dell’area. Si ricorda che l’area del rettangolo è data da base* altezza.

More Related