Petite question pour les experts

Résolu
jihednond Messages postés 143 Date d'inscription jeudi 27 mars 2008 Statut Membre Dernière intervention 3 septembre 2011 - 27 nov. 2008 à 17:20
jihednond Messages postés 143 Date d'inscription jeudi 27 mars 2008 Statut Membre Dernière intervention 3 septembre 2011 - 28 nov. 2008 à 08:33
@§§§SALUE§§§@









<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="ProgId" content="Word.Document" />
<meta name="Generator" content="Microsoft Word 11" />
<meta name="Originator" content="Microsoft Word 11" />
<link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" />
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:HyphenationZone>21</w:HyphenationZone>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" LatentStyleCount="156">
</w:LatentStyles>
</xml><![endif]-->
<style>
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
@page Section1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 70.85pt 70.85pt;
mso-header-margin:36.0pt;
mso-footer-margin:36.0pt;
mso-paper-source:0;}
div.Section1
{page:Section1;}
-->
</style>
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Tableau Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
Bonjour cher programmeurs










<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="ProgId" content="Word.Document" />
<meta name="Generator" content="Microsoft Word 11" />
<meta name="Originator" content="Microsoft Word 11" />
<link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" />
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:HyphenationZone>21</w:HyphenationZone>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" LatentStyleCount="156">
</w:LatentStyles>
</xml><![endif]-->
<style>
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
@page Section1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 70.85pt 70.85pt;
mso-header-margin:36.0pt;
mso-footer-margin:36.0pt;
mso-paper-source:0;}
div.Section1
{page:Section1;}
-->
</style>
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Tableau Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
Mon problème consiste a créer une condition pour tester si
le nombre et


Numérique et entre 0 et 20 mes en écrivent le script  un message m’affiche


Une erreur disant que c’est incompatible …j’ai chercher dans
MSDN et sur


Internet mes sont espoir méme mon prof de VB na pas trouver
la solution



….





Private Sub
Command1_Click()





If (Text1.Text
>= 0) And (Text1.Text <= 20) Then





ElseIf
IsNumeric(Text1.Text) Then





MsgBox "good"




Else


MsgBox "wrong"


End If



 




End Sub



 




Merci d’avance

8 réponses

jmenfous Messages postés 117 Date d'inscription mardi 21 janvier 2003 Statut Membre Dernière intervention 2 juillet 2009 1
27 nov. 2008 à 17:49
pardon j'ai mal copier mo exemple :

        If IsNumeric(Text1.Text) Then
            Dim d As Double = CDbl(Text1.Text)

            If (d >= 0) And (d <= 20) Then

                MsgBox("good")

            Else
                MsgBox("wrong")

            End If
        Else
            MsgBox("wrong")
        End If

Jérémy Jeanson MCP
3
cs_Jack Messages postés 14006 Date d'inscription samedi 29 décembre 2001 Statut Modérateur Dernière intervention 28 août 2015 79
27 nov. 2008 à 17:50
SaluE
aussi

Comme son nom l'indique, Text1.Text est ... du texte.
Une comparaison directe entre un texte et un chiffre peut quelque fois révéler des surprises.
La prochaine fois, dit le, ça augmentera tes chances d'avoir de l'aide.

Ton problème est l'ordre des tests : Avant de vérifier que la valeur est bien comprise entre 0 et 20, assure toi que la valeur est bien reconnue comme un chiffre
--> Mets le IsNumeric avant le test d'intervale.
Car, si tu compares un texte avec un chiffre, tu obtiens une erreur de type incompatible, c'est normal.
Le problème, c'est que la virgule ou le point (je ne sais plus) n'est pas reconnu comme une vraie virgule à cause du fait que les français et les anglais n'utilisent pas le même symbole.

Vala
Jack, MVP VB
NB : Je ne répondrai pas aux messages privés

<hr />Le savoir est la seule matière qui s'accroit quand on la partage (Socrate)
3
jmf0 Messages postés 1566 Date d'inscription mardi 26 décembre 2000 Statut Membre Dernière intervention 5 avril 2013 8
27 nov. 2008 à 17:53
Bonjour,

