Solved

function overloading

Posted on 2000-03-20
18
2,448 Views
Last Modified: 2013-11-25
is there any way to overload function in vb6?
0
Comment
Question by:makris
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
  • 3
  • +1
18 Comments
 
LVL 10

Expert Comment

by:caraf_g
ID: 2636732
No.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2636790
Wait for VB7
0
 
LVL 6

Accepted Solution

by:
anthonyc earned 50 total points
ID: 2636841
True overloading does not come to vb7.  You can attempt (although it will not give you every feature) to overload using a variant.  This is definitely not overloading, but can produce the effect in some cases.

For example, try this add function

function Add(vntAdd1 as variant, vntAdd2 as variant) as variant
  if typename(vntAdd1) = "String" or typename(vntAdd2) = "String" then
    add = vntadd1 & vntadd2
  else
    add = val(vntadd1) + val(vntadd2)
  end if
end function
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 10

Expert Comment

by:caraf_g
ID: 2636881
The answer still is No.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2637586
AnthonyC:
Your's is an example of recursion (since you don't have a shutoff in your snippet.. one that will peacefully run forever.. <smile>).

---------------------------------
As I understand it, overloading is casting an object as something different from what it was originally.. (but I could be wrong, could someone please help with an Overloading definition?.. As such, please take the following with a grain of salt.. <smile>.

With Data, I have recast variables of different types by using CopyMem APIs.
As to Functions.. there is a CallByName feature in VB6 that may be useful for your purposes.

Other than that.. <bewildered look now on my face>.. "Right On Caraf G !!!".. <lol> and a <wink>.

0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2637622
<nudge>
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2637701
caraf_g:
nudge?.. Overloaded are we, huh?.. <lol> and a <wink>. Ok.. so what is overloading, besides free tickets to an all you can eat beans and franks buffet night?.. <smile>.
0
 
LVL 6

Expert Comment

by:anthonyc
ID: 2638041
recursion?  How so?  I am not recalling the Add function from inside the add function.

My example is definitely not overloading.. don't get me wrong..  
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2638373
Anthonyc:
Ooooops.. <sheepish grin>.. missed the equal sign inside of your If.. thought you were calling add again.. <now blushing all over>.. I should have "red" it right the first time.. <smile>.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2638962
Overloading:
You can define a procedure (in the same module) using different arguments or different types:
Sub Add ( a as integer, b as integer , byref c as double )
Sub Add ( a as double, b as double, byref c as double )
aso.

anthonyc:
this feature is announced in vb7
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2638979
AngelIII:
But wait a second.. why not just pass the parameters as Variants.. you know.. type GLOB.. and then use them according to your needs? In a sense, wouldn't that be providing overloading like qualities?.. Oh well.. Thank YOU AngelIII.. <smile>.

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2639021
1) Think a moment about parameter size (variant= min 8 bytes, integer=2 bytes, long = 4 bytes aso)
2) Think about type safety (the add example above is not the best one, but you may eliminate some code with this)
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2639077
AngelIII:
Points well taken.. but with code can easily be accounted for (ie. IsNumeric.. assignments with overflow error trapping). The type safety would be a concern, but in true overloading, I doubt that type safety could be done as well (since I assume you are using indirection and only passing addresses). Anyhow.. thank you for the lesson.. <smile>.

By the way, as I recall, the reason for the variant being so long is that it can handle variables of any kind Typing.. thus making it most useful.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2639537
As i recall (smile), somebody (not it was u) said that when writing performant code, one has to enumerate the operations effectuated.
When using variant variables, VB has to allocate more memory, store the value type into the variant, and the value type has to be tested to check the cases possible.
If you could use overloading, the checks will still be done, but at a more effective way. The allocation of more memory, the store of the value type into the variant can be left away (which saves time and money, as less code = less bugs)
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2641451
AngelIII:
All TRUE.. but Gateway now sells a full 650mhz system w/17" monitor, for only $999. Did Intel make Microsoft Windows a success.. or did Microsoft Windows make Intel a success?.. <laughing>.. Who Cares? The days of tightly coding to a 640kb 4mhz 80286 (the hottest machine 10 years ago with a price tag in the thousands) are over.. and is Bill Gates ever happy.. <smile>.

Luv ya AngelIII.. Thank YOU for conversing.. <smile>

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2643419
Hey wsh2, you are right that processors today are getting faster even (1GHz is approaching), but you can put every processor into knees with bad code.
A single oparetion won't, but if the whole app is badly, poorly and bugly written, you can even have a 4x500 MHz with 512 MB Ram and UW2-SCSI aso, M$ Word will however run slowly for some operations (smile), and you (the human user) will not be able to type text faster (you are sooooo slow) (grin).
I agree that Bill does earn much money with all this...
Don't think this convinces u, but I know some things from experience...
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2643586
AngelIII:
"(the human user) will not be able to type text faster".. Hmmm.. so you have corporate executive types at your place too, huh?.. "Wow.. look at that screen saver go!!!!".. <lol> and a <wink>.

The only point that I try to make.. is to code to the application.. not to the hardware. Gates does this brilliantly, even today.

By the way whatever happened to all those brilliantly crafted 640kb 286 programs that someone so laboriously slaved over tweaking their life away ekeing every ounce of performance out of it? Oooops.. somehow they forgot a timing routine.. and today, they are now done in a blink of an eye.

In many ways.. all of this is but a chicken and egg argument. I abhor spaghetti code.. and poor design.. but then again.. I'm not going to spend a lifetime tweaking my code ad infinitum. Additionally, I will quickly forego performance for readibility / maintainability.. as to ensure the life cycle of the application.. ie.. why do it from scratch again when a major business change occurs.

All in all.. we are BOTH saying the same thing. As you well know.. when you encounter a dog of an application system that management insists on having.. the answer is not to rewrite the code.. but rather buy new hardware. Oh well.. datz life in the corporate lane.. LOL.. Does that executive laptop come with a cell phone?.. LOL.

Great yacking at ya AngelIII.. HKS to a very brilliant and beautiful "young" lady.. a peer to her fellow professionals.. <smile>
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2643594
AngelIII:
Ooops.. "Does that laptop come with a cell phone so I can call my secretary to have this schtuff typed in?.. <wink>
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question