Valhalla Legends Forums Archive | Visual Basic Programming | Function as an array?

AuthorMessageTime
CrAz3D
I have a function that I'd like to have return info in an array.  Is this possible or should I seperate each item and then split the items when the function info is recieved?

Thanks

code might be something like...
[code]MsgBox UBound(GetInfo)
o][/code]
[code]function getinfo () as array?
ubound(getinfo)= hi
redim preserve getinfo(ubound(getinfo)+1)[/code]
February 2, 2005, 11:04 PM
Newby
[code]Public Function ReturnArr() As String()
    ReturnArr = Split("returns|an|array", "|")
End Function[/code]
February 2, 2005, 11:22 PM
CrAz3D
That semi-confuses me...

[code]function TheFunc() as string()
    TheFunc(1) = "hi"
    TheFunc(2) = "low"
end function


sub DoTheWork()
    Dim Arr() as string 
        Arr()=TheFunc
end sub[/code]

Would that work?
February 2, 2005, 11:29 PM
Newby
Don't know.

Go stick it in an empty project and call it, and fix it accordingly. :)
February 3, 2005, 12:27 AM
HdxBmx27
[code]Function TheFunc() As String()
Dim Arry(1) As String
    Arry(0) = "Low"
    Arry(1) = "High"
    TheFunc = Arry
End Function


Sub DoTheWork()
    MsgBox UBound(TheFunc)
End Sub[/code]
Its usually good pratice I think Not to use a function as a vareable...
The Above Code Works.
~-~(HDX)~-~
February 3, 2005, 12:38 AM
CrAz3D
Thanks HdxBmx27, that worked like a charm...?  :-*
February 3, 2005, 12:41 AM
HdxBmx27
Never call me by my full username -.- its annoying, Hdx, short, sweet, simple, my name over ALL my usernames, ever wonder why i have
|
V that? O and NP any other questions?
~-~(HDX)~-~
February 3, 2005, 12:47 AM
kamakazie
[quote author=HdxBmx27 link=topic=10405.msg97963#msg97963 date=1107391109]
[code]Function TheFunc() As String()
Dim Arry() As String
    ReDim Arry(0 To 1)
    Arry(0) = "Low"
    Arry(1) = "High"
    TheFunc = Arry
End Function


Sub DoTheWork()
    MsgBox UBound(TheFunc)
End Sub[/code]
Its usually good pratice I think Not to use a function as a vareable...
The Above Code Works.
~-~(HDX)~-~
[/quote]

Why not just Dim Arry(0 to 1) As String?
February 3, 2005, 1:56 AM
HdxBmx27
Um iono, laziy coding, But maby cuz I wanted him to be avle to delete the lines below that and do it for himself.. But ya, mostly cuz i wrote it without looking at what i was dooing 0.o
~-~(HDX)~-~
February 3, 2005, 2:17 AM
CrAz3D
Yeah, I just publicly declared an array, & then I redim it when needed.

Mucho thanks again HDX!
February 3, 2005, 4:35 AM
kamakazie
[quote author=CrAz3D link=topic=10405.msg98001#msg98001 date=1107405316]
Yeah, I just publicly declared an array, & then I redim it when needed.

Mucho thanks again HDX!
[/quote]

Sounds costly, albeit it is Visual Basic.
February 3, 2005, 5:12 AM
HdxBmx27
[quote author=dxoigmn link=topic=10405.msg98010#msg98010 date=1107407556]
Sounds costly, albeit it is Visual Basic.
[/quote]
True, I suggest that he simply has it a private Dim, jsut for that function so it dosent take up as much space, 0.o (MEM wise)
But ya it's vb, what cha gona do? And I cant learn C till Seinor year!!! and noone else but school is willing to teach>.<
~-~(HDX)~-~
February 3, 2005, 5:49 AM
CrAz3D
It wouldn't be more work/space required to keep re-declaring it EVERYTIME I need it? ( about 5-6 times so far )
February 3, 2005, 5:58 AM
UserLoser.
[quote author=CrAz3D link=topic=10405.msg98023#msg98023 date=1107410322]
It wouldn't be more work/space required to keep re-declaring it EVERYTIME I need it? ( about 5-6 times so far )
[/quote]

Maybe this variable should be static then
February 3, 2005, 6:16 AM
KkBlazekK
[code]Function TheFunc() As String()
    Static Arry(0 To 1) As String
    Arry(0) = "Low"
    Arry(1) = "High"
    TheFunc = Arry
End Function
[/code]
Like that? Wouldn't that still be wasting time by stating whats in the variable?
February 4, 2005, 12:29 AM

Search