Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > microsoft.public.scripting.vbscript > #12129 > unrolled thread

Overload a system function like FormatDateTime with a user-defined one ?

Started by"R.Wieser" <address@not.available>
First post2019-05-09 09:23 +0200
Last post2019-05-09 11:39 +0200
Articles 20 on this page of 32 — 4 participants

Back to article view | Back to microsoft.public.scripting.vbscript


Contents

  Overload a system function like FormatDateTime with a user-defined one ? "R.Wieser" <address@not.available> - 2019-05-09 09:23 +0200
    Re: Overload a system function like FormatDateTime with a user-defined one ? GS <gs@v.invalid> - 2019-05-09 05:20 -0400
      Re: Overload a system function like FormatDateTime with a user-defined one ? "R.Wieser" <address@not.available> - 2019-05-09 11:44 +0200
        Re: Overload a system function like FormatDateTime with a user-defined one ? GS <gs@v.invalid> - 2019-05-09 14:33 -0400
          Re: Overload a system function like FormatDateTime with a user-defined one ? "R.Wieser" <address@not.available> - 2019-05-10 09:15 +0200
            Re: Overload a system function like FormatDateTime with a user-defined one ? "Mayayana" <mayayana@invalid.nospam> - 2019-05-10 08:41 -0400
              Re: Overload a system function like FormatDateTime with a user-defined one ? "R.Wieser" <address@not.available> - 2019-05-10 18:11 +0200
                Re: Overload a system function like FormatDateTime with a user-defined one ? GS <gs@v.invalid> - 2019-05-10 13:13 -0400
                  Re: Overload a system function like FormatDateTime with a user-defined one ? "R.Wieser" <address@not.available> - 2019-05-10 20:57 +0200
                    Re: Overload a system function like FormatDateTime with a user-defined one ? GS <gs@v.invalid> - 2019-05-10 15:23 -0400
                      Re: Overload a system function like FormatDateTime with a user-defined one ? "R.Wieser" <address@not.available> - 2019-05-11 09:39 +0200
                        Re: Overload a system function like FormatDateTime with a user-defined one ? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-05-11 11:31 +0200
                          Re: Overload a system function like FormatDateTime with a user-defined one ? "Mayayana" <mayayana@invalid.nospam> - 2019-05-11 06:59 -0400
                Re: Overload a system function like FormatDateTime with a user-defined one ? "Mayayana" <mayayana@invalid.nospam> - 2019-05-10 13:21 -0400
                  Re: Overload a system function like FormatDateTime with a user-defined one ? GS <gs@v.invalid> - 2019-05-10 14:06 -0400
                    Re: Overload a system function like FormatDateTime with a user-defined one ? "R.Wieser" <address@not.available> - 2019-05-10 20:52 +0200
                    Re: Overload a system function like FormatDateTime with a user-defined one ? "Mayayana" <mayayana@invalid.nospam> - 2019-05-10 15:45 -0400
                      Re: Overload a system function like FormatDateTime with a user-defined one ? GS <gs@v.invalid> - 2019-05-10 15:53 -0400
                        Re: Overload a system function like FormatDateTime with a user-defined one ? "R.Wieser" <address@not.available> - 2019-05-11 09:59 +0200
                          Re: Overload a system function like FormatDateTime with a user-defined one ? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-05-11 11:31 +0200
                            Re: Overload a system function like FormatDateTime with a user-defined one ? GS <gs@v.invalid> - 2019-05-11 14:47 -0400
                          Re: Overload a system function like FormatDateTime with a user-defined one ? GS <gs@v.invalid> - 2019-05-11 14:56 -0400
                            Re: Overload a system function like FormatDateTime with a user-defined one ? "R.Wieser" <address@not.available> - 2019-05-11 22:19 +0200
                              Re: Overload a system function like FormatDateTime with a user-defined one ? "R.Wieser" <address@not.available> - 2019-05-12 09:24 +0200
                            Re: Overload a system function like FormatDateTime with a user-defined one ? "Mayayana" <mayayana@invalid.nospam> - 2019-05-11 16:36 -0400
                              Re: Overload a system function like FormatDateTime with a user-defined one ? GS <gs@v.invalid> - 2019-05-11 17:55 -0400
                      Re: Overload a system function like FormatDateTime with a user-defined one ? "R.Wieser" <address@not.available> - 2019-05-11 11:12 +0200
                        Re: Overload a system function like FormatDateTime with a user-defined one ? "Mayayana" <mayayana@invalid.nospam> - 2019-05-11 07:49 -0400
                          Re: Overload a system function like FormatDateTime with a user-defined one ? "R.Wieser" <address@not.available> - 2019-05-11 15:12 +0200
                  Re: Overload a system function like FormatDateTime with a user-defined one ? "R.Wieser" <address@not.available> - 2019-05-10 20:46 +0200
            Re: Overload a system function like FormatDateTime with a user-defined one ? GS <gs@v.invalid> - 2019-05-10 13:28 -0400
    Re: Overload a system function like FormatDateTime with a user-defined one ? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-05-09 11:39 +0200

