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

Fonction retournant deux éléments

2 réponses
Avatar
Jean
Bonjour à tous,

j'ai écris le petit bout de code ci-dessous pour extraire le nom et le
prénom d'une chaine de caractère.
je ne sais pas comment je demande à la fonction de retourner les deux
éléments "nom" et "prenom" pour pouvoir les afficher dans test1


Function test(contact As String)
Position = InStr(1, contact)
prenom = Left(texte, Position)
nom = Right(texte, (Len(contact) - Position))
End Function

Sub test1()
tab_contact = test("jean vasseur")
MsgBox toto(1)
End Sub

Merci d'avance pour votre aide

Jean

2 réponses

Avatar
JpPradier
Bonjour jean

En modifiant ta macro comme suit, ca devrait aller :

Function test(contact As String)
Dim Tout(2)
Position = InStr(1, contact, " ")
prenom = Left(contact, Position - 1)
nom = Right(contact, (Len(contact) - Position))
Tout(0) = prenom
Tout(1) = nom
test = Tout
End Function

Sub test1()
tab_contact = test("jean vasseur")

MsgBox tab_contact(0) & " " & tab_contact(1)
End Sub


j-p
Avatar
Jean
Merci beaucoup

Jean

"JpPradier" a écrit dans le message
de news:
Bonjour jean

En modifiant ta macro comme suit, ca devrait aller :

Function test(contact As String)
Dim Tout(2)
Position = InStr(1, contact, " ")
prenom = Left(contact, Position - 1)
nom = Right(contact, (Len(contact) - Position))
Tout(0) = prenom
Tout(1) = nom
test = Tout
End Function

Sub test1()
tab_contact = test("jean vasseur")

MsgBox tab_contact(0) & " " & tab_contact(1)
End Sub


j-p