|
-
June 21st, 2001, 06:49 AM
#1
function and argument
My problem:
I create an array of strings of an unknown size.
The size of the array varies according to user's acrion.
I want to send the array to a function which accepts as an argument a string.
( Public function MyFunction(strMyArrayOfStrins))
In the function i want to do some actions on that array but the function treats it as a string parameter, not an array.
How do i send, or how do i declare the function's argument so that the function will know that this is an array ?
Thank in advance !
-
June 21st, 2001, 07:01 AM
#2
Re: function and argument
option Explicit
private Sub Command1_Click()
Dim myarray() as string
Dim ret as string
ReDim myarray(10)
ret = fnctOfArray(myarray)
MsgBox ret
End Sub
private Function fnctOfArray(received() as string) as string
fnctOfArray = "There are " & UBound(received) + 1 & " elemet in the array"
End Function
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
June 21st, 2001, 07:07 AM
#3
Re: function and argument
Here is an example of the function that returns an array
Function that returns an array
New in VB6, functions can return arrays. For example:
' Return an array of strings.
Private Function NumberList() As String()
Dim arr() As String
Dim i As Integer
ReDim arr(1 To 10)
For i = 1 To 10
arr(i) = Format$(i) & " * " & Format$(i) & " = " & Format$(i * i)
Next i
NumberList = arr
End Function
The program could invoke this function as in:
Dim strings() As String
strings = NumberList()
This assignment may not work if the array is declared statically (using
explicit bounds) and the bounds do not match those of the array returned
by the function.
Iouri Boutchkine
[email protected]
-
June 21st, 2001, 07:09 AM
#4
Re: function and argument
Here is an example how to pass array as parameter
Dim aryTest(1 To 3)
Private Sub Command1_Click()
TestArray aryTest
TestArray
End Sub
Private Sub Form_Load()
aryTest(1) = 1
aryTest(2) = 2
aryTest(3) = 3
End Sub
Private Sub TestArray(Optional aryToTest)
If IsMissing(aryToTest) Then
MsgBox "Array Not Passed"
Else
For intCount = 1 To 3
strMessage = strMessage & "Element " & CStr(intCount) & " = " & CStr(aryToTest(intCount)) & vbLf
Next
MsgBox strMessage
End If
End Sub
Iouri Boutchkine
[email protected]
-
June 21st, 2001, 07:09 AM
#5
Re: And if you want send and receive back...
'send an array of string to a sub
'it is byref, so your changes will reflect on the original array:
option Explicit
private Sub Command1_Click()
Dim myarray() as string
ReDim myarray(10)
call subOfArray(myarray)
MsgBox myarray(0)
End Sub
private sub SubOfArray(received() as string)
received(0) = "There are " & UBound(received) + 1 & " elemet in the array"
End Sub
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
June 21st, 2001, 08:06 AM
#6
and thank you too !
Some more answers like this and i'll be a guru myself !
Thanx !
-
June 21st, 2001, 08:08 AM
#7
Re: function and argument
-
June 21st, 2001, 08:10 AM
#8
Re: function and argument
Rate it if it helped you
Iouri Boutchkine
[email protected]
-
June 21st, 2001, 08:10 AM
#9
Re: function and argument
-
June 21st, 2001, 08:14 AM
#10
No response from server !
I try to rate all the answers i got but i get an error message: No ersponse from server "!
I'll do it later. Your answer helped me and i'm gratefull to you !
-
June 21st, 2001, 08:25 AM
#11
Re: No response from server !
...Mmhm... do this: try again with Iouri. As soon as you see the server error, click on "back" button of your browser. Then refresh the page. I think you'll see the page again, but with your vote setted!

Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
June 21st, 2001, 08:27 AM
#12
Re: Ok, you managed it!
..and Now welcome to The_Raters Club (of which - of course -I am the President and which - of course - does not exist)
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
June 21st, 2001, 02:48 PM
#13
Re: function and argument
You can put a certain sign in the end of each string in the array before you make the "strings array-string". Chr(10) for example and that way you can always know when one string ends and another begins.
x2=InStr(x+1, str, Chr(10), vbBinaryCompare)-x
s1=mid$(str, x+1, x2 - 1)
x=x2+x
----------
The @host is everywhere!
----------
-
June 22nd, 2001, 05:50 AM
#14
Re: i didnt rate before pressing the button !
Thats why i recieved an error message.
i rated all 3 answers giving each one different rate. (the first one i read i gave 10, the second 6 and the third 3) is it ok ?
your (yours and iouri's) answers are important to me and i hope the rating is ok ! if not, please let me know so in the future i do better !
-
June 22nd, 2001, 05:53 AM
#15
Re: function and argument
Sorry ! i didnt understand !
i need more simple answer !
Thank you any way !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|