Dim i Dim r r = 0 For i = 1 To Len(Text1.Text) r = r + Asc(UCase(Mid$(Text1.Text, i, 1))) - 64 Next If r Mod 9 Then MsgBox (r Mod 9) Else MsgBox 9 End If
Private Sub Command1_Click() Dim sChiffre As String Dim i As Long Dim result As Long sChiffre = ValeurChaine(Text1.Text) While Len(sChiffre) > 1 result = 0 For i = 1 To Len(sChiffre) result = result + Val(Mid(sChiffre, i, 1)) Next i sChiffre = CStr(result) Wend MsgBox sChiffre End Sub Function ValeurChaine(s As String) As String Dim i As Long Dim resultat As Long resultat = 0 For i = 1 To Len(s) resultat = resultat + CorrespondanceR(Mid(s, i, 1)) Next i ValeurChaine = CStr(resultat) End Function Function CorrespondanceR(ByVal Col As String) As Integer Col = UCase(Col) CorrespondanceR = Asc(Col) - 64 If Len(Col) = 2 Then CorrespondanceR = 26 * CorrespondanceR + Asc(Mid(Col, 2, 1)) - 64 End If End Function
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionDim i Dim r r = 0 For i = 1 To Len(Text1) r = r + Asc(UCase(Mid$(Text1, i, 1))) - 64 Next MsgBox r & " = " & r Mod 9