Initialisation d'une structure par référence

IenchGaleu

XLDnaute Nouveau
Bonjour!

Voila, j'ai ce code :
Code:
Function InitStructInfo(ByRef struct As t_recherche) As t_recherche

    struct.prenom = Range("G6")
    struct.nom = Range("G7")
    struct.titre = Range("G8")
    struct.fonction = Range("G9")
    struct.organisme = Range("G10")
    struct.ville = Range("G11")
    struct.departement = Range("G12")
    struct.categorie1 = Range("G13")
    struct.categorie2 = Range("G14")

End Function
C'est une petite fonction qui sert à remplir ma structure des informations sésie pas l'utilisateur.
Mais je n'arrive pas à récupérer la structure dans sa fonction mère, c'est à dire:
Code:
Sub ListeFichier()

    Dim struct As t_recherche

    struct = InitStructInfo(struct)
    MsgBox struct.prenom

End Sub
Voila la strucutre:
Code:
Public Type t_recherche

    prenom As String
    nom As String
    titre As String
    fonction As String
    organisme As String
    ville As String
    departement As String
    categorie1 As String
    categorie2 As String

End Type

J'ai donc besoin de votre aide pour comprendre comment récupérer une structure par référence.
Merci d'avance pour votre aide! :)

PS: Le tout se trouve dans un module simple. ^^
 

Grand Chaman Excel

XLDnaute Impliqué
Re : Initialisation d'une structure par référence

Bonjour IenchGaleu,

En déclarant ta variable "struct" au niveau module et en utilisant une SUB pour initialiser ta variable, ça devrait fonctionner :

Exemple :

VB:
Option Explicit

Public Type t_recherche

    prenom As String
    nom As String
    titre As String
    fonction As String
    organisme As String
    ville As String
    departement As String
    categorie1 As String
    categorie2 As String

End Type

Dim struct As t_recherche       'Variable de niveau module

' -----
Sub ListeFichier()

    InitStructInfo      'initialisation
    MsgBox struct.prenom
    
    ' -----------------------
    'essai
    struct.prenom = "Toto"
    MsgBox struct.prenom
    InitStructInfo      'initialisation
    MsgBox struct.prenom
    ' --------------------

End Sub

Sub InitStructInfo()
    struct.prenom = Range("G6")
    struct.nom = Range("G7")
    struct.titre = Range("G8")
    struct.fonction = Range("G9")
    struct.organisme = Range("G10")
    struct.ville = Range("G11")
    struct.departement = Range("G12")
    struct.categorie1 = Range("G13")
    struct.categorie2 = Range("G14")
End Sub

À essayer...
 

Statistiques des forums

Discussions
312 499
Messages
2 089 002
Membres
104 002
dernier inscrit
SkrauzTTV