Jump to content

pass one variable as multiple arguments of a function call


Recommended Posts

I would like to know if I can do this in one pass (example #1) rather than three passes (example #2):

#include <date.au3>

$datetime='2013-09-05 10:21'
$date=StringRegExpReplace($datetime, '.*?([^-+]*?)-([^-+]*?)-([^ ]*?) .*$', '"$1","$2","$3"')

$Dayofwk=_DateToDayOfWeek($date)

... leads to "Incorrect number of parameters in function call.".

#include <date.au3>

$datetime='2013-09-05 10:21'

$Y=StringRegExpReplace($End_Time, '.*?([^-+]*?)-([^-+]*?)-([^ ]*?) .*$', '$1')
$M=StringRegExpReplace($End_Time, '.*?([^-+]*?)-([^-+]*?)-([^ ]*?) .*$', '$2')
$D=StringRegExpReplace($End_Time, '.*?([^-+]*?)-([^-+]*?)-([^ ]*?) .*$', '$3')

$Dayofwk=_DateToDayOfWeek($Y,$M,$D)

... works as expected.

Link to comment
Share on other sites

This StringRegExp function put all digit sequences into an array.

The first three elements of the array will be year, month, and day.

These three elements of the array make up the three parameters of the _DateToDayOfWeek function.

#include <date.au3>
;#include <Array.au3> ; For _ArrayDisplay only

Local $datetime = '2013-09-05 10:21'
Local $aDate = StringRegExp($datetime, '\d+', 3)
;_ArrayDisplay($aDate)

Local $Dayofwk = _DateToDayOfWeek($aDate[0], $aDate[1], $aDate[2])

ConsoleWrite($Dayofwk & @LF) ; Returns 5
ConsoleWrite(_DateDayOfWeek($Dayofwk) & @LF) ; Returns Thursday
Link to comment
Share on other sites

Think about it, you are providing one parameter. A comma inside that string is just that ... a comma in a string. All you are really passing is a string. If you wanted to get the three required parameters from your string, you could have used StringSplit with the comma as delimiter.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...