returning multiple values from one function

M

muyBN

(My first post may not have gone through according a web page error message I
received so I'm writing this again just in case. If two show up, please
answer the other one, not this.)

I know that functions are generally made to return one value but I know that
there are also ways to return multiple values with arrays or objects and dot
notation. However, from the few examples I've seen on the Web I haven't
understood completely how to accomplish it. I'm hoping that someone can help
me if I write what I'm trying to accomplish using snippets of my code.

Sub umSaveDocName(strGradingDoc as String, strNewFile As String)
'need more details here; this is a guess
strGradingDoc = umGetTargetFileInfo.File1Info
strNewFile = umGetTargetFileInfo.File2Info
End Sub

Function umGetTargetFileInfo(File1Info as String, File2Info as String) as
Variant
'need more details here; this is a guess
umGetTargetFileInfo(File1Info, File2Info)
End Function
 
J

Jezebel

There are three ways to return multiple values from a function ---

1. Setting the arguments:

Sub MyFunc(Arg1, Arg2, Arg3)
Arg1 = 1
Arg2 = 2
Arg3 = 3
End Sub

Note that the arguments have to be passed ByRef (which is the default
anyway), not ByVal. There is a style of programming where *all* return
values are handled like this; every function returns only true or false
indicating error status.

2. Returning an array:

Function MyFunc() as String()
Dim localArray(1 to 3) as string

localArray(1) = 1
MyFunc = localArray
End Function

3. Returning a user-defined type:

Type FileDataType
Name as string
Public as boolean
End Type

Function MyFunc() as FileDataType
Dim localFDT as FileDataType

localFDT.Name = "LKJ"
localFDT.Public = TRUE

MyFunc = localFDT
End Function

Don't understand your code snippets.
 
G

Greg Maxey

Hmm...and I don't understand yours. Can you further explain using your
examples how you would a) querry the function from a calling macro b) how
you get the multiple result backt. I mean in this example a function
returns one valube (i.e., the sum of A and B):

Sub MainMacro()



Dim MyResult As Double

Dim A As Double

Dim B As Double

A = CDbl(InputBox("Enter value:", "A"))

B = CDbl(InputBox("Enter value:", "B"))

MyResult = BasicAddition(A, B)

MsgBox MyResult

End Sub



Function BasicAddition(A As Double, B As Double) As Double

BasicAddition = A + B

End Function
 
H

Helmut Weber

Hi Greg,

this is another academic exercise, IMHO.
A function should return _one_ value by definition.

This _one_ value might be an array or a type.

It could even be an array of arrays.
Still, it would be, well, kind of, _one_ value.

I think, there are limits to programming.

I never understood how a program could work,
after a code line like this:
x = Sqr(9)

as there are two solutions: +3, -3.

Yet the program would continue with +3 only.

As you are diving deeper and deeper,
you may soon reach the ground,
and programming Word wouldn't be a challenge anymore.

Then it comes to mathematics.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
G

Greg Maxey

Hi Helmut,
As you are diving deeper and deeper, you may soon reach the ground,
and programming Word wouldn't be a challenge anymore.

I am in mighty deep water and I am afraid my pressure hull will rupture
before I hit bottom. ;-)

I was really perplexed by Jezebels reply. I mean:

Sub MyFunc(Arg1, Arg2, Arg3)
Arg1 = 1
Arg2 = 2
Arg3 = 3
End Sub

Doesn't appear to be a function at all.

I was able to see how:

Option Explicit
Type FileDataType
Name As String
Public As Boolean
End Type
Sub CallFunc()
MsgBox MyFunc.Name & " " & MyFunc.Public
End Sub
Function MyFunc() As FileDataType
Dim localFDT As FileDataType
localFDT.Name = "LKJ"
localFDT.Public = True
MyFunc = localFDT
End Function

Appears to return two values, but in stepping through the code it runs
through the function twice. I also fail to see a practical use for it.

This one is completely over my head:

Function MyFunc() as String()
Dim localArray(1 to 3) as string

localArray(1) = 1
MyFunc = localArray
End Function

I would like to see an example of what you would get from it and how you
would get it.

