|
-
Jan 21st, 2000, 03:45 AM
#1
Thread Starter
Hyperactive Member
A friend had given me some code to go through a csv file and grab out a count of the number of fields as well as the actual info. It works but I have a question and he's not available at the moment.
I have the code to do this in a seperate function.
function ScanLine(iLine as string, strFields() as string) as integer
hte iLine is the entire line from the csv file. The strFields array is used to store the value and ScanLine returns a count of the number of fields. The function that calls it has a strFields() array declared as well. It seems that it runs this 2 times, 1 to get a count of fields, then ReDim's the strFields array with that number. Then it runs it again and this time it puts the value into the strFields array. I don't understand how 1 function can affect a variable in another function. Neither are globals or anything. They're just plain string declarations. If someone can shed some light on this I would appreciate it.
Thanks.
-
Jan 21st, 2000, 04:43 AM
#2
When Declaring/Creating Functions/Subs Parameters are passed ByRef by default, which means the Sub/Function gets a Pointer to the Actual Variable, not just the Value of the Variable, so making a Change to the Parameter would Directly Change the Variable Passed to it, ie.
Code:
Private Sub Add2(iValue As Integer)
iValue = iValue + 2
End Sub
If you call Add2 and Pass it a Variable, that Variable will be Incremented by 2..
Code:
Private Sub Add2(ByVal iValue As Integer)
iValue = iValue + 2
End Sub
Calling this Version of Add2 with the Same Variable, will never change the Variables Value as the Sub is Recieving the Value of the Variable and Storing it in a Local/Private Variable whose Scope Only Exists within the Sub.
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
-
Jan 21st, 2000, 06:04 AM
#3
Thread Starter
Hyperactive Member
Thanks, that makes sense.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|