473,624 Members | 2,119 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

simple question on parameter passing

Consider the procedure

Private Sub Adder(ByVal Num1 As Integer, etc. )

End Sub

which called by Call Adder( TxtNum1,.) where TxtNum1 is a text box.

Why does Num1 accept the value as an integer when the actual parameter being
passed is of type string? Why no type mismatch error??

Many thanks

Geoff
Sep 7 '06 #1
2 4281
Geoff wrote:
Consider the procedure

Private Sub Adder(ByVal Num1 As Integer, etc. )

End Sub

which called by Call Adder( TxtNum1,.) where TxtNum1 is a text
box.

Why does Num1 accept the value as an integer when the actual
parameter being passed is of type string? Why no type mismatch
error??
That's one of the "features" introduced at VB4, and commonly referred to as
"Evil Type Coercion". If VB can coerce, it does. Here's an article I wrote
on that, way back when:

Coercion Aversion
http://vb.mvps.org/articles/pt199511.pdf

--
Sep 7 '06 #2

"Karl E. Peterson" <ka**@mvps.orgw rote in message
news:ed******** **@emma.aioe.or g...
Geoff wrote:
>Consider the procedure

Private Sub Adder(ByVal Num1 As Integer, etc. )

End Sub

which called by Call Adder( TxtNum1,.) where TxtNum1 is a text
box.

Why does Num1 accept the value as an integer when the actual
parameter being passed is of type string? Why no type mismatch
error??

That's one of the "features" introduced at VB4, and commonly referred to as
"Evil Type Coercion". If VB can coerce, it does. Here's an article I wrote
on that, way back when:

Coercion Aversion
http://vb.mvps.org/articles/pt199511.pdf
IN fact, when you pass TxtNum1, you are passing a TextBox, not a string. VB also
finds the default property of the TextBox, which is Text, which is a string, and
then does ETC and passes the result. Since default properties can also get you
in trouble, it is usually considered better to use TxtNum1.Text directly:
If IsNumeric(TxtNu m1.Text) Then
Call Adder(CInt(TxtN um1.Text))
End If
Sep 8 '06 #3

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

Similar topics

27
2371
by: Brian Sabbey | last post by:
Here is a first draft of a PEP for thunks. Please let me know what you think. If there is a positive response, I will create a real PEP. I made a patch that implements thunks as described here. It is available at: http://staff.washington.edu/sabbey/py_do Good background on thunks can be found in ref. . Simple Thunks
20
2557
by: Sam | last post by:
Hi I'm learning to code with C++ and wrote some very simple code. I think it's consistent with every rule but always got compiling errors that I don't understand. The code include 5 files as following, delimited by //////: ////////////////pose.h #ifndef pose_h #define pose_h #include "point.h"
33
2247
by: hermit_crab67 | last post by:
Can someone explain to a C newbie why this doesn't work as I expect it to work? (expectations clearly outlined in the printf statement in main routine) OS: Linux 2.4.26 GCC: 2.95.4 void modify_pointer(char *); int main(int argc, char *argv) {
6
16259
by: wiredless | last post by:
What is the advantage of passing an interface type? according to UML (visio) when i reverse engineer existing code to a UML diagram I get the error "UMLE00046: sample : - An interface cannot be used as the type of a parameter." for this code:
21
3288
by: vmsgman | last post by:
Here is a code sample ... int blah = ReadFile( defArray, defFileName, w, h); // Read File Contents into memory array and return for processing public int ReadFile( ref ushort nArray, string sFname, int w, int h) { FileStream fs = new FileStream(sFname, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); // Read data
20
5039
by: Brien King | last post by:
If I have a parameter that has an Object type (as opposed to something like a string), can I make that parameter a CONST? Right now, if you pass an object into a sub/function, that sub/function can modify the object no matter how it's defined (ByVal or ByRef). In some cases, I want to make sure that you cannot modify the object. Is there a way to do that in VS2003 or the up comming VS2005?
2
1607
by: Simon Harvey | last post by:
Hi everyone, I'm having a really simple problem - I can't seem to insert a null value into the database. When I do it tells me that the procedure expects the parameter and that I'm not providing it. Well, I am, its just a null value! The code is: con.Open();
2
1393
by: serge calderara | last post by:
Dear all, Within a web service you are able to receive or send soap header values. Does the soap header could be a place to pass web service parameter function ? If this is the case, wjat is the real benefits on passing paramter value in sop header rather that function parameter ? Thanks for your reply regards
24
3436
by: Michael | last post by:
Hi, I am trying to pass a function an array of strings, but I am having trouble getting the indexing to index the strings rather than the individual characters of one of the strings. I have declared an array as: char *stringArray = {"one","two","three","a"}; When I pass the array using:
3
1846
by: nembo kid | last post by:
I have an issue with a simple function that has to make a linear search for a key into an array. If the key is found in the array, the function it has to return 1 to the caller and pass array index through a out parameter. The issue is that the out parameter is not being updated. If I return the position to the caller (instead to use a out parameter) all is ok.
0
8234
marktang
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...
0
8620
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
8335
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
8474
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...
1
6110
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
5563
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
4079
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...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.