Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Souci avec un test

2 réponses
Avatar
Ayrton [ASC]
Bonsoir à tous,

Voilà, j'ai essayé de faire une petite boucle pour faire un test mais je
sèche devant le résultat ; voici ce que j'ai fait :
Sub test()
Dim S As String
S = "Toto"
For I = 1 To 4
S = S + S
Next I
MsgBox S
End Sub

Je pensais que la MsgBox allait m'afficher 4 fois " Toto " ; en fin de
compte, "toto" est affcihé 16 fois dans la MsgBox.
J'ai un peu de mal à comprendre mon erreur.....
Un très grand merci d'avance à ceux qui pourront m'éclairer...;-)

Merci et Joyeux Noêl à vous tous

Cordialement

--
Christophe
--------------------------------------------------------------
--------------------------------------------------------------
http://cerbe rmail.com/?cUkbZNnG8H (Enlever l'espace)
ou
http://viadresse.com?25031980
Recherche dans les Archives :
http://groups.google.fr/group/microsoft.public.fr.windowsxp?hl=fr
Forum Office :
http://forums.offices.free.fr/

2 réponses

Avatar
Jacky
Bonsoir,

Pour comprendre ton erreur, insère un msgbox dans la boucle
'---
Sub test()
Dim S As String
S = "Toto"
For I = 1 To 4
S = S + S
Msgbox S
Next I
MsgBox S
End Sub
'--------
Avent de commencer la boucle:
S=toto
1er passage S=S+S
donc S=TotoToto
2ème passage S=S+S et S est déjà égale à TotoToto
Donc S=TotoTotoTotoToto
3ème passage S=S+S et S est déjà égale à TotoTotoTotoToto
Donc S=TotoTotoTotoTotoTotoTotoTotoToto
etc...
'-----------
La logique serait :
'---------
Sub test()
Dim X As String
S = "Toto"
For I = 1 To 4
X = X & S
'ou
'X = X + S
'ou
'X = X & "Toto"
Next I
MsgBox X
End Sub

'--------
--
Salutations
JJ



"Ayrton [ASC]" a écrit dans le message de news:
%
Bonsoir à tous,

Voilà, j'ai essayé de faire une petite boucle pour faire un test mais je
sèche devant le résultat ; voici ce que j'ai fait :
Sub test()
Dim S As String
S = "Toto"
For I = 1 To 4
S = S + S
Next I
MsgBox S
End Sub

Je pensais que la MsgBox allait m'afficher 4 fois " Toto " ; en fin de
compte, "toto" est affcihé 16 fois dans la MsgBox.
J'ai un peu de mal à comprendre mon erreur.....
Un très grand merci d'avance à ceux qui pourront m'éclairer...;-)

Merci et Joyeux Noêl à vous tous

Cordialement

--
Christophe
--------------------------------------------------------------
--------------------------------------------------------------
http://cerbe rmail.com/?cUkbZNnG8H (Enlever l'espace)
ou
http://viadresse.com?25031980
Recherche dans les Archives :
http://groups.google.fr/group/microsoft.public.fr.windowsxp?hl=fr
Forum Office :
http://forums.offices.free.fr/




Avatar
Ayrton [ASC]
Bonjour *Jacky*,
Dans ton message de news:,
Tu nous annonçais ce qui suit :-(*)
Bonsoir,


Bonjour,

[....}
'-----------
La logique serait :
'---------
Sub test()
Dim X As String
S = "Toto"
For I = 1 To 4
X = X & S
'ou
'X = X + S
'ou
'X = X & "Toto"
Next I
MsgBox X
End Sub


Effectivement, ça va mieux comme ça ;-)
Je me suis bien emmêlé !
Ton explication est claire et je comprends maintenant mon erreur.

Encore merci

--
Christophe
--------------------------------------------------------------
--------------------------------------------------------------
http://cerbe rmail.com/?cUkbZNnG8H (Enlever l'espace)
ou
http://viadresse.com?25031980
Recherche dans les Archives :
http://groups.google.fr/group/microsoft.public.fr.windowsxp?hl=fr
Forum Office :
http://forums.offices.free.fr/