1) Petite question pour les experts n'est pas un titre explicite (évite ce genre de titre)
2) Ta question est très loin d'être une question "pour experts" !!!
3) "méme mon prof de VB na pas trouver la solution" ===>> change très vite de prof, car c'est du niveau débutant
4) tu ne nous parles ni de de que tu permets ou non la saisie de nombres décimaux, ni (si nombres décimaux permis) du séparateur utilisé !!!

Voilà un bout de code uiltra-simple aui permet la saisie, quel que soit ce séparateur :


Private Sub Command1_Click()
    If Not IsNumeric(Replace(Text1.Text, ".", ",")) Then
      MsgBox "ce n'est pas un nombre valable)"
    ElseIf Val(Text1.Text) >= 0 And Val(Text1.Text) <= 20 Then
      MsgBox "bon"
    Else
      MsgBox "nombre valable mais non compris entre 0 et 20"
    End If
End Sub


 


 
3
cs_loulou69 Messages postés 672 Date d'inscription mercredi 22 janvier 2003 Statut Membre Dernière intervention 2 juin 2016 1
27 nov. 2008 à 17:40
Bonjour
Private Sub Command1_Click()<?XML:NAMESPACE PREFIX = O /??>

if (CDbl(Text1.Text) >= 0) And (CDbl(Text1.Text) <= 20) Then

MsgBox "good"

Else

MsgBox "wrong"

End If

End Sub
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
jmenfous Messages postés 117 Date d'inscription mardi 21 janvier 2003 Statut Membre Dernière intervention 2 juillet 2009 1
27 nov. 2008 à 17:47
Il serrait peut être un peu plus propre de tester que tu as bine affaire à une valeur numérique...
Avec un petit IsNueric au début et non pas à la fin par exemple et une seule convertion:

        If Not IsNumeric(Text1.Text) Then
                MsgBox("wrong")
        ElseIf (d >= 0) And (d <= 20) Then
                MsgBox("good")
        Else
                MsgBox("wrong")
        End If

Jérémy Jeanson MCP
0
cs_Jack Messages postés 14006 Date d'inscription samedi 29 décembre 2001 Statut Modérateur Dernière intervention 28 août 2015 79
27 nov. 2008 à 17:53
PS : Par curiosité, tape "isnumeric" ou "tester si numerique" parmi les questions du forum : tu verras, la solution est dedans (sujet récurrent)
0
cs_casy Messages postés 7741 Date d'inscription mercredi 1 septembre 2004 Statut Membre Dernière intervention 24 septembre 2014 40
27 nov. 2008 à 19:30
"...(sujet récurrent)..."

Tout comme cette erreur de mettre le IsNumeric à la fin, qui elle aussi revient assez souvent.

Et si un prof de VB n'est pas capable de la voir, c'est à croire que c'est comme ça qu'ils l'enseignent. J'espère que non quand même

---- Sevyc64  (alias Casy) ----<hr size="2" width="100%" /># LE PARTAGE EST NOTRE FORCE #    http://aide-office-vba.monforum.com/index.php
0
jihednond Messages postés 143 Date d'inscription jeudi 27 mars 2008 Statut Membre Dernière intervention 3 septembre 2011 1
28 nov. 2008 à 08:33
@§§§salue§§§@




merci pour tout vos réponses 
[auteur/LOULOU69/38668.aspx loulou69]
[auteur/JMENFOUS/38179.aspx jmenfous ]
[auteur/JACK/2204.aspx jack]
[auteur/CASY/333139.aspx casy]
[auteur/JMF0/1519380.aspx jmf0]

c'est résolu  par[auteur/JMENFOUS/38179.aspx jmenfous][auteur/JMENFOUS/38179.aspx  ]  et [auteur/JMF0/1519380.aspx jmf0] qui proposé un script pour annuler la valeur double " truc de malin"  
merci
[auteur/CASY/333139.aspx casy] le problème est du au manque de formation ou d'enseigner or spécialité car mon prof c'est un spécialiste java et c++ --->VB 
0
Rejoignez-nous