BTW, did you get my e-mail response wrt to the donation received?
 
G

Greg Maxey

Helmut,

I was able to construct a call for the array example:

Sub CallTest()
Dim a As Variant
Dim i As Long
a = MyFunct
For i = 1 To UBound(a)
MsgBox a(i)
Next i
End Sub
Function MyFunct() As String()
Dim localArray(1 To 3) As String
localArray(1) = 1
localArray(2) = 2
localArray(3) = 3
MyFunct = localArray
End Function
 
J

Jezebel

Sub MyFunc(Arg1, Arg2, Arg3)
Arg1 = 1
Arg2 = 2
Arg3 = 3
End Sub
All I was getting at with this is that MyFunc sets all three argument
values. As it stands, no of course it's not much of a function. Consider a
function that takes an array of values as argument, and returns a set of
values calculated from that array (Excel has statistics and financial
functions that do exactly this sort of thing) --

Sub StatsData(ArgArray(), Total, Mean, StandardDeviation)

For i = lbound(ArgArray) to ubound(ArgArray)
Total = Total + ArgArray(i)
Next
Mean = Total / (Ubound(ArgArray) - LBound(ArgArray) + 1)
StandardDeviation = ... [whatever the formula is]

End Sub
 
H

Helmut Weber

Hi Greg,
BTW, did you get my e-mail response wrt to the donation received?

got it. Feels good. :)
Sub MyFunc(Arg1, Arg2, Arg3)
Arg1 = 1
Arg2 = 2
Arg3 = 3
End Sub

Doesn't appear to be a function at all.
Right.

but in stepping through the code it runs through the function twice.
Yes.

MsgBox MyFunc.Name & " " & MyFunc.Public

Once for each occurance of "MyFunc" in the code line.
I also fail to see a practical use for it.

So do I.
This one is completely over my head:

Function MyFunc() as String()
Dim localArray(1 to 3) as string

localArray(1) = 1
MyFunc = localArray
End Function

What Jezebel intended was:

Function MyFunc() as String()
Dim localArray(1 to 3) as string
localArray(1) = "1"
localArray(2) = "2"
localArray(3) = "3"
MyFunc = localArray
End Function

'---------------------------

Have a nice day.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
G

Greg Maxey

Jezebel,

I concede, as I have many times before, that you have a grasp of VBA that I
will likely never match.

This looks brillant:

Sub StatsData(ArgArray(), Total, Mean, StandardDeviation)

For i = lbound(ArgArray) to ubound(ArgArray)
Total = Total + ArgArray(i)
Next
Mean = Total / (Ubound(ArgArray) - LBound(ArgArray) + 1)
StandardDeviation = ... [whatever the formula is]
End Sub

But it is a locked door as I can't step through it with F8 to see what it
will do.

If this is a *Function* why does it start with *Sub*?

I would love to learn to fish, but I need more bait, a pole, a hook, a
*key,* whatever to get past GO. Can you show me something complete that I
can step through to perhaps grasp what it is that you want to teach?

You have been posting in these groups for a long time. You have a lot to
offer budding VBA enthusiast. Would you consider making your true identity
known to some of us? You know how to contact me off line and I would like
to do contact you offline from time to time for technical explanations.

Here's hoping you take the bait ;-)

--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
Sub MyFunc(Arg1, Arg2, Arg3)
Arg1 = 1
Arg2 = 2
Arg3 = 3
End Sub
All I was getting at with this is that MyFunc sets all three argument
values. As it stands, no of course it's not much of a function.
Consider a function that takes an array of values as argument, and
returns a set of values calculated from that array (Excel has
statistics and financial functions that do exactly this sort of
thing) --

Sub StatsData(ArgArray(), Total, Mean, StandardDeviation)

For i = lbound(ArgArray) to ubound(ArgArray)
Total = Total + ArgArray(i)
Next
Mean = Total / (Ubound(ArgArray) - LBound(ArgArray) + 1)
StandardDeviation = ... [whatever the formula is]

End Sub
 
J

Jezebel

Hi Greg

