Private Sub Command1_Click() Dim nbmax As Integer, nombre As String nbmax = 5 nombre = "01264" MsgBox toto(nbmax, nombre) End Sub Private Function toto(nbmax As Integer, nombre As String) As Boolean Dim i As Integer toto = True For i = 1 To Len(nombre) If Val(Mid(nombre, i, 1)) > nbmax Then toto = False Exit Function End If Next End Function
Private Sub Command1_Click() Dim nbmax As Integer, nombre As String nombre = "01264" MsgBox toto(nombre) End Sub Private Function toto(nombre As String) As Boolean Dim i As Integer toto = True For i = 1 To Len(nombre) If Val(Mid(nombre, i, 1)) > Len(nombre) Then toto = False Exit Function End If Next End Function
Private Function ChiffresBornes(ByVal nombre As String) As Boolean Dim listeNombres As String = "0123456789".Substring(0, nombre.Length + 1) For Each cr As Char In nombre If listeNombres.Contains(cr) = False Then Return False End If Next Return True End Function
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionj'ai un nombre de N chiffre (N <= 10)
je veux verifier si le nombre ne contient
pas un chiffre supérieur à N-1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim Nombre = "15932" If ContientChiffresSupérieurs(Nombre) = True Then MsgBox("Le nombre " & Nombre & " contient des chiffres supérieurs à la (longueur du nombre -1)") Else MsgBox("Le nombre " & Nombre & " ne contient pas des chiffres supérieurs à la (longueur du nombre -1)") End If End Sub Private Function ContientChiffresSupérieurs(ByVal Nombre As String) As Boolean Dim Longueur = Nombre.Length Dim Resultat As Boolean = False For Each Ch As Char In Nombre If IsNumeric(Ch) = True Then If Val(Ch) > (Longueur - 1) Then Resultat = True End If Next Return Resultat End Function
Dim listeNombres As String = "0123456789".Substring(word.Length) 'listNombres liste de chiffre exclue dim flag as boolean flag = false For Each cr As Char In nombre If listeNombres.Contains(cr) = True Then flag = true Exit For End If Next
Private Function toto(nombre As String) As Boolean Dim titi() As Byte titi = StrConv(nombre, vbFromUnicode) If Chr(WorksheetFunction.Max(titi)) <Len(nombre) Then toto True End Function