Page 1 of 2  [1] 2  Next page →


#12129 — Overload a system function like FormatDateTime with a user-defined one ?

From"R.Wieser" <address@not.available>
Date2019-05-09 09:23 +0200
SubjectOverload a system function like FormatDateTime with a user-defined one ?
Message-ID<qb0khc$1onn$1@gioia.aioe.org>
Hello all,

I'm using timestamps and wanted to display them in a certain way.  Though 
when I took a look at "FormatDateTime" I found I could only have it return 
one of five pre-defined formats, none of which served my purpose.   So I 
wrote my own, using a formatting string.

The thing is, the name of the system function is quite appropriate for what 
my function is doing: FormatDateTime.

tl;dr:
Can I have the VBScript engine pick the right function depending on the 
types of the provided arguments ?

I don't think its possible, but it doesn't hurt to ask. :-)

Regards,
Rudy Wieser


[toc] | [next] | [standalone]


#12130

FromGS <gs@v.invalid>
Date2019-05-09 05:20 -0400
Message-ID<qb0rc7$l70$1@dont-email.me>
In reply to#12129
> Hello all,
>
> I'm using timestamps and wanted to display them in a certain way.  Though 
> when I took a look at "FormatDateTime" I found I could only have it return 
> one of five pre-defined formats, none of which served my purpose.   So I 
> wrote my own, using a formatting string.
>
> The thing is, the name of the system function is quite appropriate for what 
> my function is doing: FormatDateTime.
>
> tl;dr:
> Can I have the VBScript engine pick the right function depending on the types 
> of the provided arguments ?
>
> I don't think its possible, but it doesn't hurt to ask. :-)
>
> Regards,
> Rudy Wieser

Whenever I name a VB UDF after an existing one I use an underscore like so...

  Public Function Format_DateTime$(iFormat%)

..where iFormat specifies the index of the pre-defined (string) formats to use 
according to their (named) position in an Enum. You can remove the Type symbols 
for use with VBS.

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#12132

From"R.Wieser" <address@not.available>
Date2019-05-09 11:44 +0200
Message-ID<qb0spu$v8s$1@gioia.aioe.org>
In reply to#12130
GS,

> Whenever I name a VB UDF after an existing one I use an underscore like 
> so...

Yes, naming the function differently is ofcourse the easiest solution. 
Currently I've named my function "GetDateFormatted" - which does pretty much 
cover what its doing.

But I really would like to know if VBScript knows (how to handle) function 
overloading.


... Or even if it knows how to replace a system function and still be able 
to call the replaced one (something I saw used in another langueage).

Regards,
Rudy Wieser


[toc] | [prev] | [next] | [standalone]


#12133

FromGS <gs@v.invalid>
Date2019-05-09 14:33 -0400
Message-ID<qb1rp7$438$1@dont-email.me>
In reply to#12132
> GS,
>
>> Whenever I name a VB UDF after an existing one I use an underscore like 
>> so...
>
> Yes, naming the function differently is ofcourse the easiest solution. 
> Currently I've named my function "GetDateFormatted" - which does pretty much 
> cover what its doing.
>
> But I really would like to know if VBScript knows (how to handle) function 
> overloading.
>
>
> ... Or even if it knows how to replace a system function and still be able to 
> call the replaced one (something I saw used in another langueage).
>
> Regards,
> Rudy Wieser

My impression is that MS is looking to deprecate VBS in favor of something more 
suitable for web apps and so I doubt they'll want to 'upgrade' VBS with 
function/method overloading features. Home-grown is the way to go as I see it!

Now you can build your own overloaded functions for C# (and some of the other 
languages), but not to work/run like a VBS script.

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#12134

From"R.Wieser" <address@not.available>
Date2019-05-10 09:15 +0200
Message-ID<qb38eh$1i4i$1@gioia.aioe.org>
In reply to#12133
GS,

> My impression is that MS is looking to deprecate VBS in favor of something 
> more suitable for web apps and so I doubt they'll want to 'upgrade' VBS 
> with function/method overloading features.

I think there is some kind of misunderstanding here.  I just wanted to know 
if its (or something like it) available /now/.

> Home-grown is the way to go as I see it!

