473,385 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Function with Different Number of Arguments

I have a client application which is using a specific library. This library can have different versions and I would like to have only one application flexible to be used with all different versions of this library.
My main problem now is that they changed the number of arguments of some specific functions in different versions and I don't know if I can workaround in VB for that.
Example:
Library Version 1, we have:
FuncA(Arg1, Arg2, Arg3) as Boolean
Library Version 2 we have the same but with 4 arguments:
FuncA(Arg1, Arg2, Arg3, Arg4) as Boolean


If I use always 4 arguments I will not be able to compile in using Library Version 1.

Does anyone know if it is possible to have such flexibility in VB?

William Vidal.
May 9 '07 #1
3 1414
Killer42
8,435 Expert 8TB
I don't have much experience in this area. But I wonder, if there is some way you can interrogate the libary for its version, then perhaps you can follow different paths in your VB code. Something along the lines of...
Expand|Select|Wrap|Line Numbers
  1. If Library-Version = 1 Then
  2.   Value = FuncA(Arg1, Arg2, Arg3)
  3. ElseIf Lubrary-Version = 2 Then
  4.   Value = FuncA(Arg1, Arg2, Arg3, Arg4)
  5.  
May 9 '07 #2
Thanks Killer,

But in this way the code will not compile once it will expect to match exactly the number of arguments the library has. In this way you will receive during compilation: "Argument not Optional" in case you are in version 2 of the library (which asks for 4 arguments)
Actually this is a mistake from the library designers, they should have done the library with this new 4th argument as Optional.

But I found a way using Conditional Compilation. Follows the code:

Expand|Select|Wrap|Line Numbers
  1. #Const LibVer1 = "Version 1.0"
  2. #Const LibVer2 = "Version 2.0"
  3.  
  4. Function AuxFuncA(Arg1, Arg2, Arg3, Optional Arg4) as Boolean
  5. Dim CurrentLibVersion as string
  6. 'The Function or method to find out the library version
  7. CurrentLibVersion = GetLibVersion() 
  8.  
  9. 'Now the Compiler Switches
  10. #If CurrentLibVersion = LibVer1 Then
  11.       AuxFuncA = FuncA(Arg1, Arg2, Arg3)
  12. #ElseIf CurrentLibVersion = LibVer2 Then
  13.       AuxFuncA = FuncA(Arg1, Arg2, Arg3, Arg4)
  14. #End If
  15.  
  16. End Function
Then just replace in your code all functions FuncA to AuxFuncA.
The good thing is that with conditional compilation VB will not try to compile this region between #If ... #End If before you are really using it.

Thanks anyway,

William Vidal.
May 9 '07 #3
Killer42
8,435 Expert 8TB
Ah! Good idea.

I didn't realise you had the luxury of running different versions of your program on the different machines.

And yes, I suppose the number of parameters could be a problem at compile time. I wonder whether you could get around it by defining two aliases for the function, with different parameters. I have seen that done to make things safer by defining an alias which constrains certain parameters to certain data types, but never changing the number of parameters (for obvious reasons).
May 9 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
4
by: anonymous | last post by:
Thanks your reply. The article I read is from www.hakin9.org/en/attachments/stackoverflow_en.pdf. And you're right. I don't know it very clearly. And that's why I want to understand it; for it's...
3
by: Randy Yates | last post by:
Hi, We know we can build arrays of variables of the same type and arrays of functions of the same "type" (i.e., same return value and same parameters), but is there a way to automate the calling...
18
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
3
by: carvalho.miguel | last post by:
hello, imagine you have a static class method that receives a function pointer, an int with the number of arguments and a variable number of arguments. in that static method you want to call...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
11
by: Felix Kater | last post by:
Hi, I can compile and run this code (see below) which twice calls the function f, first with too less, second with too much arguments. But is it legal and free of memory leaks and other...
0
by: John O'Hagan | last post by:
On Tue Sep 30 11:32:41 CEST 2008, Steven D'Aprano Thanks, both to you and Bruno for pointing this out, I'll certainly be using it in future.
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.