Si Array(x,y) vide ?

L

loukiki

Guest
Bonjour au forum,
J'ai un pb dont je ne trouve pas solution, alors je fais appel à vous :

Dans vba, je défini un tableau dont les valeurs peuvent etre vide ou numérique.
Il est déclaré comme Variant.

Comment peut on faire une boucle if then else, tel que par exemple :

if array(x,y) = vide then
ACTION 1
elseif array(x,y)=a then
ACTION 2
elseif array(x,y)=b then
ACTION 3
else
ACTION 4
end if

A noter que if array(x,y) = '' then ne fonctionne pas.

Merci par avance
Eric
 

ChTi160

XLDnaute Barbatruc
Salut louKiki

j'ai testé cela

Sub MyArray()
Dim MyArray()
Dim L As Byte

MyArray = Array('', 'A', 'B')

For L = 0 To UBound(MyArray)

Select Case MyArray(L)
Case Is = ''
Range('A1') = 'Qui'
Case Is = 'A'
Range('B1') = 'Non'
Case Is = 'B'
Range('C1') = 'Ou'
'Etc
End Select

Next L
End Sub

bonne Nuit

Message édité par: ChTi160, à: 29/07/2005 23:24
 

Hellboy

XLDnaute Accro
Bonsoir loukiki

C'est difficile de voir comme ça. Mais ton Array, c'est une fonction et nom une variable en passant. Sa fonction est de renvoyer un tableau. A ma connaissance, tu ne peux l'exploiter directement comme tableau.

Je te donne un exemple trèa ordinaire:

Public Sub Test_Array()
Dim MyArray() As Variant
Dim Item As Variant
MyArray() = Array(x, y)
If MyArray(1) = Empty Then
 
'Action
 
ElseIf MyArray(2) = Empy Then
'action
End If

' Ou encore
For Each Item In MyArray()
   
If Item = Empty Then
     
'
    Else
     
Select Case Item
             
Case 1
                 
'action
              Case 2
                 
'action
      End Select
   
End If
Next Item
   
End Sub

Message édité par: Hellboy, à: 29/07/2005 23:38
 

Discussions similaires

Statistiques des forums

Discussions
312 294
Messages
2 086 924
Membres
103 404
dernier inscrit
sultan87