View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Flystar Flystar is offline
external usenet poster
 
Posts: 1
Default Excel VBA Function Parameter Overwritten

I have two vba functions in an excel macro, where the result of th
first is passed into the other as a parameter. The problem is that th
value of this paramter appears to be changed by the actions of thi
second function, hence overwritting the value of my first function
result. To illustrate:

Dim a, b As Integer

a = funcone(0,"Hello")
b = functwo(a,"Hello")

FUNCTION DEFINITIONS
Function funcone(pos As Integer, text As String) As Integer
Dim pos As Integer
'Some tasks obtaining pos
funcone = pos
End Function

Function functwo(pos As Integer, text As String) As Integer
For pos = 1 To 10
'Some tasks
Next pos
functwo = pos + 30
End Function

By using the basics of the functions above, a = 10 always. Why


Tracing the values of a and b.
a = funcone(0,"Hello")
'a = 5 for example

b = functwo(a,"Hello")
'a = 10
'b = 40

This is driving me crazy so any help will be greatly appreciated

--
Message posted from http://www.ExcelForum.com