programma in visual basic
TRANSCRIPT
![Page 1: Programma In Visual Basic](https://reader033.vdocuments.net/reader033/viewer/2022051112/558e384c1a28abfe078b465b/html5/thumbnails/1.jpg)
Programma in Visual Basic
Spiegazione di come si traduce un programma in Visual Basic!!!!
![Page 2: Programma In Visual Basic](https://reader033.vdocuments.net/reader033/viewer/2022051112/558e384c1a28abfe078b465b/html5/thumbnails/2.jpg)
Testo del problema
• Dati N numeri ciclomotori e motocicli (nome del modello, cilindrata, prezzo), visualizzare il prezzo massimo tra i modelli di cilindrata superiore a 50cc.
![Page 3: Programma In Visual Basic](https://reader033.vdocuments.net/reader033/viewer/2022051112/558e384c1a28abfe078b465b/html5/thumbnails/3.jpg)
DATI INPUT• Numero modelli• Nome del modello• Cilindrata• Prezzo
DATI OUTPUT• Prezzo massimo tra i
modelli di cilindrata superiore a 50cc.
E adesso dobbiamo distinguere i dati input e
dati output…
![Page 4: Programma In Visual Basic](https://reader033.vdocuments.net/reader033/viewer/2022051112/558e384c1a28abfe078b465b/html5/thumbnails/4.jpg)
Nome
Variabile
Contenuto Tipo I/O/L
N Numero modelli
Numerico I
NOME Nome modello Alfanumerico I
CC Cilindrata Numerico I
P Prezzo Numerico I
PM Prezzo massimo
Numerico O
CONT Contatore Numerico L
CONTM Contatore massimo
Numerico L
Ed ora descriviamo
singolarmente le variabili
![Page 5: Programma In Visual Basic](https://reader033.vdocuments.net/reader033/viewer/2022051112/558e384c1a28abfe078b465b/html5/thumbnails/5.jpg)
Come prima cosa si fa lo pseudocodice…
INIZIO
LEGGI (N)
CONT = 0
CONTM = 0
RIPETI
LEGGI (NOME, CC, P)
CONT = CONT + 1
SE CC > 50 ALLORA
CONTM = CONTM + 1
SE CONTM = 1 ALLORA
PM = P
ALTRIMENTI
SE P > PM ALLORA
PM = P
FINE SE
FINE SE
FINE SE
FINO A CHE CONT = N
SCRIVI (PM)
FINE
![Page 6: Programma In Visual Basic](https://reader033.vdocuments.net/reader033/viewer/2022051112/558e384c1a28abfe078b465b/html5/thumbnails/6.jpg)
Inseguito si proceda facendo il
diagramma a blocchi
INIZIO
CONT=0CONTM=0
N
CONT=CONT+1
NOME, CC, P
A
F
B
C
C
F CONT=N
VPM
FINE
CONTM=CONTM+1
D
D
CONTM = 1
PM=P
P>PM
V
V
PM= P
F
CC>50 BV
A
![Page 7: Programma In Visual Basic](https://reader033.vdocuments.net/reader033/viewer/2022051112/558e384c1a28abfe078b465b/html5/thumbnails/7.jpg)
E in visual basic come si traduce??Inizio
N i
Cominciamo
dall’inizio;la form
Textbox
Nome: txtnmod
Label
Nome:lblnmod
Command
Nome:cmdcalcola
Command
Nome:cmdesci
![Page 8: Programma In Visual Basic](https://reader033.vdocuments.net/reader033/viewer/2022051112/558e384c1a28abfe078b465b/html5/thumbnails/8.jpg)
Come si dichiarano le
variabili in visual basic???
Ecco fatto!!!
![Page 9: Programma In Visual Basic](https://reader033.vdocuments.net/reader033/viewer/2022051112/558e384c1a28abfe078b465b/html5/thumbnails/9.jpg)
Il codice da scrivere deve essere eseguito alla
pressione del pulsante cmdcalcola
![Page 10: Programma In Visual Basic](https://reader033.vdocuments.net/reader033/viewer/2022051112/558e384c1a28abfe078b465b/html5/thumbnails/10.jpg)
Option Explicit
'Dati inputDim N As IntegerDim NOME As StringDim CC As IntegerDim P As Double
'Dati eleborazioneDim CONT As IntegerDim CONTM As Integer
'Dati outputDim PM As Double
Private Sub cmdcalcola_Click()
End
Ed ora…Cominceremo a scrivere qui !!!
![Page 11: Programma In Visual Basic](https://reader033.vdocuments.net/reader033/viewer/2022051112/558e384c1a28abfe078b465b/html5/thumbnails/11.jpg)
Come prima cosa devo scrivere:
N = txtnmod.text
Poi devo azzerare le variabili:
CONT = 0
CONTM = 0
A questo punto posso iniziare il ciclo
Do
Loop until
All’interno metto le istruzioni
![Page 12: Programma In Visual Basic](https://reader033.vdocuments.net/reader033/viewer/2022051112/558e384c1a28abfe078b465b/html5/thumbnails/12.jpg)
N = txtnmod.Text
'azzeramento variabili
CONT = 0CONTM = 0
Do NOME = InputBox("Dimmi il nome del modello") CC = InputBox("Dimmi la cilindrata") P = InputBox("Dimmi il prezzo") CONT = CONT + 1 If CC > 50 Then CONTM = CONTM + 1
If CONTM = 1 Then PM = P Else If P > PM Then PM = P End If End If End If Loop Until CONT = N
MsgBox " il prezzo massimo tra i modelli di cilindrata superiore a 50 cc." & "è" & CStr(PM)
End Sub
Conta solo se la cilindrata è maggiore di 50
Fine ciclo (controlla se ha esaminato tutti i modelli)
Inizio ciclo prezzo massimo
Se è il primo modello con cilindrata superiore a 50 il prezzo è quello massimo
Se il prezzo di un altro modello di cilindrata superiore a 50 è maggiore del prezzo
massimo; esso prende il posto di quello precedente.
![Page 13: Programma In Visual Basic](https://reader033.vdocuments.net/reader033/viewer/2022051112/558e384c1a28abfe078b465b/html5/thumbnails/13.jpg)
NOME, CC, P
‘Inizio cicloDo
NOME = InputBox("Dimmi il nome del modello”)CC = InputBox("Dimmi la cilindrata“)P = InputBox("Dimmi il prezzo")
Loop until
Guardiamo passo per passo …Dati input
![Page 14: Programma In Visual Basic](https://reader033.vdocuments.net/reader033/viewer/2022051112/558e384c1a28abfe078b465b/html5/thumbnails/14.jpg)
‘Inizio cicloDo
NOME = InputBox("Dimmi il nome del modello”)
CC = InputBox("Dimmi la cilindrata“)P = InputBox("Dimmi il prezzo")
If cc > 50 then CONTM = CONTM + 1
If CONTM = 1 thenPM= P
elseIf P > PM then
PM =Pend if
end ifend if
Loop until CONT =N
CC>50V CONTM=CONTM+1
FCONTM = 1
PM=P
P>PM
V
V
PM= P
F
CONT=N
![Page 15: Programma In Visual Basic](https://reader033.vdocuments.net/reader033/viewer/2022051112/558e384c1a28abfe078b465b/html5/thumbnails/15.jpg)
PM
FINE
‘Inizio cicloDo
NOME = InputBox("Dimmi il nome del modello”)CC = InputBox("Dimmi la cilindrata“)P = InputBox("Dimmi il prezzo")
If cc > 50 then CONTM = CONTM + 1
If CONTM = 1 thenPM= P
elseIf P > PM then
PM =Pend if
end ifend if
Loop until CONT =N
MsgBox " il prezzo massimo tra i modelli di cilindrata superiore a 50 cc." & "è" & CStr(PM)
End Sub
![Page 16: Programma In Visual Basic](https://reader033.vdocuments.net/reader033/viewer/2022051112/558e384c1a28abfe078b465b/html5/thumbnails/16.jpg)
Ed ecco fatto il programma!!!!!!!
ED ORA PROVALO PER VEDERE SE FUNZIONA!!!
BUONA FORTUNA!!!
![Page 17: Programma In Visual Basic](https://reader033.vdocuments.net/reader033/viewer/2022051112/558e384c1a28abfe078b465b/html5/thumbnails/17.jpg)
A cura di Coverini Chiara
3C Mercurio