Thomas95390
Messages postés2Date d'inscriptionvendredi 2 octobre 2009StatutMembreDernière intervention 3 octobre 2009
-
2 oct. 2009 à 17:04
PCPT
Messages postés13272Date d'inscriptionlundi 13 décembre 2004StatutMembreDernière intervention 3 février 2018
-
3 oct. 2009 à 14:07
Bonjour,
Voilà je suis débutant en Visual basic et donc je suis entrain de faire ... une calculatrice (pas vraiment révolutionnaire). Mon problème correspond à l'affichage du nombre dans la textbox résultat.
Pour pouvoir obtenir un nombre décimal, j'ai besoin de déterminer le nombre de caractère dans la variable Nombre_1_décimal pour obtenir la partie décimal du nombre que j'ajouterais à la partie entière. J'ai utilisé la fonction Len(), mais au premier chiffre décimal que j'écrit j'obtiens la valeur 8 alors que j'attends 1.
Voici un bout du programme qui vous aidera à comprendre ma démarche :
Private Sub CmdChiffre_Click(Index As Integer)
If Virgule = False Then
If CmdChiffre(Index).Index 0 Then Nombre_1 (Nombre_1 * 10)
If CmdChiffre(Index).Index 1 Then Nombre_1 (Nombre_1 * 10) + 1
If CmdChiffre(Index).Index 2 Then Nombre_1 (Nombre_1 * 10) + 2
If CmdChiffre(Index).Index 3 Then Nombre_1 (Nombre_1 * 10) + 3
If CmdChiffre(Index).Index 4 Then Nombre_1 (Nombre_1 * 10) + 4
If CmdChiffre(Index).Index 5 Then Nombre_1 (Nombre_1 * 10) + 5
If CmdChiffre(Index).Index 6 Then Nombre_1 (Nombre_1 * 10) + 6
If CmdChiffre(Index).Index 7 Then Nombre_1 (Nombre_1 * 10) + 7
If CmdChiffre(Index).Index 8 Then Nombre_1 (Nombre_1 * 10) + 8
If CmdChiffre(Index).Index 9 Then Nombre_1 (Nombre_1 * 10) + 9
End If
If Virgule = True Then
If CmdChiffre(Index).Index 0 Then Nombre_1_décimal (Nombre_1_décimal * 10)
If CmdChiffre(Index).Index 1 Then Nombre_1_décimal (Nombre_1_décimal * 10) + 1
If CmdChiffre(Index).Index 2 Then Nombre_1_décimal (Nombre_1_décimal * 10) + 2
If CmdChiffre(Index).Index 3 Then Nombre_1_décimal (Nombre_1_décimal * 10) + 3
If CmdChiffre(Index).Index 4 Then Nombre_1_décimal (Nombre_1_décimal * 10) + 4
If CmdChiffre(Index).Index 5 Then Nombre_1_décimal (Nombre_1_décimal * 10) + 5
If CmdChiffre(Index).Index 6 Then Nombre_1_décimal (Nombre_1_décimal * 10) + 6
If CmdChiffre(Index).Index 7 Then Nombre_1_décimal (Nombre_1_décimal * 10) + 7
If CmdChiffre(Index).Index 8 Then Nombre_1_décimal (Nombre_1_décimal * 10) + 8
If CmdChiffre(Index).Index 9 Then Nombre_1_décimal (Nombre_1_décimal * 10) + 9
End If
'Nombre_1_décimal = Nombre_1_décimal * 10 ^ (-Len(Nombre_1_décimal))
TxtRésultat.Text = Nombre_1 + Nombre_1_décimal
End Sub
Quelqu'un serait assez aimable pour m'expliquer la bonne démarche.
Merci beaucoup
A voir également:
Problème pour compter le nombre de caractère d'une variable numérique
Thomas95390
Messages postés2Date d'inscriptionvendredi 2 octobre 2009StatutMembreDernière intervention 3 octobre 2009 3 oct. 2009 à 11:37
Merci pour ton aide. Mais comme je débute que depuis peut j'ai pas encore les automatisme pour voir les simplifications que je peux faire.
Enfin merci pour ton aide.