Sorry about sub/function ambiguity. You're quite right that this is a sub,
not a function; 'function' is a generic term referring to all such
constructions (as you'll find in the literature). In some languages, every
'function' returns *something*, even if it's nothing or 'void' as in Java; a
sub is just a special case where the return value is discarded
automatically.

As it stands, you can't step through the code because it's just indicative
of how to do it: you'd need to declare the variables, etc, to make it work.

And specifically for the purpose of calculating means and standard
deviations you might, if you were really keen, dig out Donald Knuth's
classic volume on functions and algorithms where he explains the effects of
rounding error on the root-mean-square formula. If you use the textbook
standard deviation formula you can end up trying to get the square root of a
negative number.

I'll consider (sympathetically) your offline suggestion. My ISP went broke
last week so I have no email for a few days, until I can shift my website to
a new provider.

Cheers



Greg Maxey said:
Jezebel,

I concede, as I have many times before, that you have a grasp of VBA that
I will likely never match.

This looks brillant:

Sub StatsData(ArgArray(), Total, Mean, StandardDeviation)

For i = lbound(ArgArray) to ubound(ArgArray)
Total = Total + ArgArray(i)
Next
Mean = Total / (Ubound(ArgArray) - LBound(ArgArray) + 1)
StandardDeviation = ... [whatever the formula is]
End Sub

But it is a locked door as I can't step through it with F8 to see what it
will do.

If this is a *Function* why does it start with *Sub*?

I would love to learn to fish, but I need more bait, a pole, a hook, a
*key,* whatever to get past GO. Can you show me something complete that I
can step through to perhaps grasp what it is that you want to teach?

You have been posting in these groups for a long time. You have a lot to
offer budding VBA enthusiast. Would you consider making your true
identity known to some of us? You know how to contact me off line and I
would like to do contact you offline from time to time for technical
explanations.

Here's hoping you take the bait ;-)

--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
Sub MyFunc(Arg1, Arg2, Arg3)
Arg1 = 1
Arg2 = 2
Arg3 = 3
End Sub
All I was getting at with this is that MyFunc sets all three argument
values. As it stands, no of course it's not much of a function.
Consider a function that takes an array of values as argument, and
returns a set of values calculated from that array (Excel has
statistics and financial functions that do exactly this sort of
thing) --

Sub StatsData(ArgArray(), Total, Mean, StandardDeviation)

For i = lbound(ArgArray) to ubound(ArgArray)
Total = Total + ArgArray(i)
Next
Mean = Total / (Ubound(ArgArray) - LBound(ArgArray) + 1)
StandardDeviation = ... [whatever the formula is]

End Sub
 
G

Greg Maxey

Jezebel,

*Cheers!* The warmest expression to date. Hey World!, the ice water that
reportedly flows through this man's (of that I am convinced) veins has been
subject to global warming! ;-)

Just kidding (reluctantly).

I don't know if I am so keen as to start digging through tombs of classical
text for the answer to questions pursued simply as a intellectual hobby.
Truth be told, I am a borderline old man that could log off the PC tomorrow
and never look back. If I have to wiggle through a knot hole backwards for
an answer that I life doesn't depend on, I may just fold. Hope you
understand?

Anticipating the restoration of your e-mail and offline contact.

Cheers.

--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

Hi Greg

