473,509 Members | 2,951 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Very very simple

Hi,

I'm used to programming with Java, and am unsure of how this may work within
VB.

I want to pass some strings to a function, and alter them within the
function. I want the strings to stay altered when the function ends
*without returning the strings explicitly*. I think this is to do with
passing references? How should it work (if possible?) using VB?

Thanks in advance,
Chris
Jul 17 '05 #1
9 2395
Chris,

Paramters in VB are ByRef ('by reference') by default, so what you want to
do will happen automatically.

HTH,

Rob.

"C L Humphreys" <cl*********@toofgib.moc> wrote in message
news:bk**********@ucsnew1.ncl.ac.uk...
Hi,

I'm used to programming with Java, and am unsure of how this may work within VB.

I want to pass some strings to a function, and alter them within the
function. I want the strings to stay altered when the function ends
*without returning the strings explicitly*. I think this is to do with
passing references? How should it work (if possible?) using VB?

Thanks in advance,
Chris

Jul 17 '05 #2
If I remember correctly (and I probably do), you have three choices...

1. Define the variables that you want to retain information as STATIC types.

2. Define the variables that you want to retain information as PUBLIC types
in your general declarations area.

3. Define the variables that you want to retain information as PUBLIC types
in a separate MDI child form.

I personally prefer to use method #2, unless I have one MAJOR padload of
variables, then I switch to the MDI form system.

---------------8<-------------------cut
here------------8<------------------------

"C L Humphreys" <cl*********@toofgib.moc> wrote in message
news:bk**********@ucsnew1.ncl.ac.uk...
Hi,

I'm used to programming with Java, and am unsure of how this may work within VB.

I want to pass some strings to a function, and alter them within the
function. I want the strings to stay altered when the function ends
*without returning the strings explicitly*. I think this is to do with
passing references? How should it work (if possible?) using VB?

Thanks in advance,
Chris

Jul 17 '05 #3
"Rob Strover" <di*************@NOSPAMyahoo.com.invalid> wrote in message
news:Ha********************@news-server.bigpond.net.au...
Chris,

Paramters in VB are ByRef ('by reference') by default, so what you want to
do will happen automatically.


Thanks, through the interpreter I've realised the problem lies in a replace
statement..

?Replace("Hello", "lo", "p")
Hello

I'm wanting it to return "Help" - i.e, change the "lo" to "p"... how can I
do this?

Thanks again,
Chris
Jul 17 '05 #4
Chris,

Can't help as I don't have VB6, where this function exists.

The code that MS released to achieve this functionality for VB5 developers
(Q188007: Simulate Visual Basic 6.0 String Functions in VB5) gives the
result you expected, so I guess someone with VB6 will have to answer this
question.

Rob.

"C L Humphreys" <cl*********@toofgib.moc> wrote in message
news:bk**********@ucsnew1.ncl.ac.uk...
"Rob Strover" <di*************@NOSPAMyahoo.com.invalid> wrote in message
news:Ha********************@news-server.bigpond.net.au...
Chris,

Paramters in VB are ByRef ('by reference') by default, so what you want to do will happen automatically.
Thanks, through the interpreter I've realised the problem lies in a

replace statement..

?Replace("Hello", "lo", "p")
Hello

I'm wanting it to return "Help" - i.e, change the "lo" to "p"... how can I
do this?

Thanks again,
Chris

Jul 17 '05 #5
"Rob Strover" <di*************@NOSPAMyahoo.com.invalid> wrote in message
news:tK********************@news-server.bigpond.net.au...
Chris,

Can't help as I don't have VB6, where this function exists.

The code that MS released to achieve this functionality for VB5 developers
(Q188007: Simulate Visual Basic 6.0 String Functions in VB5) gives the
result you expected, so I guess someone with VB6 will have to answer this
question.


Hmm, trying the examples given on that KB article results in errors for me,
I think this may be due to me using VB for access.

FYI the optional parameters are not allowed, and it only works if the string
to search for is a single character long.. odd.

Thanks again,
Chris
Jul 17 '05 #6
Chris,

I've been checking with VBA under Word 97 (rather than VB5 <not on this
PC>), but in the version of the VB5/MSKB Replace version I got rid of the
various optional parameters, so that may be the answer.

BTW, just ran the following amended version in an Access 97 Module OK

HTH

Rob.

-------------------- Code Begins --------

Private Sub AAAA()

MsgBox Replace("Hello", "llo", "lp") ' ==> Help

End Sub

Private Function Replace(sIn As String, sFind As String, sReplace As String)
As String

Dim nC As Long
Dim nPos As Integer
Dim sOut As String

sOut = sIn
nPos = InStr(sOut, sFind)

If nPos <> 0 Then
Do
nC = nC + 1
sOut = Left$(sOut, nPos - 1) & sReplace & Mid$(sOut, nPos +
Len(sFind))

nPos = InStr(sOut, sFind)
Loop While nPos > 0

End If

Replace = sOut

End Function

-------------------- Code Ends --------

"C L Humphreys" <cl*********@toofgib.moc> wrote in message
news:bk**********@ucsnew1.ncl.ac.uk...
"Rob Strover" <di*************@NOSPAMyahoo.com.invalid> wrote in message
news:tK********************@news-server.bigpond.net.au...
Chris,

Can't help as I don't have VB6, where this function exists.

The code that MS released to achieve this functionality for VB5 developers (Q188007: Simulate Visual Basic 6.0 String Functions in VB5) gives the
result you expected, so I guess someone with VB6 will have to answer this question.
Hmm, trying the examples given on that KB article results in errors for

