Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

IknowMe

Programmer
Aug 6, 2004
1,214
US
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
'***********************************************************
 
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
 
I got the hang of it now thanks purp. Perhaps we found our Forum ehh.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top