473,804 Members | 3,453 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 2406
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*********@to ofgib.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*********@to ofgib.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.c om.invalid> wrote in message
news:Ha******** ************@ne ws-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*********@to ofgib.moc> wrote in message
news:bk******** **@ucsnew1.ncl. ac.uk...
"Rob Strover" <di************ *@NOSPAMyahoo.c om.invalid> wrote in message
news:Ha******** ************@ne ws-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.c om.invalid> wrote in message
news:tK******** ************@ne ws-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*********@to ofgib.moc> wrote in message
news:bk******** **@ucsnew1.ncl. ac.uk...
"Rob Strover" <di************ *@NOSPAMyahoo.c om.invalid> wrote in message
news:tK******** ************@ne ws-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 ChangeStringTha tIsPassedIn(Str ingIn As String)
StringIn = Replace(StringI n, "lo", "p")
End Sub

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

MyVariable = "Hello"
Call ChangeStringTha tIsPassedIn(MyV ariable)
MsgBox MyVariable

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

MyVariable = "Hello"
ChangeStringTha tIsPassedIn 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

ChangeStringTha tIsPassedIn (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*********@to ofgib.moc> wrote:
"Rob Strover" <di************ *@NOSPAMyahoo.c om.invalid> wrote in message
news:Ha******* *************@n ews-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("Hell o", "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******** ************@co mcast.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 ChangeStringTha tIsPassedIn(Str ingIn As String)
StringIn = Replace(StringI n, "lo", "p")
End Sub

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

MyVariable = "Hello"
Call ChangeStringTha tIsPassedIn(MyV ariable)
MsgBox MyVariable

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

MyVariable = "Hello"
ChangeStringTha tIsPassedIn 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

ChangeStringTha tIsPassedIn (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
2434
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 able to lock records within the very large dictionary when records are written to. Estimated number of records will be in the ballpark of 50,000 to 100,000 in his early phase and 10 times that in the future. Each record will run about 100 to 150...
6
2071
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 unstructured (no nested sections). And is not really very simple. Before trying to setup a stripped-down document format by myself, I would like to know if there are simple XML document structure proposals ready to be used (I dislike to reinvent the...
0
1398
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 blah</content> </newspage> How can I use XLink to make an HTML hyperlink out of the "click here" text?
4
6322
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 confusing and perhaps uunnecessarily complex for my needs. What I would like to do is 1) know the dimensions of the screen (eg. 1024x768x32bit) 2) be able to use some sort of framebuffering, i.e. drawing to one frame while showing the other to...
8
3184
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 "Wrong, bye!" and docmd.quit If lookup succeeds: open the switchboard. Now I'm not very familiar with the lookup function, and this is where I
6
2304
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, where my browser resides. Browser would be IE, O.S. Windows 2000 or XP, and it's for an intranet application. The goal of the little server on the localhost client side would be to trigger a scanner, with the TWAIN library. Also this server is...
16
1680
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 two kinds of people can make such a comment on C programming. One is C expert with rich experiences of some years on real projects; The other is opportunist idiocy of C programming. What do you think of C programming? Is writing C code an art?...
3
7572
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 counter on the page when it receives the response from the server. I'm not changing the page actually, so the browser don't have to modify the internal DOM and to render the changes. I tried this simple page with IE 7.0, Firefox 2.0 and Opera 9.10....
1
1221
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 ID (Done before Auction) Unit Description (Done before Auction) Unit Donor (Done before Auction) Unit Value (Done before Auction)
5
1764
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 am looking for how to get an IF statement to give me the correct output. I am trying to get it to give me a result for a weeks pay, taking that the code worked before i tried to add the IF statement, to make it that if HoursWorked >= 20, the rate of...
0
9576
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10567
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10323
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10074
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7613
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5515
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.