Sorry about sub/function ambiguity. You're quite right that this is a
sub, not a function; 'function' is a generic term referring to all
such constructions (as you'll find in the literature). In some
languages, every 'function' returns *something*, even if it's nothing
or 'void' as in Java; a sub is just a special case where the return
value is discarded automatically.

As it stands, you can't step through the code because it's just
indicative of how to do it: you'd need to declare the variables, etc,
to make it work.
And specifically for the purpose of calculating means and standard
deviations you might, if you were really keen, dig out Donald Knuth's
classic volume on functions and algorithms where he explains the
effects of rounding error on the root-mean-square formula. If you use
the textbook standard deviation formula you can end up trying to get
the square root of a negative number.

I'll consider (sympathetically) your offline suggestion. My ISP went
broke last week so I have no email for a few days, until I can shift
my website to a new provider.

Cheers



Greg Maxey said:
Jezebel,

I concede, as I have many times before, that you have a grasp of VBA
that I will likely never match.

This looks brillant:

Sub StatsData(ArgArray(), Total, Mean, StandardDeviation)

For i = lbound(ArgArray) to ubound(ArgArray)
Total = Total + ArgArray(i)
Next
Mean = Total / (Ubound(ArgArray) - LBound(ArgArray) + 1)
StandardDeviation = ... [whatever the formula is]
End Sub

But it is a locked door as I can't step through it with F8 to see
what it will do.

If this is a *Function* why does it start with *Sub*?

I would love to learn to fish, but I need more bait, a pole, a hook,
a *key,* whatever to get past GO. Can you show me something
complete that I can step through to perhaps grasp what it is that
you want to teach? You have been posting in these groups for a long time.
You have a
lot to offer budding VBA enthusiast. Would you consider making your
true identity known to some of us? You know how to contact me off
line and I would like to do contact you offline from time to time
for technical explanations.

Here's hoping you take the bait ;-)

--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
Sub MyFunc(Arg1, Arg2, Arg3)
Arg1 = 1
Arg2 = 2
Arg3 = 3
End Sub


All I was getting at with this is that MyFunc sets all three
argument values. As it stands, no of course it's not much of a
function. Consider a function that takes an array of values as
argument, and returns a set of values calculated from that array
(Excel has statistics and financial functions that do exactly this
sort of thing) --

Sub StatsData(ArgArray(), Total, Mean, StandardDeviation)

For i = lbound(ArgArray) to ubound(ArgArray)
Total = Total + ArgArray(i)
Next
Mean = Total / (Ubound(ArgArray) - LBound(ArgArray) + 1)
StandardDeviation = ... [whatever the formula is]

End Sub
 
J

Jezebel

Just opened a new bottle of medications (a nice vintage medication at that).

Knuth is probably not worth reading as an aid to programming (it's *way* out
of date for that); but the theory is still valid, and he's an old-school
academic of the charm-and-wit, eminently readable style. CP Snow, where are
you now that we need you!?



Greg Maxey said:
Jezebel,

*Cheers!* The warmest expression to date. Hey World!, the ice water that
reportedly flows through this man's (of that I am convinced) veins has
been subject to global warming! ;-)

Just kidding (reluctantly).

I don't know if I am so keen as to start digging through tombs of
classical text for the answer to questions pursued simply as a
intellectual hobby. Truth be told, I am a borderline old man that could
log off the PC tomorrow and never look back. If I have to wiggle through
a knot hole backwards for an answer that I life doesn't depend on, I may
just fold. Hope you understand?

Anticipating the restoration of your e-mail and offline contact.

Cheers.

--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

Hi Greg

