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(str A, Integer))
MsgBox(strA)
End Sub
Public Sub funcB(ByRef objA As Integer)
objA = 1234
End Sub
End Class
" 5 1862
Ann,
You are not getting the return value from the function call.
e.g.
strA = funcB(CType(str A, Integer))
--
Thanks,
Carl Prothman
Microsoft ASP.NET MVP http://www.able-consulting.com
"ann" <wa********@yah oo.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(str A, 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(str A, 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(str A, 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********@yah oo.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(str A, Integer)) MsgBox(strA)
End Sub
Public Sub funcB(ByRef objA As Integer) objA = 1234 End Sub
End Class
"
"Andre" <fo********@hot mail.com> wrote Carl Prothman [MVP] wrote: Ann, You are not getting the return value from the function call. e.g. strA = funcB(CType(str A, 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(str A, Integer))
--
Thanks, Carl Prothman Microsoft ASP.NET MVP http://www.able-consulting.com
"ann" <wa********@yah oo.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(str A, Integer)) MsgBox(strA)
End Sub
Public Sub funcB(ByRef objA As Integer) objA = 1234 End Sub
End Class
"
.
"ann" <wa********@yah oo.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)
{
this.s=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
collection. Thus, my interface now looks like this
public interface IMyCollection : ICollection
{
void Add (string toBeAdded);
|
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 with me...
using System.Collections.Generic;
|
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. Löwis |
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: $Revision: 42333 $
|
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 -- Deep
Secrets, Perter van der Linden'. But I wonder why line 9 is ok but line
10 is illegal?
Is what Keith Thompson said in another post also helpful to understand
this question:
"... The implicit conversion rule applies only to void*, not...
|
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 paper written on this
subject.
On the Expressive Power of Programming Languages, by Matthias
Felleisen, 1990.
http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
|
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) : x0(a), y0(b),
|
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 developer.
x = someObject as MySpecificType;
x = (MySpecificType) someObject;
Thanks.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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...
|
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...
|
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...
|
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...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |