help needed to debug this VBA program

help needed to debug this VBA program

Anonymous
Not applicable
488 Views
9 Replies
Message 1 of 10

help needed to debug this VBA program

Anonymous
Not applicable
Hi All,

I am new to VBA and I have been stuck wid this.Can someone please help.

Public Function GetArray(ByRef pFileArray As Variant) As Boolean
Me.Show
For Each i In sFileArray
pFileArray(i) = sFileArray(i + 1) 'assigning the values in sFileArray to pFileArray
Next
GetArray = mbool
End Function

At the loop it says that i is not initialized.Before the 'For' ...The Me.Show navigates to the form and takes all the input I need.when it comes back it does not recognize variable i.
Can u please tell me how to make that function recognize 'i'
Any help will be appreciated.

Thanks
Avantika
0 Likes
489 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable
typically you would use something like

For i = 0 to

Next i

wrote in message news:5210809@discussion.autodesk.com...
Hi All,

I am new to VBA and I have been stuck wid this.Can someone please help.

Public Function GetArray(ByRef pFileArray As Variant) As Boolean
Me.Show
For Each i In sFileArray
pFileArray(i) = sFileArray(i + 1) 'assigning the values in sFileArray to
pFileArray
Next
GetArray = mbool
End Function

At the loop it says that i is not initialized.Before the 'For' ...The
Me.Show navigates to the form and takes all the input I need.when it comes
back it does not recognize variable i.
Can u please tell me how to make that function recognize 'i'
Any help will be appreciated.

Thanks
Avantika
0 Likes
Message 3 of 10

Anonymous
Not applicable
don't you need this..

dim i as interger

right at the start????
0 Likes
Message 4 of 10

Anonymous
Not applicable
For i = Lbound(sFileArray) to Ubound(sFileArray)-1
pFileArray(i) = sFileArray(i + 1)
Next i

--
Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica

wrote in message news:5210809@discussion.autodesk.com...
Hi All,

I am new to VBA and I have been stuck wid this.Can someone please help.

Public Function GetArray(ByRef pFileArray As Variant) As Boolean
Me.Show
For Each i In sFileArray
pFileArray(i) = sFileArray(i + 1) 'assigning the values in sFileArray to
pFileArray
Next
GetArray = mbool
End Function

At the loop it says that i is not initialized.Before the 'For' ...The
Me.Show navigates to the form and takes all the input I need.when it comes
back it does not recognize variable i.
Can u please tell me how to make that function recognize 'i'
Any help will be appreciated.

Thanks
Avantika
0 Likes
Message 5 of 10

Anonymous
Not applicable
It depends on whther they have the option Explicit at the top of the mdule.


"C Witt" wrote in message
news:5211397@discussion.autodesk.com...
don't you need this..

dim i as interger

right at the start????
0 Likes
Message 6 of 10

Anonymous
Not applicable
"It depends on whther they have the option Explicit at the top of the
module."

yea, and that is what i think he has.. (given his original comment of
vba not recognizing the "i" variable)
0 Likes
Message 7 of 10

Anonymous
Not applicable
I believe "i" should be declared as a Variant
or the For Each statement will fail when used
on an array.

--
Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica


"C Witt" wrote in message
news:5212234@discussion.autodesk.com...
"It depends on whther they have the option Explicit at the top of the
module."

yea, and that is what i think he has.. (given his original comment of
vba not recognizing the "i" variable)
0 Likes
Message 8 of 10

Anonymous
Not applicable
what for each? per your example post

For i = Lbound(sFileArray) to Ubound(sFileArray)-1
pFileArray(i) = sFileArray(i + 1)
Next i

i could be an integer or long wo problem but i dont use variant for index
value.


"Jorge Jimenez" wrote in message
news:5212614@discussion.autodesk.com...
I believe "i" should be declared as a Variant
or the For Each statement will fail when used
on an array.

--
Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica


"C Witt" wrote in message
news:5212234@discussion.autodesk.com...
"It depends on whther they have the option Explicit at the top of the
module."

yea, and that is what i think he has.. (given his original comment of
vba not recognizing the "i" variable)
0 Likes
Message 9 of 10

Anonymous
Not applicable
> what for each? per your example post

Sorry, I was reffering to the OP's problem
and sample code he posted.

What I posted was another way of doing it
but if he wants to use a For Each on an array
he must declare the variable as a Variant

--
Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica


"Ben Stone" wrote in message
news:5212874@discussion.autodesk.com...
what for each? per your example post

For i = Lbound(sFileArray) to Ubound(sFileArray)-1
pFileArray(i) = sFileArray(i + 1)
Next i

i could be an integer or long wo problem but i dont use variant for index
value.


"Jorge Jimenez" wrote in message
news:5212614@discussion.autodesk.com...
I believe "i" should be declared as a Variant
or the For Each statement will fail when used
on an array.

--
Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica


"C Witt" wrote in message
news:5212234@discussion.autodesk.com...
"It depends on whther they have the option Explicit at the top of the
module."

yea, and that is what i think he has.. (given his original comment of
vba not recognizing the "i" variable)
0 Likes
Message 10 of 10

Anonymous
Not applicable
sorry didnt see the other post you made, ok yes thats true

"Jorge Jimenez" wrote in message
news:5212882@discussion.autodesk.com...
> what for each? per your example post

Sorry, I was reffering to the OP's problem
and sample code he posted.

What I posted was another way of doing it
but if he wants to use a For Each on an array
he must declare the variable as a Variant

--
Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica


"Ben Stone" wrote in message
news:5212874@discussion.autodesk.com...
what for each? per your example post

For i = Lbound(sFileArray) to Ubound(sFileArray)-1
pFileArray(i) = sFileArray(i + 1)
Next i

i could be an integer or long wo problem but i dont use variant for index
value.


"Jorge Jimenez" wrote in message
news:5212614@discussion.autodesk.com...
I believe "i" should be declared as a Variant
or the For Each statement will fail when used
on an array.

--
Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica


"C Witt" wrote in message
news:5212234@discussion.autodesk.com...
"It depends on whther they have the option Explicit at the top of the
module."

yea, and that is what i think he has.. (given his original comment of
vba not recognizing the "i" variable)
0 Likes