So ?   Any other methods available to create the same effect (even just to 
see if its possible) ?

Regards,
Rudy Wieser

[toc] | [prev] | [next] | [standalone]


#12135

From"Mayayana" <mayayana@invalid.nospam>
Date2019-05-10 08:41 -0400
Message-ID<qb3rme$5et$1@dont-email.me>
In reply to#12134
"R.Wieser" <address@not.available> wrote

| So ?   Any other methods available to create the same effect (even just to
| see if its possible) ?
|

  VB has optional parameters, but not VBS. Personally
I think it's a very dumb idea, lending itself to errors.
So I've never actually used an optional parameter.
But that's just my preference.

  I have used multi-purpose functions. For instance:

ProcessThisText(sTheText, TheTarget)

  Where TheTarget would probably be a numeric value.
For instance, if I needed to same function to prepare
text strings for multiple text windows, TheTarget could
be used to specify which window it goes to.

  I'm curious what you want to do. It's hard for me
to imagine a necessary purpose for such tricky ambiguity
in function design. 

[toc] | [prev] | [next] | [standalone]


#12136

From"R.Wieser" <address@not.available>
Date2019-05-10 18:11 +0200
Message-ID<qb47sb$342$1@gioia.aioe.org>
In reply to#12135
Mayayana,

>  I'm curious what you want to do.

In that case I would suggest you (re)read my initial message.  I explained 
it there.

But in short: To add functionality to an already existing function.  In this 
case, a formatting string to complement a few numeric options.

> It's hard for me to imagine a necessary purpose
> for such tricky ambiguity in function design.

:-) Than I hope you never try your hand at a language like one of the C 
{something} variants, as they are rather common there.

But to give an example:
FormatDateTime(date, value) 'system function
FormatDateTime(date, formatting string) 'my function

Regards,
Rudy Wieser

[toc] | [prev] | [next] | [standalone]


#12137

FromGS <gs@v.invalid>
Date2019-05-10 13:13 -0400
Message-ID<qb4bfq$6j4$1@dont-email.me>
In reply to#12136
> But to give an example:
> FormatDateTime(date, value) 'system function
> FormatDateTime(date, formatting string) 'my function

This is what I was trying to pass along!

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#12143

From"R.Wieser" <address@not.available>
Date2019-05-10 20:57 +0200
Message-ID<qb4hi4$1euo$3@gioia.aioe.org>
In reply to#12137
GS,

>> But to give an example:
>> FormatDateTime(date, value) 'system function
>> FormatDateTime(date, formatting string) 'my function
>
> This is what I was trying to pass along!

WHAT where you trying to pass along ?

Because when I declare /my/ "FormatDateTime" function I will lose access to
the system function.    Something I do NOT want.  Which I tried to make
clear in my second post with "and still be able to call the replaced one".

So, all I need now is how to call the origional, replaced function.   Can 
you at least pass /that/ along ?   'Cause without it being able to replace 
a(n origional) system function is /absolutily worthless/ to me.

Regards,
Rudy Wieser


[toc] | [prev] | [next] | [standalone]


#12144

FromGS <gs@v.invalid>
Date2019-05-10 15:23 -0400
Message-ID<qb4j32$n9e$1@dont-email.me>
In reply to#12143
> GS,
>
>>> But to give an example:
>>> FormatDateTime(date, value) 'system function
>>> FormatDateTime(date, formatting string) 'my function
>>
>> This is what I was trying to pass along!
>
> WHAT where you trying to pass along ?
>
> Because when I declare /my/ "FormatDateTime" function I will lose access to
> the system function.    Something I do NOT want.  Which I tried to make
> clear in my second post with "and still be able to call the replaced one".
>
> So, all I need now is how to call the origional, replaced function.   Can you 
> at least pass /that/ along ?   'Cause without it being able to replace a(n 
> origional) system function is /absolutily worthless/ to me.
>
> Regards,
> Rudy Wieser

Ok, I'll try to explain more clearly...

My Format_DateTime$(iFormat%) function takes the iFormat arg and puts it to a 
Select Case struct that returns the desired date or time format. This in turn 
sets a global date or time variable to that format which in turn is used by the 
project thereafter.

I assume that what you want is a procedure to take a DateTime value and return 
it in a specific string format -OR- specific Date format IN A SINGLE function 
as you could do in a language that supports using several methods with a SINGLE 
NAME as .NET Framework class method 'overloads'.

I'm just proposing a single multi-task function to do the same thing! You just 
need to change your mindset FROM thinking 'overloading' a method TO using 
'multi-task' functions instead!

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#12147

