• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2454
  • Last Modified:

function overloading

is there any way to overload function in vb6?
0
makris
Asked:
makris
  • 8
  • 5
  • 3
  • +1
1 Solution
 
caraf_gCommented:
No.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Wait for VB7
0
 
anthonycCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
caraf_gCommented:
The answer still is No.
0
 
wsh2Commented:
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
 
caraf_gCommented:
<nudge>
0
 
wsh2Commented:
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
 
anthonycCommented:
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
 
wsh2Commented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
wsh2Commented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
wsh2Commented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
wsh2Commented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
wsh2Commented:
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
 
wsh2Commented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 8
  • 5
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now