Question 1 Sub nomPrenom() Dim prenom As String, nom As String prenom = InputBox("prenom") nom = InputBox("nom") MsgBox ("tu es" + prenom + nom) End Sub Question 2 Sub note() Dim note As Double Dim st As String note = InputBox("note") note = note * 1.1 st = CStr(note) MsgBox ("ta note est" + st) End Sub Sub t() Question 3 Dim t As Double t = InputBox("Quelle est la temperature ?") If t > 200 Then MsgBox ("extrêmement chaud") ElseIf 200 > t And t > 40 Then MsgBox ("élevé") ElseIf 40 > t And t > 20 Then MsgBox ("correct") ElseIf 20 >= t And t > 0 Then MsgBox ("correct") Else MsgBox ("Beaucoup trop froid") End If End Sub
Function com(montant As Double) com As Double com = 20 If montant >= 5000 Then com = 5000 * 0.012 + (montant - 5000) * 0.009 Else com = montant * 0.012 End If If com < 20 Then com = 20 End If MsgBox com End Function Function age(datee As Date) Dim a As Integer age = DateDiff("yyyy", datee, Date) MsgBox age End Function Function etudiant() As String Dim cellule As Range Dim nb As Integer, Mini As Integer, Maxi As Integer, r As Integer nb = 0 For Each cellule In Range("A1:A14") If Not IsEmpty(cellule) Then nb = nb + 1 End If Next Mini = 1 Maxi = nb Randomize r = Int((Maxi - Mini + 1) * Rnd + Mini) etudiant = Range("A" & r).Value MsgBox (etudiant) End Function Exercice 7 Sub nbplus() Dim tableau(10) As Integer, r As String, s As Integer, max As Integer Randomize r = "" For i = 0 To 10 tableau(i) = Int((50 - 1 + 1) * Rnd + 1) r = r & " " & tableau(i) Next MsgBox (r) s = 0 For i = 0 To 10 s = s + tableau(i) Next MsgBox (s) max = tableau(0) For i = 1 To 10 If tableau(i) > max Then max = tableau(i) End If Next MsgBox (max) End Sub Exercice 8 Sub madate() Range("B2").Value = Date End Sub exercice 9 Créer un bouton qui lance le formulaire. Sub lancement() monForm.Show End Sub Au clic du bouton ok, fermer la fenetre et realiser le calcul. Private Sub ok_Click() Dim a As Integer monForm.Hide a = CInt(TextBox1) + CInt(TextBox2) Range("C1").Value = a End Sub Mission Loto Sub loto() Dim tableau(2) As Double, essai(2) As Double, hit As Integer, stack As Double, try As Integer stack = 0 try = 0 Randomize Do stack = stack - 5 try = try + 1 For i = 0 To 2 tableau(i) = Int(49 * Rnd + 1) If i = 1 Then While tableau(i) = tableau(0) tableau(i) = Int(49 * Rnd + 1) Wend End If If i = 2 Then While tableau(i) = tableau(0) or tableau(i) = tableau(2) tableau(i) = Int(49 * Rnd + 1) Wend End If Next MsgBox (CStr(tableau(0)) + " " + CStr(tableau(1)) + " " + CStr(tableau(2))) For i = 0 To 2 essai(i) = InputBox("entrer un nombre entre 1 et 50") If i = 1 Then while essai(i) = essai(0) essai(i) = inputbox("entrez un autre nombre") wend End If If i = 2 Then while essai(i) = essai(0) or essai(i) = essai(1) essai(i) = inputbox("entrez un autre nombre") wend End If Next hit = 0 For i = 0 To 2 For j = 0 To 2 If tableau(i) = essai(j) Then hit = hit + 1 Next Next If hit = 2 Then stack = stack + 500 MsgBox ("vous avez gagnez 500") Range("A" & try).Value = 500 ElseIf hit = 3 Then stack = stack + 5000 MsgBox ("vous avez gagné 5000") Range("A" & try).Value = 5000 Else MsgBox ("desolé t'as perdu") Range("A" & try).Value = 0 End If MsgBox (CStr(stack)) choix = InputBox("voulez-vous rejouer") Loop While choix = "oui" MsgBox ("vos gains totaux sont de " + CStr(stack)) Range("B" & 1).Value = stack End Sub