VB Programming wont return string

Microsoft Visual studio 2005 professiona...
November 16, 2009 at 15:56:34
Specs: Windows XP
Private Function Ctext(ByVal utext As
String) As String
If System.IO.File.Exists("npcs.txt") =
True Then
Dim objReader As New
System.IO.StreamReader("npcs.txt")
Do While objReader.Peek() <> -1
utext = Replace(utext,
objReader.ReadLine(), "[[" +
objReader.ReadLine() + "]]")
Loop
objReader.Close()
End If

If System.IO.File.Exists("locations.txt")
= True Then
Dim objReader As New
System.IO.StreamReader("locations.txt")
Do While objReader.Peek() <> -1
utext = Replace(utext,
objReader.ReadLine(), "[[" +
objReader.ReadLine() + "]]")
Loop
objReader.Close()
End If
End Function

this will not return the replaced string.


See More: VB Programming wont return string

Report •


#1
November 16, 2009 at 21:13:04
If it is Utext that you trying to return then it is the ByVal directive that is causing the problem.

Replace it with ByRef and it should work.

Or alternatively put the command ctext = Utext as the end of the function and the value will be returned to the calling function providing you ask for it with the command ReturnString = ctect(utext)

Having said that I believe that with VB.Net the ByVal directive is superfluous as parameters are passed ByVal by default to conform to C++ calling conventions.

In VB6 values are passed ByRef by default and if you want to only pass the value then you need to use the ByVal directive. Either way using the ByVal directive does just that and only passes that value and not a reference to the value which is what you need.

Stuart


Report •
Related Solutions


Ask Question