me, I think this may be due to me using VB for access.

FYI the optional parameters are not allowed, and it only works if the string to search for is a single character long.. odd.

Thanks again,
Chris

Jul 17 '05 #7
> > Paramters in VB are ByRef ('by reference') by default, so what you want
to
do will happen automatically.
Thanks, through the interpreter I've realised the problem lies in a

replace statement..

?Replace("Hello", "lo", "p")
Hello

I'm wanting it to return "Help" - i.e, change the "lo" to "p"... how can I
do this?


Sub ChangeStringThatIsPassedIn(StringIn As String)
StringIn = Replace(StringIn, "lo", "p")
End Sub

You would call this either like this (simplistic, non-realistic example):

MyVariable = "Hello"
Call ChangeStringThatIsPassedIn(MyVariable)
MsgBox MyVariable

or like this (using the alternate method of calling a Sub)

MyVariable = "Hello"
ChangeStringThatIsPassedIn MyVariable
MsgBox MyVariable

Note in this last example, you **must** leave out the parentheses or the Sub
won't do what you expect. The reason, anything non-syntactical in
parentheses is evaluated as an expression. If you wrote this

ChangeStringThatIsPassedIn (MyVariable)

(note the space in front of the open parenthesis that VB will insert), then
MyVariable would be evaluated as an expression (whose result was nothing
more than its own contents) and the memory location of where VB housed the
evaluated expression, **not** the variable, would be passed into the Sub.

Rick - MVP

Rick - MVP
Jul 17 '05 #8
On Wed, 17 Sep 2003 15:48:02 +0100, "C L Humphreys"
<cl*********@toofgib.moc> wrote:
"Rob Strover" <di*************@NOSPAMyahoo.com.invalid> wrote in message
news:Ha********************@news-server.bigpond.net.au...
Chris,

Paramters in VB are ByRef ('by reference') by default, so what you want to
do will happen automatically.


Thanks, through the interpreter I've realised the problem lies in a replace
statement..

?Replace("Hello", "lo", "p")
Hello

I'm wanting it to return "Help" - i.e, change the "lo" to "p"... how can I
do this?


It should be doing just that

Jul 17 '05 #9
"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message
news:Mo********************@comcast.com...
Paramters in VB are ByRef ('by reference') by default, so what you
want
to do will happen automatically.
Thanks, through the interpreter I've realised the problem lies in a

replace
statement..

?Replace("Hello", "lo", "p")
Hello

I'm wanting it to return "Help" - i.e, change the "lo" to "p"... how can I do this?


Sub ChangeStringThatIsPassedIn(StringIn As String)
StringIn = Replace(StringIn, "lo", "p")
End Sub

You would call this either like this (simplistic, non-realistic example):

MyVariable = "Hello"
Call ChangeStringThatIsPassedIn(MyVariable)
MsgBox MyVariable

or like this (using the alternate method of calling a Sub)

MyVariable = "Hello"
ChangeStringThatIsPassedIn MyVariable
MsgBox MyVariable

Note in this last example, you **must** leave out the parentheses or the

Sub won't do what you expect. The reason, anything non-syntactical in
parentheses is evaluated as an expression. If you wrote this

ChangeStringThatIsPassedIn (MyVariable)

(note the space in front of the open parenthesis that VB will insert), then MyVariable would be evaluated as an expression (whose result was nothing
more than its own contents) and the memory location of where VB housed the
evaluated expression, **not** the variable, would be passed into the Sub.

Thanks to all for their help.

Chris
Jul 17 '05 #10

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

Similar topics

10
2397
by: Eric S. Johansson | last post by:
I have an application where I need a very simple database, effectively a very large dictionary. The very large dictionary must be accessed from multiple processes simultaneously. I need to be...
6
2049
by: Manuel Collado | last post by:
I would like to write simple, yet well structured documents with a really simple XML DTD (or schema). Either Docbook or SDocbook are overkill for this simple case. XHTML is simpler, but...
0
1384
by: Gene Ellis | last post by:
Very simple question. If I have the XML file below: <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="newspage.xsl"?> <newspage> <content>Click here for blah...
4
6304
by: Ville Ahonen | last post by:
I'm just learning C++ and thought I'd program a simple screensaver in VC++ as my first assignment. I've found some tutorials showing how to create a screenasver using OpenGL, but I found it very...
8
3168
by: alsemgeest | last post by:
Hi, I'd like to make my own very simple autorisation system. Just a table: tblUsers (user and pw). Next I need a form with user and pw in textbox, with an OK button. If the lookup fails: msgbox...
6
2248
by: Marc | last post by:
How could I directly trigger a very simple on localhost and a known port listening server from my internet browser client? Local host means the little server would be running on the client machine,...
16
1643
by: lovecreatesbeauty | last post by:
`Writing C code is very simple', one guy related to my work said. I'm not sure whether he is an expert or not. What he said about C programming like this can't convince me. I think there should be...
3
7557
by: cold80 | last post by:
I was just doing a performance test in order to see the benefit of using AJAX instead of doing a postback on the server. So I have a simple page that performs a request to the server and write a...
1
1206
by: Raycaster | last post by:
I'm 3/4 finished 2 simple VB apps for a upcoming silent auction being held at my children's school. Very Simple - This is what it does: 1st app allows input and builds a text database Unit...
5
1745
by: Ibys | last post by:
Hi, i am just starting to learn javascript, so i am probably doing something very simple wrong. i have read a lot of articles on maths in java, but cant find anything simple enough for my problem. I...
0
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7416
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5062
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4732
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3218
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3207
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
779
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
443
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.