Global/ public array problem
Hello guys, Im trying to develop a visualizer for a program that i have made before, i made some kind of searcher but one i get an array and try to use it in a different instance it shows an erres, i would appreciate any kind of help, thanks.
the error is when i try to use the array B() on the command 2 click, it says the subindex is out of the bound. any idea?
here's the code
Public num As Integer
Public tope As Integer
Public ruta As String
Public nactivo As String
Private Sub Command1_Click()
num = num + 1
If num >= tope Then
Command1.Enabled = False
Else
If (num >= 1 And num <= (tope - 1)) Then
Command1.Enabled = True
Command2.Enabled = True
End If
End If
Label2.Caption = num
End Sub
Public Sub Command2_Click()
num = num - 1
If num <= 0 Then
Command2.Enabled = False
Else
If (num >= 1 And num <= (tope - 1)) Then
Command1.Enabled = True
Command2.Enabled = True
End If
End If
Label2.Caption = num
OLE1.SourceDoc = ruta & "\" & nactivo & B(num)
OLE1.CreateEmbed ruta & "\" & nactivo & B(num)
OLE1.Update
End Sub
Public Sub Command3_Click()
Dim fso As New Scripting.FileSystemObject
Dim fld As Scripting.Folder
Dim fil As Scripting.File
Dim lngCount As Long
Dim count As Integer
Dim num As Integer
Dim A() As String
Dim arreglo(29) As String
Dim B() As String
arreglo(0) = "C:\SDOM\Caldera y auxiliares\aceite liviano"
arreglo(1) = "C:\SDOM\Caldera y auxiliares\Agua alimentacion"
arreglo(2) = "C:\SDOM\Caldera y auxiliares\Agua de circulacion"
arreglo(3) = "C:\SDOM\Caldera y auxiliares\Aire y gases de combustion"
arreglo(4) = "C:\SDOM\Caldera y auxiliares\Caldera"
arreglo(5) = "C:\SDOM\Caldera y auxiliares\Condensado principal"
arreglo(6) = "C:\SDOM\Caldera y auxiliares\Dosificador quimico"
arreglo(7) = "C:\SDOM\Caldera y auxiliares\Gas natural"
arreglo(8) = "C:\SDOM\Caldera y auxiliares\Manejo de ceniza"
arreglo(9) = "C:\SDOM\Caldera y auxiliares\Manejo y quemado de carbon"
arreglo(10) = "C:\SDOM\Caldera y auxiliares\Sopladores de hollin"
arreglo(11) = "C:\SDOM\Caldera y auxiliares\Tratamiento de agua"
arreglo(12) = "C:\SDOM\Caldera y auxiliares\Vapor auxiliar"
'-----
arreglo(13) = "C:\SDOM\Miscelaneos y auxiliares\Control automatico planta"
arreglo(14) = "C:\SDOM\Miscelaneos y auxiliares\Control ambiental"
arreglo(15) = "C:\SDOM\Miscelaneos y auxiliares\Comunicaciones planta"
arreglo(16) = "C:\SDOM\Miscelaneos y auxiliares\Drenaje planta"
arreglo(17) = "C:\SDOM\Miscelaneos y auxiliares\Agua enfriamiento cojinetes"
arreglo(18) = "C:\SDOM\Miscelaneos y auxiliares\Agua y servicio de agua potable"
arreglo(19) = "C:\SDOM\Miscelaneos y auxiliares\Aire comprimido e instrumentos"
arreglo(20) = "C:\SDOM\Miscelaneos y auxiliares\Alumbrado"
arreglo(21) = "C:\SDOM\Miscelaneos y auxiliares\Contraincendio"
arreglo(22) = "C:\SDOM\Miscelaneos y auxiliares\Edificio y vias"
arreglo(23) = "C:\SDOM\Miscelaneos y auxiliares\Equipos y herramientas talleres"
arreglo(24) = "C:\SDOM\Miscelaneos y auxiliares\Transporte carga"
'-----
arreglo(25) = "C:\SDOM\Turbogenerador y auxiliares\Bypass alta y baja presion"
arreglo(26) = "C:\SDOM\Turbogenerador y auxiliares\Generador"
arreglo(27) = "C:\SDOM\Turbogenerador y auxiliares\Potencia electrica"
arreglo(28) = "C:\SDOM\Turbogenerador y auxiliares\Turbina"
arreglo(29) = "C:\SDOM\Turbogenerador y auxiliares\Vapor sello y vacio condensador"
Dim numactivo() As Integer
count = 0
sal = 0
lngCount = 0
For i = 0 To 29
Set fld = fso.GetFolder(arreglo(i))
For Each fil In fld.Files
count = count + 1
ReDim A(count)
A(count) = fil.Name
nactivo = Left(A(count), 6)
auxnombre = fso.GetFileName(fil.Path)
auxnombre2 = Left(auxnombre, 6)
If auxnombre2 = text1.Text Then
lngCount = lngCount + 1
ReDim B(lngCount)
aux7 = Len(A(count))
aux8 = aux7 - 6
aux9 = Right(A(count), aux8)
B(lngCount) = aux9
MsgBox B(lngCount)
tope = lngCount
End If
If nactivo = text1.Text Then
ruta = arreglo(i)
numarchivos = lngCount
Archivo = A(count)
End If
'MsgBox A(count)
Next fil
Next i
MsgBox numarchivos
MsgBox ruta
Set fil = Nothing
Set fld = Nothing
Set fso = Nothing
MsgBox lngCount
num = count
OLE1.SourceDoc = ruta & "\" & Archivo
OLE1.CreateEmbed ruta & "\" & Archivo
OLE1.Update
End Sub
Re: Global/ public array problem
Is your "Public" Variables, such as arreglo(), in a module? If it's in a form it will not be public to other forms. If you put into a Class OR Module, then it will be Public.
You could also use Property Set/Let/Get.
Code:
'Quick Example of a Property
Private Property Set MyPropertyName(Arg As String)
'Code
End Property
Re: Global/ public array problem
Arrays A and B are only in scope in the Command3_Click event, they should be declared in the Form's Declaration section as opposed to in the Command3_Click event.
BTW Where you are ReDim'ing A and B I think you need to use 'ReDim Preserve'
Re: Global/ public array problem
Hi guys and thanks for replying,
i have created a Module to declre my public variables, but i still have trouble declaring the array B
Public num As Integer
Public tope As Integer
Public ruta As String
Public nactivo As String
Public lngcount As Integer
Public B() As Integer
that is inside a module
But i am still uncapable of using the variable B created in command click3 in the command click 2 event. please help me out.
here's the code with the corrections.
Private Sub Command1_Click()
num = num + 1
If num >= tope Then
Command1.Enabled = False
Else
If (num >= 1 And num <= (tope - 1)) Then
Command1.Enabled = True
Command2.Enabled = True
End If
End If
Label2.Caption = num
End Sub
Private Sub Command2_Click()
num = num - 1
If num <= 0 Then
Command2.Enabled = False
Else
If (num >= 1 And num <= (tope - 1)) Then
Command1.Enabled = True
Command2.Enabled = True
End If
End If
Label2.Caption = num
OLE1.SourceDoc = ruta & "\" & nactivo & B(1)
OLE1.CreateEmbed ruta & "\" & nactivo & B(1)
OLE1.Update
End Sub
Private Sub Command3_Click()
Dim fso As New Scripting.FileSystemObject
Dim fld As Scripting.Folder
Dim fil As Scripting.File
Dim lngcount As Long
Dim count As Integer
Dim num As Integer
Dim A() As String
Dim arreglo(29) As String
Dim B() As String
arreglo(0) = "C:\SDOM\Caldera y auxiliares\aceite liviano"
arreglo(1) = "C:\SDOM\Caldera y auxiliares\Agua alimentacion"
arreglo(2) = "C:\SDOM\Caldera y auxiliares\Agua de circulacion"
arreglo(3) = "C:\SDOM\Caldera y auxiliares\Aire y gases de combustion"
arreglo(4) = "C:\SDOM\Caldera y auxiliares\Caldera"
arreglo(5) = "C:\SDOM\Caldera y auxiliares\Condensado principal"
arreglo(6) = "C:\SDOM\Caldera y auxiliares\Dosificador quimico"
arreglo(7) = "C:\SDOM\Caldera y auxiliares\Gas natural"
arreglo(8) = "C:\SDOM\Caldera y auxiliares\Manejo de ceniza"
arreglo(9) = "C:\SDOM\Caldera y auxiliares\Manejo y quemado de carbon"
arreglo(10) = "C:\SDOM\Caldera y auxiliares\Sopladores de hollin"
arreglo(11) = "C:\SDOM\Caldera y auxiliares\Tratamiento de agua"
arreglo(12) = "C:\SDOM\Caldera y auxiliares\Vapor auxiliar"
'-----
arreglo(13) = "C:\SDOM\Miscelaneos y auxiliares\Control automatico planta"
arreglo(14) = "C:\SDOM\Miscelaneos y auxiliares\Control ambiental"
arreglo(15) = "C:\SDOM\Miscelaneos y auxiliares\Comunicaciones planta"
arreglo(16) = "C:\SDOM\Miscelaneos y auxiliares\Drenaje planta"
arreglo(17) = "C:\SDOM\Miscelaneos y auxiliares\Agua enfriamiento cojinetes"
arreglo(18) = "C:\SDOM\Miscelaneos y auxiliares\Agua y servicio de agua potable"
arreglo(19) = "C:\SDOM\Miscelaneos y auxiliares\Aire comprimido e instrumentos"
arreglo(20) = "C:\SDOM\Miscelaneos y auxiliares\Alumbrado"
arreglo(21) = "C:\SDOM\Miscelaneos y auxiliares\Contraincendio"
arreglo(22) = "C:\SDOM\Miscelaneos y auxiliares\Edificio y vias"
arreglo(23) = "C:\SDOM\Miscelaneos y auxiliares\Equipos y herramientas talleres"
arreglo(24) = "C:\SDOM\Miscelaneos y auxiliares\Transporte carga"
'-----
arreglo(25) = "C:\SDOM\Turbogenerador y auxiliares\Bypass alta y baja presion"
arreglo(26) = "C:\SDOM\Turbogenerador y auxiliares\Generador"
arreglo(27) = "C:\SDOM\Turbogenerador y auxiliares\Potencia electrica"
arreglo(28) = "C:\SDOM\Turbogenerador y auxiliares\Turbina"
arreglo(29) = "C:\SDOM\Turbogenerador y auxiliares\Vapor sello y vacio condensador"
Dim numactivo() As Integer
count = 0
sal = 0
lngcount = 0
For i = 0 To 29
Set fld = fso.GetFolder(arreglo(i))
For Each fil In fld.Files
count = count + 1
ReDim Preserve A(count)
A(count) = fil.Name
nactivo = Left(A(count), 6)
auxnombre = fso.GetFileName(fil.Path)
auxnombre2 = Left(auxnombre, 6)
If auxnombre2 = text1.Text Then
lngcount = lngcount + 1
ReDim Preserve B(lngcount)
aux7 = Len(A(count))
aux8 = aux7 - 6
aux9 = Right(A(count), aux8)
B(lngcount) = aux9
MsgBox B(lngcount)
tope = lngcount
End If
If nactivo = text1.Text Then
ruta = arreglo(i)
numarchivos = lngcount
Archivo = A(count)
End If
'MsgBox A(count)
Next fil
Next i
MsgBox numarchivos
MsgBox ruta
Set fil = Nothing
Set fld = Nothing
Set fso = Nothing
MsgBox lngcount
num = count
OLE1.SourceDoc = ruta & "\" & Archivo
OLE1.CreateEmbed ruta & "\" & Archivo
OLE1.Update
End Sub
Re: Global/ public array problem
You must remove the declaration of Array B in the Command3_Click code.
Re: Global/ public array problem
WOW! Thanks a lot Doogle!!!, Now it is working i really apreciate your help!!!!:)
Thaaaank you!!!!!!!