473,385 Members | 1,329 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Function parameter function

Joe
Hi,

I like to know what do you specify in the function parameter (in the
function implementation) if you want the string that you pass in with the
function call to be changed while its in the function and then you get it
back changed as well?

Is it ByRef or just notthing

function prc0(ByRef editablestring as string )
or

function prc0(editablestring as string )
Feb 8 '06 #1
5 3148
function prc0(ByRef editablestring as string )

--
Peter Macej
Helixoft - http://www.vbdocman.com
VBdocman - Automatic generator of technical documentation for VB, VB
..NET and ASP .NET code
Feb 8 '06 #2
A string is handled a little differently. You can not just set the scoping
as ByRef because strings are immutable. Thus when you change the string, the
reference to the new string inside of the function is changed, but the
reference pointer in the calling method is not changed. You need to pass a
stringbuilder rather than a simple string if you want to manipulate the
return values inside of a sub.

The method declaration you provided seems to indicate that you don't need a
function and could do with a simple method call as in:

Sub prc0(ByRef EditableString as StringBuilder)

Alternatiely, could you alter your calls to have a function that returned a
string rather than changes the mathod's parameters as in:

Function prc0(inString as string) as String
return inString & " is altered"
End Function

The calling method then would be:
MyString = prc0(MyString)

Just some food for thought.
Jim Wooley

"Joe" <jo*******@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

I like to know what do you specify in the function parameter (in the
function implementation) if you want the string that you pass in with the
function call to be changed while its in the function and then you get it
back changed as well?

Is it ByRef or just notthing

function prc0(ByRef editablestring as string )
or

function prc0(editablestring as string )

Feb 8 '06 #3
"Joe" <jo*******@yahoo.com> schrieb:
I like to know what do you specify in the function parameter (in the
function implementation) if you want the string that you pass in with the
function call to be changed while its in the function and then you get it
back changed as well?

Is it ByRef or just notthing

function prc0(ByRef editablestring as string )
or

function prc0(editablestring as string )


'ByRef'.

'Prc(a As String)' is equivalent to 'Prc(ByVal a As String)'. By the way,
if your function does not have a return value, declare it as 'Sub' instead
of 'Function'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Feb 8 '06 #4
"Jim Wooley" <jw******@bellsouth.net> schrieb:
A string is handled a little differently. You can not just set the scoping
as ByRef because strings are immutable. Thus when you change the string,
the reference to the new string inside of the function is changed, but the
reference pointer in the calling method is not changed. You need to pass a
stringbuilder rather than a simple string if you want to manipulate the
return values inside of a sub.


Sorry, but that's wrong. You can pass in a string by-reference and get back
a reference to a new string object.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Feb 8 '06 #5
Jim Wooley wrote:
A string is handled a little differently. You can not just set the scoping
as ByRef because strings are immutable. Thus when you change the string, the
reference to the new string inside of the function is changed, but the
reference pointer in the calling method is not changed. You need to pass a
stringbuilder rather than a simple string if you want to manipulate the
return values inside of a sub.


Sorry but the followibg works perfectly:

Sub test()
Dim s As String = "original"
prc0(s)
MsgBox(s)
End Sub

Sub prc0(ByRef EditableString As String)
EditableString = "modified"
End Sub

Message box shows "modified".

--
Peter Macej
Helixoft - http://www.vbdocman.com
VBdocman - Automatic generator of technical documentation for VB, VB
..NET and ASP .NET code
Feb 8 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
14
by: dover | last post by:
/*Copy the line a token at a time into the output*/ copy(istream_iterator<string>(iss), istream_iterator<string>(), ostream_iterator<string>(oss, " ")); What's the meaning of this statement?...
4
by: Vish | last post by:
Hi all, I am having a build error in one of the overloaded functions in my class. The function takes either a string as a parameter or a type referenced in another dll as a parameter. My class...
16
by: hzmonte | last post by:
Correct me if I am wrong, declaring formal parameters of functions as const, if they should not be/is not changed, has 2 benefits; 1. It tells the program that calls this function that the...
4
by: Tony Lownds | last post by:
(Note: PEPs in the 3xxx number range are intended for Python 3000) PEP: 3107 Title: Function Annotations Version: $Revision: 53169 $ Last-Modified: $Date: 2006-12-27 20:59:16 -0800 (Wed, 27 Dec...
10
by: Janus | last post by:
Hi, Is there a way to pass arguments to the callback function used inside an addEventListener? I see that I can only list the name of the callback function. For eg, I use this: var...
40
by: Angus | last post by:
Hello I am writing a library which will write data to a user defined callback function. The function the user of my library will supply is: int (*callbackfunction)(const char*); In my...
5
by: pauldepstein | last post by:
Hi all, I saw some code like this: unsigned short SomeFunc(unsigned short SomeNum, bool SomeBool, const SomeClass& SomeMem, bool(SomeClass::*AmemberFunctionOfSomeClass)(const unsigned...
1
by: Jorge | last post by:
On Oct 23, 10:36 am, Tuxedo <tux...@mailinator.comwrote: Yes: function first_function (PARAMETER) { preload_image = new Image(800,600); preload_image.onload = function () {...
10
by: Constantine AI | last post by:
Hi i am having a little problem with an equation function that was created from all your help previously. The function works fine itself but with a small glitch within it. Here is the function...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.