Sorry about sub/function ambiguity. You're quite right that this is a
sub, not a function; 'function' is a generic term referring to all
such constructions (as you'll find in the literature). In some
languages, every 'function' returns *something*, even if it's nothing
or 'void' as in Java; a sub is just a special case where the return
value is discarded automatically.

As it stands, you can't step through the code because it's just
indicative of how to do it: you'd need to declare the variables, etc,
to make it work.
And specifically for the purpose of calculating means and standard
deviations you might, if you were really keen, dig out Donald Knuth's
classic volume on functions and algorithms where he explains the
effects of rounding error on the root-mean-square formula. If you use
the textbook standard deviation formula you can end up trying to get
the square root of a negative number.

I'll consider (sympathetically) your offline suggestion. My ISP went
broke last week so I have no email for a few days, until I can shift
my website to a new provider.

Cheers



Greg Maxey said:
Jezebel,

I concede, as I have many times before, that you have a grasp of VBA
that I will likely never match.

This looks brillant:

Sub StatsData(ArgArray(), Total, Mean, StandardDeviation)

For i = lbound(ArgArray) to ubound(ArgArray)
Total = Total + ArgArray(i)
Next
Mean = Total / (Ubound(ArgArray) - LBound(ArgArray) + 1)
StandardDeviation = ... [whatever the formula is]
End Sub

But it is a locked door as I can't step through it with F8 to see
what it will do.

If this is a *Function* why does it start with *Sub*?

I would love to learn to fish, but I need more bait, a pole, a hook,
a *key,* whatever to get past GO. Can you show me something
complete that I can step through to perhaps grasp what it is that
you want to teach? You have been posting in these groups for a long
time. You have a
lot to offer budding VBA enthusiast. Would you consider making your
true identity known to some of us? You know how to contact me off
line and I would like to do contact you offline from time to time
for technical explanations.

Here's hoping you take the bait ;-)

--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

Jezebel wrote:
Sub MyFunc(Arg1, Arg2, Arg3)
Arg1 = 1
Arg2 = 2
Arg3 = 3
End Sub


All I was getting at with this is that MyFunc sets all three
argument values. As it stands, no of course it's not much of a
function. Consider a function that takes an array of values as
argument, and returns a set of values calculated from that array
(Excel has statistics and financial functions that do exactly this
sort of thing) --

Sub StatsData(ArgArray(), Total, Mean, StandardDeviation)

For i = lbound(ArgArray) to ubound(ArgArray)
Total = Total + ArgArray(i)
Next
Mean = Total / (Ubound(ArgArray) - LBound(ArgArray) + 1)
StandardDeviation = ... [whatever the formula is]

End Sub
 
J

Jay Freedman

Hi Greg,

I see that you got the first method working.

The second method will only call the function once if you change the
calling function to this:

Sub CallFunc()
Dim result As FileDataType
result = MyFunc()
MsgBox result.Name & " " & result.Public
End Sub

This is a general recommendation -- when a function does two or more
things, declare a variable to hold the return value and call the
function just once, then extract the pieces of the return value from
the temporary variable. This is especially important if the function
has "side effects", something that happens every time it's called
(such as clearing a shared buffer in memory that you expect to contain
previous results). Lots of bugs happen because this is overlooked.

The third method, as a working example that you can step through, goes
like this:

Sub Test()
Dim testArray As Variant
Dim i As Long
testArray = MyFunc()

For i = 1 To 3
Debug.Print testArray(i)
Next i
End Sub

Function MyFunc() As String()
Dim localArray(1 To 3) As String

localArray(1) = "My Dog Has Fleas"
localArray(2) = "Every Good Boy Does Fine"
localArray(3) = "I'll Be Right Bach"

MyFunc = localArray
End Function

The reason that testArray is declared as a Variant here is that you
can't assign the result of the function directly to an array declared
as Dim testArray(3) As String. You get a compile error if you try it.
(It has something to do with the way the VBA compiler/interpreter
deals with memory addresses.)

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
G

Greg Maxey

Thanks Jay. I haven't stepped through these yet, but from just browsing I
think it helps.
 
J

Jonathan West

Greg Maxey said:
Hi Helmut,


I am in mighty deep water and I am afraid my pressure hull will rupture
before I hit bottom. ;-)

I was really perplexed by Jezebels reply. I mean:

Sub MyFunc(Arg1, Arg2, Arg3)
Arg1 = 1
Arg2 = 2
Arg3 = 3
End Sub

Doesn't appear to be a function at all.

OK, lets give you an example.

Sub MainRoutine()
Dim a as long
Dim b as Long
Dim c as Long
a = 1
b = 1
c = 1
RoutineByref a, b, c
Debug.print a, b, c
a = 1
b = 1
c = 1
RoutineByval a, b, c
Debug.print a, b, c
End Sub

Sub RoutineByRef(x as Long, y As Long, z As Long)
x = x + 1
y = y + 2
z = z + 3
End Sub

Sub RoutineByVal(ByVal x as Long, ByVal y As Long, ByVal z As Long)
x = x + 1
y = y + 2
z = z + 3
End Sub

If you step through that code, what you find is that when you return from
RoutineByref, the values of a, b and c have been changed as a result of
running the routine. But when you return from RoutineByval, they are
unchanged from their values on entry.

