Does somebody know why I get a blank string in strA? Last
time post the wrong code.
"
Option Strict On
Option Explicit On
Public Class Cast
Private Sub FuncA()
Dim strA As String
funcB(CType(strA, Integer))
MsgBox(strA)
End Sub
Public Sub funcB(ByRef objA As Integer)
objA = 1234
End Sub
End Class
" 5 1839
Ann,
You are not getting the return value from the function call.
e.g.
strA = funcB(CType(strA, Integer))
--
Thanks,
Carl Prothman
Microsoft ASP.NET MVP http://www.able-consulting.com
"ann" <wa********@yahoo.com> wrote in message news:06****************************@phx.gbl... Does somebody know why I get a blank string in strA? Last time post the wrong code.
" Option Strict On Option Explicit On
Public Class Cast Private Sub FuncA()
Dim strA As String funcB(CType(strA, Integer)) MsgBox(strA)
End Sub
Public Sub funcB(ByRef objA As Integer) objA = 1234 End Sub
End Class
"
Carl Prothman [MVP] wrote: Ann, You are not getting the return value from the function call. e.g. strA = funcB(CType(strA, Integer))
No that's not correct. The function isn't returning anything in the
first place. Note that CType returns the result of the explicit
conversion of types.. so in fact, you should be storing that result in
another integer and passing that variable by reference to the function.
Observe:
Option Strict On
Option Explicit On
Public Class Cast
Private Sub FuncA()
Dim strA As String
Dim strB As Integer
strB = CType(strA, Integer)
funcB(strB)
MsgBox(strB)
End Sub
Public Sub funcB(ByRef objA As Integer)
objA = 1234
End Sub
End Class
If you don't do this, the object reference that you passed via:
funcB(CType(strA, Integer))
will be updated in funcB but on return of that routine, you lose that
object reference and are actually refering to the old reference to the
empty string object in the following line:
MsgBox(strA)
Hope that helps.
-Andre --
Thanks, Carl Prothman Microsoft ASP.NET MVP http://www.able-consulting.com
"ann" <wa********@yahoo.com> wrote in message news:06****************************@phx.gbl...
Does somebody know why I get a blank string in strA? Last time post the wrong code.
" Option Strict On Option Explicit On
Public Class Cast Private Sub FuncA()
Dim strA As String funcB(CType(strA, Integer)) MsgBox(strA)
End Sub
Public Sub funcB(ByRef objA As Integer) objA = 1234 End Sub
End Class
"
"Andre" <fo********@hotmail.com> wrote Carl Prothman [MVP] wrote: Ann, You are not getting the return value from the function call. e.g. strA = funcB(CType(strA, Integer))
No that's not correct. The function isn't returning anything in the first place.
Doh! When I quickly scanned through the code, I "Func" in the name
and thought it was a Function. That's what I get for answering a post
before my first cup of coffee in the morning... ;-)
--
Thanks,
Carl Prothman
Microsoft ASP.NET MVP http://www.able-consulting.com
Carl, my problem here is I want to pass a variable by
reference to a function which has a parameter in a
different type. Two way to do that :
1. Undre's way-- But it means more memory copy action.
2. Set strict OFF, then everything works fine except
there will no type checking.
So can you give some detail for Ctype()? -----Original Message----- Ann, You are not getting the return value from the function
call.e.g. strA = funcB(CType(strA, Integer))
--
Thanks, Carl Prothman Microsoft ASP.NET MVP http://www.able-consulting.com
"ann" <wa********@yahoo.com> wrote in message
news:06****************************@phx.gbl... Does somebody know why I get a blank string in strA?
Last time post the wrong code.
" Option Strict On Option Explicit On
Public Class Cast Private Sub FuncA()
Dim strA As String funcB(CType(strA, Integer)) MsgBox(strA)
End Sub
Public Sub funcB(ByRef objA As Integer) objA = 1234 End Sub
End Class
"
.
"ann" <wa********@yahoo.com> wrote Carl, my problem here is I want to pass a variable by reference to a function which has a parameter in a different type. Two way to do that : 1. Undre's way-- But it means more memory copy action. 2. Set strict OFF, then everything works fine except there will no type checking.
I think your best bet is to NOT use a Sub / ByRef parameter,
but to create a Function that returns a value. That way you can do
the conversion on a ByVal parameter and not run into the ByRef
conversion problem.
If you do still want to use ByRef, then use Andre's technique,
which is right on the mark! I would not Set Strict Off.
So can you give some detail for Ctype()?
Here is what the on-line help says for CType: http://msdn.microsoft.com/library/de...vafctCType.asp
--
Thanks,
Carl Prothman
Microsoft ASP.NET MVP http://www.able-consulting.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mark Oliver |
last post by:
Hi, I want to put a type conversion in my class, but I don't want the
conversion to be usable in a passed parameter because it makes no sense.
class cData
{
string s;
public cData(string s)...
|
by: Madhu Gopinathan |
last post by:
Hi,
I hope this is the right forum for this question.
I am extending ICollection to create a Collection Type (say
MyCollection) wherein I can control the types of objects being added to the...
|
by: Yuriy Solodkyy |
last post by:
Hi
VS 2005 beta 2 successfully compiles the following:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1 {
class Program {
|
by: pgconnolly |
last post by:
/* foreach does implicit type conversion on elements of a params argument or
Generic.List.
* This is not good.
* Examples of evil follow...
*/
using System;
// I love it when C# is strict...
|
by: Enekajmer |
last post by:
Hi,
1 int main()
2 {
3 float a = 17.5;
4 printf("%d\n", a);
5 printf("%d\n", *(int *)&a);
6 return 0;
7 }
|
by: Martin v. Lwis |
last post by:
I've been working on PEP 353 for some time now.
Please comment, in particular if you are using 64-bit
systems.
Regards,
Martin
PEP: 353
Title: Using ssize_t as the index type
Version:...
|
by: lovecreatesbeauty |
last post by:
There is a warning/(error? I remember it is an error for line 10 on
some compilers before. At least on g++, it is an error.) for line 10. I
first read a similar example from `Expert C Programming...
|
by: Xah Lee |
last post by:
in March, i posted a essay “What is Expressiveness in a Computer
Language”, archived at:
http://xahlee.org/perl-python/what_is_expresiveness.html
I was informed then that there is a academic...
|
by: zaeminkr |
last post by:
I got a good answer here I have still confusing part.
I have two very simple classes
class DRect
{
private :
double x0, y0, x1, y1;
public :
DRect(double a, double b, double c, double d) :...
|
by: Smithers |
last post by:
Are there any important differences between the following two ways to
convert to a type?... where 'important differences' means something more
profound than a simple syntax preference of the...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
| |