×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Can an Array be passed to and from a Function?2

## Can an Array be passed to and from a Function?

(OP)
I have been trying to pass an Array to function for the purpose of adding/removing a line from different Arrays.  Not sure if this is even possible in the manner I have been trying but here's the code I've been trying to get working.  Any help is greatly appreciated.

'***********************************************************
Function SubtractLine(SomeArray() as string,SomeArrayCnt as integer,RemoveLine as Integer)
Dim temp2(5000)
if SomeArrayCnt > 0 then
for x = 1 to RemoveLine - 1
temp2(x) = SomeArray(x)
next
for x = Removeline + 1 to SomeArrayCnt
Temp2(x) = SomeArray(x)
next
SomeArrayCnt = SomeArrayCnt - 1
end if
redim SomeArray(SomeArrayCnt)
for x = 1 to SomeArrayCnt
SomeArray(x) = temp2(x)
next
SubtractLine = SomeArray()
end function
'***********************************************************
Dim temp2(5000)
if SomeArrayCnt > 0 then
for x = 1 to SomeArrayCnt
temp2(x) = SomeArray(x)
next
end if
SomeArrayCnt = SomeArrayCnt + 1
redim SomeArray(SomeArrayCnt)
for x = 1 to SomeArrayCnt
SomeArray(x) = temp2(x)
next
end function
'***********************************************************

### RE: Can an Array be passed to and from a Function?

2
See if these functions will work for you! :)

Declare Function RemoveLineArray(strArray() As String,LineRemove As Integer)

Sub Main
Dim i As Integer
Dim strArray1() As String
ReDim strArray1(10) As String
For i = 0 to 10
strArray1(i) = "Array # " & i
Next i

msgbox "Size Before We Remove a line = "&UBound(strArray1())
Call RemoveLineArray(strArray1(),5)
msgbox "Size After We Remove a line = "&UBound(strArray1())

msgbox "Size Before We Add a line = "&UBound(strArray1())
msgbox "Size After We Add a line = "&UBound(strArray1())

End Sub

'************************************************************************
'* This function will remove any line from an array
*Use this "Call RemoveLineArray(yourarray(),whichline)" to remove line
'* This function is for all the Buck Buck people out there
'************************************************************************

Function RemoveLineArray(strArray() As String,LineRemove As Integer)
Dim i As Integer
Dim cnt As Integer
Dim newcnt As Integer
Dim RemoveTempArray(5000) As String
newcnt=UBound(strArray())-1
cnt=0
For i = LBound(strArray()) To UBound(strArray())
strArray(cnt)=strArray(i)
cnt=cnt+1
End if
Next i
cnt=cnt-1
for i = LBound(strArray()) to cnt
RemovetempArray(i) = strArray(i)
next i
ReDim strArray(newcnt) As String
for i = LBound(strArray()) to cnt
strArray(i) = RemovetempArray(i)
next i
End Function

'************************************************************************
'* This function will remove any line from an array                     *
'* Use this "Call AddLineArray(strArray1())" to Add a line at the bottom*
'************************************************************************

Dim i As Integer

For i = LBound(strArray()) To UBound(strArray())
Next i

ReDim strArray(UBound(strArray())+1) As string

for i = LBound(strArray()) to UBound(strArray())
next i
End Function

### RE: Can an Array be passed to and from a Function?

(OP)
I got the hang of it now thanks purp.  Perhaps we found our Forum ehh.

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!