Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: CrAz3D on February 02, 2005, 05:04 PM

Title: Function as an array?
Post by: CrAz3D on February 02, 2005, 05:04 PM
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...
MsgBox UBound(GetInfo)
o]

function getinfo () as array?
ubound(getinfo)= hi
redim preserve getinfo(ubound(getinfo)+1)
Title: Re: Function as an array?
Post by: Newby on February 02, 2005, 05:22 PM
Public Function ReturnArr() As String()
    ReturnArr = Split("returns|an|array", "|")
End Function
Title: Re: Function as an array?
Post by: CrAz3D on February 02, 2005, 05:29 PM
That semi-confuses me...

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


sub DoTheWork()
    Dim Arr() as string 
        Arr()=TheFunc
end sub


Would that work?
Title: Re: Function as an array?
Post by: Newby on February 02, 2005, 06:27 PM
Don't know.

Go stick it in an empty project and call it, and fix it accordingly. :)
Title: Re: Function as an array?
Post by: Hdx on February 02, 2005, 06:38 PM
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

Its usually good pratice I think Not to use a function as a vareable...
The Above Code Works.
~-~(HDX)~-~
Title: Re: Function as an array?
Post by: CrAz3D on February 02, 2005, 06:41 PM
Thanks HdxBmx27, that worked like a charm...?  :-*
Title: Re: Function as an array?
Post by: Hdx on February 02, 2005, 06:47 PM
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)~-~
Title: Re: Function as an array?
Post by: dxoigmn on February 02, 2005, 07:56 PM
Quote from: HdxBmx27 on February 02, 2005, 06:38 PM
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

Its usually good pratice I think Not to use a function as a vareable...
The Above Code Works.
~-~(HDX)~-~

Why not just Dim Arry(0 to 1) As String?
Title: Re: Function as an array?
Post by: Hdx on February 02, 2005, 08:17 PM
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)~-~
Title: Re: Function as an array?
Post by: CrAz3D on February 02, 2005, 10:35 PM
Yeah, I just publicly declared an array, & then I redim it when needed.

Mucho thanks again HDX!
Title: Re: Function as an array?
Post by: dxoigmn on February 02, 2005, 11:12 PM
Quote from: CrAz3D on February 02, 2005, 10:35 PM
Yeah, I just publicly declared an array, & then I redim it when needed.

Mucho thanks again HDX!

Sounds costly, albeit it is Visual Basic.
Title: Re: Function as an array?
Post by: Hdx on February 02, 2005, 11:49 PM
Quote from: dxoigmn on February 02, 2005, 11:12 PM
Sounds costly, albeit it is Visual Basic.
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)~-~
Title: Re: Function as an array?
Post by: CrAz3D on February 02, 2005, 11:58 PM
It wouldn't be more work/space required to keep re-declaring it EVERYTIME I need it? ( about 5-6 times so far )
Title: Re: Function as an array?
Post by: UserLoser. on February 03, 2005, 12:16 AM
Quote from: CrAz3D on February 02, 2005, 11:58 PM
It wouldn't be more work/space required to keep re-declaring it EVERYTIME I need it? ( about 5-6 times so far )

Maybe this variable should be static then
Title: Re: Function as an array?
Post by: Blaze on February 03, 2005, 06:29 PM
Function TheFunc() As String()
    Static Arry(0 To 1) As String
    Arry(0) = "Low"
    Arry(1) = "High"
    TheFunc = Arry
End Function

Like that? Wouldn't that still be wasting time by stating whats in the variable?