This is because in the first routine, you are passing the variable itself
(technically, this is called passing a reference to the variable) and the
routine changes the original variable. In the second routine, you are making
a copy of the variable (passing the variable's value), so any changes made
to the variable are made to the copy, leaving the original untouched.

Generally, to keep your code as compartmentalisd as possible, you should
pass parameters by value using the ByVal keyword. There is a minor
performance penalty. I admit that I do this less than I should, but I do if
I make any modification to the parameter in the routine to which it is
passed, unless I specififcally want the change to be reflected back to the
calling routine.
I was able to see how:

Option Explicit
Type FileDataType
Name As String
Public As Boolean
End Type
Sub CallFunc()
MsgBox MyFunc.Name & " " & MyFunc.Public
End Sub
Function MyFunc() As FileDataType
Dim localFDT As FileDataType
localFDT.Name = "LKJ"
localFDT.Public = True
MyFunc = localFDT
End Function

Appears to return two values, but in stepping through the code it runs
through the function twice.

That is because it is called twice. Once for MyFunc.Name and once for
MyFunc.Public
I also fail to see a practical use for it.

If you need a function to return the coordinates of a rectangle (e.g. the
current selected text), then you might want to define a user-defined type
that contains the x & y coordinates of the top left and bottom right
corners. Yes, you could also use an array, but using a Type means that you
get to define meaningful names for the various items. Makes the code easier
to understand. :)
This one is completely over my head:

Function MyFunc() as String()
Dim localArray(1 to 3) as string

localArray(1) = 1
MyFunc = localArray
End Function

I would like to see an example of what you would get from it and how you
would get it.

Here, the data type being returned from the function is an array of
strings - hence "As String()" with the parentheses in the function
definition. Within the function, a local array of strings is defined and
some value assigned to an element, and then that local array is being
assigned as the return value of the function.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
J

Jonathan West

Helmut Weber said:
Hi Greg,

this is another academic exercise, IMHO.
A function should return _one_ value by definition.

This _one_ value might be an array or a type.

It could even be an array of arrays.
Still, it would be, well, kind of, _one_ value.

I think, there are limits to programming.

I never understood how a program could work,
after a code line like this:
x = Sqr(9)

as there are two solutions: +3, -3.

Yet the program would continue with +3 only.

That is because Sqr is *defined* as the positive square root of the number
passed to it. (Read the help file <g>) You can define a function to be
whatever you want it to be. When you use mathematical functions in
programming, you have to be very careful to ensure that you are correctly
understanding the function as defined in the program itself, which for
perfectly good reasons may be different from the commonly understood
mathematical meaning of the term. Sqr is a perfect example of this.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
J

Jezebel

I also fail to see a practical use for it.
If you need a function to return the coordinates of a rectangle (e.g. the
current selected text), then you might want to define a user-defined type
that contains the x & y coordinates of the top left and bottom right
corners. Yes, you could also use an array, but using a Type means that you
get to define meaningful names for the various items. Makes the code
easier to understand. :)

An advantage of user-defined types over arrays is that their elements can be
of different data types.

They are also essential for API calls to functions that, in C, take or
return a Struct argument (which is why they were introduced in the first
place) ---

Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type

Private Declare Sub GetLocalTime Lib "kernel32" (lpSystem As SYSTEMTIME)

Public Function GetHour() As Integer

Dim sysLocalTime As SYSTEMTIME

GetLocalTime sysLocalTime
GetHour = sysLocalTime.wHour

End Function
 
J

John Nurick

They are also essential for API calls to functions that, in C, take or
return a Struct argument

and (with LSet) for typecasting by mapping the actual bytes of one
variable onto those of another...
 
M

muyBN

Thank you, everyone. I was able to run most of the suggested formats in their
generic form but the only one I was able to apply to my project and get
working was #3; but I notice that in order to return two values, it has to
run through the function as many times. Also, I finally realized that the
"Type" statement had to be at the very beginning of the module. But at least
this one is working and I can hopefully play with and tweak one of the
"one-sweep-wonders" until I get it working.

On to another question: When you're in a directory, I know that this is how
you search for a file within that directory or folder:

With Application.FileSearch
.LookIn = "[path]"
.SearchSubFolders = True
.FileName = "[file]"
.Execute
End With

How would I programatically move up a directory/folder (by "up," I mean
headed toward the root, "C\:") from where I am? Is there any code I can write
to move from and search in a subdirectory, to its parent directory?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top