Hola,
estaba haciendo este proyecto y me puse de metano usar control de errores ya que quiero que mi programa pueda estar preparado ante cualquier defecto y aprender mas, asi que no quisiera tomar por opción forzar un error para saber si el array existe o no asi que tomé la segunda opción que fue como dijo seba123neo:
form:
If Not Es_Array(Imagenes) Then
Estado_1.Caption = "No se han localizado imagenes"
Exit Function
End If
Strings.bas:
Private Declare Function ArrPtr Lib "msvbvm60" Alias "VarPtr" (arr() As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
' .........
Public Function Es_Array(Array_data) As Boolean
Dim vValorMemoria As Long
CopyMemory vValorMemoria, ByVal VarPtr(Array_data) + 8, ByVal 4
CopyMemory vValorMemoria, ByVal vValorMemoria, ByVal 4
Es_Array = (vValorMemoria <> 0)
End Function
' ..........
Cuando lo hecho a correr me funciona bién la comprobación cuando si hay valor en el array pero cuando no hay valor el IDE de visual basic se cae lanzando el drwin y cerrandome la ventana.
Probaré la otra opción con copymemory
Private Sub Form_Load()
Dim ArrayPrueba() As String
Dim CadenaPrueba As String
CadenaPrueba = "hola,como,va"
If ((Not ArrayPrueba) = -1) Then
MsgBox "No esta Inicializado"
Else
MsgBox "Si esta Inicializado"
End If
ArrayPrueba = Split(CadenaPrueba, ",")
If ((Not ArrayPrueba) = -1) Then
MsgBox "No esta Inicializado"
Else
MsgBox "Si esta Inicializado"
End If
End Sub
Acá me dice que no coinciden los tipos pero es raro porque si le estoy enviando la variante
form:
Imagenes = Obtiene_imagenes(Text1.Text)
If Not Es_Array(Imagenes) Then
Estado_1.Caption = "No se han localizado imagenes"
Exit Function
End If
Archivos.bas:
Public Function Obtiene_archivos(Ruta_expreg As String) As String
Dim Archivo As String, temp As String
Archivo = Dir(Ruta_expreg)
While Archivo <> ""
Archivo = Dir
If Es_String(Archivo) Then
Obtiene_archivos = Obtiene_archivos & Archivo & ","
End If
Wend
End Function
Public Function Obtiene_imagenes(Ruta As String) As Variant
Dim Archivos As String, Imagenes As Variant, Cuenta As Integer, Buffer As String
' Obtiene el listado de imagenes con posibles extensiones
Archivos = _
Obtiene_archivos(Ruta & "*.jpg") & _
Obtiene_archivos(Ruta & "*.jpeg") & _
Obtiene_archivos(Ruta & "*.png") & _
Obtiene_archivos(Ruta & "*.gif")
' Separa en array
Imagenes = Split(Archivos, ",")
' Procesa una por una
For Cuenta = 0 To UBound(Imagenes) - 1
' Filtra imagenes de hasta 1.5 MB solamente
If FileLen(Ruta & Imagenes(Cuenta)) < 1500000 Then
Buffer = Buffer & Imagenes(Cuenta) & ","
End If
Next Cuenta
' Retorna solamente si hay imagenes válidas
If Es_String(Buffer) Then
Obtiene_imagenes = Split(Buffer, ",")
End If
End Function
Algo pasa que me está dando conflictos en los tipos