Solved

function overloading

Posted on 2000-03-20
18
2,441 Views
Last Modified: 2013-11-25
is there any way to overload function in vb6?
0
Comment
Question by:makris
  • 8
  • 5
  • 3
  • +1
18 Comments
 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
No.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
Wait for VB7
0
 
LVL 6

Accepted Solution

by:
anthonyc earned 50 total points
Comment Utility
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
 
LVL 10

Expert Comment

by:caraf_g
Comment Utility
The answer still is No.
0
 
LVL 14

Expert Comment

by:wsh2
Comment Utility
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
Comment Utility
<nudge>
0
 
LVL 14

Expert Comment

by:wsh2
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
Comment Utility
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 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
Comment Utility
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 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
Comment Utility
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 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now