From"R.Wieser" <address@not.available>
Date2019-05-11 09:39 +0200
Message-ID<qb5vds$1jqb$1@gioia.aioe.org>
In reply to#12144
GS,

> Ok, I'll try to explain more clearly...
>
> My Format_DateTime$(iFormat%) function

And I'll stop you just there.  Using two functions with different names is 
NOT in any way what I asked for.

In my posted example you see two calls USING THE SAME FUNCTION NAME.  One of 
those calls is supposed to go to the system function, the other to a 
function I wrote myself.

/How/ that can be made possible is upto debate.  Nothing else.

> I'm just proposing a single multi-task function to do
> the same thing!

1) You should have made that a bit more clear.  Maybe like "I have no idea 
how to do what you're asking for but maybe you can use the following 
instead".  To which I than would have answered: (see #2).

2) It would be rather stupid to call that new function only to have it call 
the actual function instead of just calling the actual function directly.

The whole idea of overloading is to /extend the capabilities/ of a certain 
(build-in) function.   Definitily /not/ to just introduce complexity where 
none is needed.


As for the "something like it" I mentioned ?     That was in regard to when 
only a /replace/ of the the function would be possible (as it appears to be 
with VBScript), but than being able to call the replaced (build-in) function 
anyway (do you know how ?).  Like some other languages do by adding a 
certain prefix to the function name, which than always refers to the 
build-in function table.

But, maybe even by a much simpler "call the replaced function" (parent?) 
construction (which would also allow for the stacking of function 
replacements).

Do /I/ now have made myself clear ?

Regards,
Rudy Wieser

[toc] | [prev] | [next] | [standalone]


#12150

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2019-05-11 11:31 +0200
Message-ID<XnsAA4C752A88FEAeejj99@194.109.6.166>
In reply to#12147
"R.Wieser" <address@not.available> wrote on 11 May 2019 in 
microsoft.public.scripting.vbscript:

> /How/ that can be made possible is upto debate.  Nothing else.

You are severely mistaken in the use of usenet NGs.

You are not in charge of a thread, even if you are the OP.

> 2) It would be rather stupid to call that new function only to have it 
> call the actual function instead of just calling the actual function 
> directly.

No, It would not.

This is often done in scripts.

For instance to make intricate debugging possible, 
and [temporarily or finally] remark-out such.




-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#12152

From"Mayayana" <mayayana@invalid.nospam>
Date2019-05-11 06:59 -0400
Message-ID<qb6a1k$o53$1@dont-email.me>
In reply to#12150
"Evertjan." <exxjxw.hannivoort@inter.nl.net> wrote

| > 2) It would be rather stupid to call that new function only to have it
| > call the actual function instead of just calling the actual function
| > directly.
|
| No, It would not.
|
| This is often done in scripts.
|
| For instance to make intricate debugging possible,
| and [temporarily or finally] remark-out such.
|

  And, of course, that's basically the role of a function:
to call a series of other functions in order to accomplish
a task.

[toc] | [prev] | [next] | [standalone]


#12138

From"Mayayana" <mayayana@invalid.nospam>
Date2019-05-10 13:21 -0400
Message-ID<qb4c2p$a5o$1@dont-email.me>
In reply to#12136
"R.Wieser" <address@not.available> wrote

| But to give an example:
| FormatDateTime(date, value) 'system function
| FormatDateTime(date, formatting string) 'my function
|

  I guess I don't get it. Overloading would be to
have one function work differently depending on
parameters. You're just asking if you can use
an existing keyword or function name and somehow
hope that WSH doesn't notice. 

[toc] | [prev] | [next] | [standalone]


#12140

FromGS <gs@v.invalid>
Date2019-05-10 14:06 -0400
Message-ID<qb4ek4$qp5$1@dont-email.me>
In reply to#12138
> "R.Wieser" <address@not.available> wrote
>
>> But to give an example:
>> FormatDateTime(date, value) 'system function
>> FormatDateTime(date, formatting string) 'my function
>> 
>
>   I guess I don't get it. Overloading would be to
> have one function work differently depending on
> parameters. You're just asking if you can use
> an existing keyword or function name and somehow
> hope that WSH doesn't notice. 

Overloading in the current C languages supports multiple methods with the same 
name but different parameters; - which combo of params you use determines which 
version the compiler uses.

I've been doing similar in VB_ projects for years by passing an action index to 
a single function to tell it what to do; - the function may also have other 
args but the only one I use for Format_DateTime() is an index to tell it which 
date or time format to return.

