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.
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]
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]
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.
Re: function and argument
Re: function and argument
Rate it if it helped you
Iouri Boutchkine
[email protected]
Re: function and argument
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 !
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.
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!
----------
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 !
Re: function and argument
Sorry ! i didnt understand !
i need more simple answer !
Thank you any way !