×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • 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.

Students Click Here

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

Can an Array be passed to and from a Function?

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
'***********************************************************
Function AddLine(SomeArray() as string,SomeArrayCnt as integer,AddLine as string)
    Dim temp2(5000)
    if SomeArrayCnt > 0 then
        for x = 1 to SomeArrayCnt
            temp2(x) = SomeArray(x)       
        next
    end if
    temp2(SomeArrayCnt+1) = AddLine
    SomeArrayCnt = SomeArrayCnt + 1        
    redim SomeArray(SomeArrayCnt)
    for x = 1 to SomeArrayCnt
        SomeArray(x) = temp2(x)   
    next
    AddLine = SomeArray()
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)
Declare Function AddLineArray(strArray() As String)


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())
Call AddLineArray(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())
    if i <> lineAdd then
        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*
'************************************************************************

Function AddLineArray(strArray() As String)
Dim i As Integer
Dim AddTempArray(5000) As String

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

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

for i = LBound(strArray()) to UBound(strArray())
    strArray(i)=AddTempArray(i)
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.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

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:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close