I'm in the process of converting all my stuff to C# and so far all is going 
well. While it's possible to convert my multi-task functions to overloaded 
ones, I don't yet see their point (other than to simplify naming and persist 
further support of unnecessary bloating)! Single multi-task functions use 
'Case' branching for actions to take for a common purpose. For example, my 
GetInfo_FromWMI() function contains all the code necessary for all the various 
WMI queries I use for my licensing methodology to return a delimited string for 
a license profile MachineID property consisting of:

   Make, Model, Mainboard SerialNumber,BIOS SerialNumber

The process involves using GoTo statements to control the order the info is 
collected from the various WMI classes when the 'Case' statements don't 
necessarily follow any order. This has been working well for 15+ years and so I 
don't see any point in 'breaking' it just because the .NET Framework supports 
the 'new and improved' feature of method overloading.

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#12142

From"R.Wieser" <address@not.available>
Date2019-05-10 20:52 +0200
Message-ID<qb4hi2$1euo$2@gioia.aioe.org>
In reply to#12140
"GS" <gs@v.invalid> wrote in message news:qb4ek4$qp5$1@dont-email.me...
>> "R.Wieser" <address@not.available> wrote
>>
>>> But to give an example:
>>> FormatDateTime(date, value) 'system function
>>> FormatDateTime(date, formatting string) 'my function
>>>
>>
>>   I guess I don't get it. Overloading would be to
>> have one function work differently depending on
>> parameters. You're just asking if you can use
>> an existing keyword or function name and somehow
>> hope that WSH doesn't notice.

Garry, you should be carefull how you're quoting.

In the above I said whats behind the ">>>" prefixes, Mayayana said whats 
behind the ">>" ones.

The way you made it look is that someone you didn't mention said whats 
behind the ">>>" prefixes, and /I/ said whats behind the ">>" ones. :-(

Regards,
Rudy Wieser

[toc] | [prev] | [next] | [standalone]


#12145

From"Mayayana" <mayayana@invalid.nospam>
Date2019-05-10 15:45 -0400
Message-ID<qb4kgn$vtg$1@dont-email.me>
In reply to#12140
"GS" <gs@v.invalid> wrote

| Overloading in the current C languages supports multiple methods with the 
same
| name but different parameters; - which combo of params you use determines 
which
| version the compiler uses.
|

  I get that, but it's not what Rudy was trying to do.
He's just asking for a way to name his function with
a name already taken.

| I've been doing similar in VB_ projects for years by passing an action 
index to
| a single function to tell it what to do;

  Yes, I do that, too. Much less prone to confusion
than overloading. 

[toc] | [prev] | [next] | [standalone]


#12146

FromGS <gs@v.invalid>
Date2019-05-10 15:53 -0400
Message-ID<qb4kr4$268$1@dont-email.me>
In reply to#12145
> He's just asking for a way to name his function with
> a name already taken.

Yes, I get that BUT VB_ doesn't support it and so an alternative must be used. 
I prefer a single multi-task function over individual task-specific procedures 
and so why I'm suggesting the described approach.<g>

-- 
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
  comp.lang.basic.visual.misc
  microsoft.public.vb.general.discussion

[toc] | [prev] | [next] | [standalone]


#12148

From"R.Wieser" <address@not.available>
Date2019-05-11 09:59 +0200
Message-ID<qb5vds$1jqb$2@gioia.aioe.org>
In reply to#12146
GS,

> Yes, I get that BUT VB_ doesn't support it and so an alternative must be 
> used.

THAT should have been the first thing you should have said, /before/ 
suggesting your alternative solution.

... I would not have believed you on your word (VBS does allow function 
replacing, and it stands to reason the developers would have realized the 
problems that that would cause when replacing build-in functions and likely 
created a solution for it), but it would than have been clear where your 
suggestion came from.

But for the record: If I am able to create a date/time formatting function 
using a formatting string (as I mentioned in my first post) than don't you 
think I would likely be able to come up with a 'write another function and 
decide there what to actually do' myself ?   Writing such a (switch case ? 
if-else if ?) function isn't really rocket science you know ... :-)

Regards,
Rudy Wieser

[toc] | [prev] | [next] | [standalone]


#12151

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2019-05-11 11:31 +0200
Message-ID<XnsAA4C754C0D13Deejj99@194.109.6.166>
In reply to#12148
"R.Wieser" <address@not.available> wrote on 11 May 2019 in 
microsoft.public.scripting.vbscript:

>> Yes, I get that BUT VB_ doesn't support it and so an alternative must be 
>> used.
> 
> THAT should have been the first thing you should have said, /before/ 
> suggesting your alternative solution.

More important. VB is off topic, this NG is about VBS.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | microsoft.public.scripting.vbscript


csiph-web