-=(the3fold)=-

New Generation

Forum public

Cette partie contient des sujets épinglés depuis le forum, c'est à dire des sujets jugés interessants et qui méritent d'être partagés. Cependant, cette partie est en lecture seule. Si vous désirez poster des messages ou acceder aux discussions non épinglées, vous devez vous identifier sur le forum.


Skippy
Skippy
Super Administrateur
Voici une macro OpenOffice bien utile pour obtenir des informations sur une variable. La première fonction (ShowVarInfo) permet d'obtenir des informations pour tout type de variable (type, contenu). La deuxième fonction (ShowObjInfo) permet d'obtenir le détail d'un objet (méthodes, propriétés ...). La troisième fonction (TypeTest) est un exemple d'utilisation des deux précédentes.


option explicit

REM Affiche des informations de base pour le paramètre.
sub ShowVarInfo(vObj as variant)
    Dim s as string
    s = "TypeName = " & TypeName(vObj) & CHR$(10) &_
        "VarType = " & VarType(vObj) & CHR$(10)
    if IsNull(vObj) then
        s = s & "IsNull = True"
    elseif IsEmpty(vObj) then
        s = s & "IsEmpty = True"
    else
        if IsObject(vObj) then
            's = s & "Implementation = " & vObj.getImplementationName() & CHR$(10)   
            s = s & "IsObject = True" & CHR$(10)
        end if
        if IsUnoStruct(vObj) then s = s & "IsUnoStruct = True" & CHR$(10)
        if IsDate(vObj) then s = s & "IsDate = True" & CHR$(10)
        if IsNumeric(vObj) then s = s & "IsNumeric = True" & CHR$(10)
        if IsArray(vObj) then
            Dim i as integer
            s = s & "IsArray = True" & CHR$(10) & "size = " & ubound(vObj) & CHR$(10)
            for i = 0 to ubound(vObj)               
                s = s & vObj(i) & ", "
            next i
            s = s & ")" & CHR$(10)
        end if
    end if
    MsgBox s, 64, "Variable Info"
end sub

REM Affiche les propriétés détaillées d'un objet
sub ShowObjInfo(vObj as object)
    Dim s as string
    s = s & "Methodes : " & vObj.dbg_methods
    s = s & "Interfaces : " & vObj.dbg_supportedInterfaces
    s = s & "Propriétés : " & vObj.dbg_properties
    MsgBox s, 64, "Object Info"
end sub

REM  Exemple de test de type d'une variable
sub TypeTest
    Dim oSimpleFileAccess
    Dim aProperty as new com.sun.star.beans.Property
    Dim v as variant, o as object, s as string, a(4) as string
    MsgBox "Premier test", 64, "Type Test"
    ShowVarInfo(v)
    v=4
    ShowVarInfo(v)
    v=o
    ShowVarInfo(v)
    ShowVarInfo(o)
    ShowVarInfo(s)
    ShowVarInfo(a())
    a(0) = "tata"
    a(1) = "tete"
    a(2) = "titi"
    a(3) = "toto"
    a(4) = "tutu"
    ShowVarInfo(a())
    ShowVarInfo(aProperty)
    ShowObjInfo(aProperty)
    oSimpleFileAccess = CreateUnoService( "com.sun.star.ucb.SimpleFileAccess" )
    ShowVarInfo(oSimpleFileAccess)
    ShowObjInfo(oSimpleFileAccess)
end sub