Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Why the Value not able to Pass to a Function

Reply
 
Old 12-10-2007   #1 (permalink)
Peter Sun


 
 

Why the Value not able to Pass to a Function

Hi,

Here I have a code that do not pass the value to the function, which is
below

$tempString='http://xxx.com'

$sqlString="select id from urlScreenLog where screennedURL='$tempString'"
$ScreenlogID = QueryScreenLog $sqlString

Function QueryScreenLog([string]$queyString)
{
$mycommand.CommandText = $queyString
$myreader = $mycommand.ExecuteReader()
}

in the function, $queyString is always "select id from urlScreenLog where
screennedURL=''", not like what I want

"select id from urlScreenLog where screennedURL='http://xxx.com'"


Any help? I appreciated it!

Peter



My System SpecsSystem Spec
Old 12-10-2007   #2 (permalink)
Jon


 
 

Re: Why the Value not able to Pass to a Function

Try an 'escape character' (small tick below the top left 'esc' key on the
keyboard) before the single quotes eg

$sqlString = "select id from urlScreenLog where
screennedURL=`'$tempString`'"

--
Jon


"Peter Sun" <koarla@xxxxxx> wrote in message
news:%23tf9aE1OIHA.4440@xxxxxx
Quote:

> Hi,
>
> Here I have a code that do not pass the value to the function, which is
> below
>
> $tempString='http://xxx.com'
>
> $sqlString="select id from urlScreenLog where screennedURL='$tempString'"
> $ScreenlogID = QueryScreenLog $sqlString
>
> Function QueryScreenLog([string]$queyString)
> {
> $mycommand.CommandText = $queyString
> $myreader = $mycommand.ExecuteReader()
> }
>
> in the function, $queyString is always "select id from urlScreenLog where
> screennedURL=''", not like what I want
>
> "select id from urlScreenLog where screennedURL='http://xxx.com'"
>
>
> Any help? I appreciated it!
>
> Peter
>
My System SpecsSystem Spec
Old 12-10-2007   #3 (permalink)
Jon


 
 

Re: Why the Value not able to Pass to a Function

Looking at it again, I think it's more of an order issue....

Define your function before you call it - that's one of the idiosyncracies
of PowerShell

ie


Function QueryScreenLog([string]$queyString)
{
$mycommand.CommandText = $queyString
$myreader = $mycommand.ExecuteReader()
}

$sqlString="select id from urlScreenLog where screennedURL='$tempString'"
$ScreenlogID = QueryScreenLog $sqlString



--
Jon


"Jon" <Email_Address@xxxxxx> wrote in message
news:e$Hc$K1OIHA.5264@xxxxxx
Quote:

> Try an 'escape character' (small tick below the top left 'esc' key on the
> keyboard) before the single quotes eg
>
> $sqlString = "select id from urlScreenLog where
> screennedURL=`'$tempString`'"
>
> --
> Jon
>
>
> "Peter Sun" <koarla@xxxxxx> wrote in message
> news:%23tf9aE1OIHA.4440@xxxxxx
Quote:

>> Hi,
>>
>> Here I have a code that do not pass the value to the function, which is
>> below
>>
>> $tempString='http://xxx.com'
>>
>> $sqlString="select id from urlScreenLog where screennedURL='$tempString'"
>> $ScreenlogID = QueryScreenLog $sqlString
>>
>> Function QueryScreenLog([string]$queyString)
>> {
>> $mycommand.CommandText = $queyString
>> $myreader = $mycommand.ExecuteReader()
>> }
>>
>> in the function, $queyString is always "select id from urlScreenLog where
>> screennedURL=''", not like what I want
>>
>> "select id from urlScreenLog where screennedURL='http://xxx.com'"
>>
>>
>> Any help? I appreciated it!
>>
>> Peter
>>
>
My System SpecsSystem Spec
Old 12-10-2007   #4 (permalink)
Peter Sun


 
 

Re: Why the Value not able to Pass to a Function

Thank you fro you reply, Jon,

I looked back to the code a again, what I found the value is in the
$tempString,
but what refer to the $sqlString, then I found

$sqlString="select id from urlScreenLog where screennedURL=''".

I already put the function in front making call.

let me do more test and try different way.


Peter


"Jon" <Email_Address@xxxxxx> wrote in message
news:e64eiS1OIHA.5980@xxxxxx
Quote:

> Looking at it again, I think it's more of an order issue....
>
> Define your function before you call it - that's one of the idiosyncracies
> of PowerShell
>
> ie
>
>
> Function QueryScreenLog([string]$queyString)
> {
> $mycommand.CommandText = $queyString
> $myreader = $mycommand.ExecuteReader()
> }
>
> $sqlString="select id from urlScreenLog where screennedURL='$tempString'"
> $ScreenlogID = QueryScreenLog $sqlString
>
>
>
> --
> Jon
>
>
> "Jon" <Email_Address@xxxxxx> wrote in message
> news:e$Hc$K1OIHA.5264@xxxxxx
Quote:

>> Try an 'escape character' (small tick below the top left 'esc' key on
>> the keyboard) before the single quotes eg
>>
>> $sqlString = "select id from urlScreenLog where
>> screennedURL=`'$tempString`'"
>>
>> --
>> Jon
>>
>>
>> "Peter Sun" <koarla@xxxxxx> wrote in message
>> news:%23tf9aE1OIHA.4440@xxxxxx
Quote:

>>> Hi,
>>>
>>> Here I have a code that do not pass the value to the function, which is
>>> below
>>>
>>> $tempString='http://xxx.com'
>>>
>>> $sqlString="select id from urlScreenLog where
>>> screennedURL='$tempString'"
>>> $ScreenlogID = QueryScreenLog $sqlString
>>>
>>> Function QueryScreenLog([string]$queyString)
>>> {
>>> $mycommand.CommandText = $queyString
>>> $myreader = $mycommand.ExecuteReader()
>>> }
>>>
>>> in the function, $queyString is always "select id from urlScreenLog
>>> where screennedURL=''", not like what I want
>>>
>>> "select id from urlScreenLog where screennedURL='http://xxx.com'"
>>>
>>>
>>> Any help? I appreciated it!
>>>
>>> Peter
>>>
>>
>

My System SpecsSystem Spec
Old 12-10-2007   #5 (permalink)
Jon


 
 

Re: Why the Value not able to Pass to a Function

Yeah give it another go. Post back if you can't get it resolved. There are
many helpful people in this group, who I'm sure will be able to get it
running smoothly, if not.

--
Jon


"Peter Sun" <koarla@xxxxxx> wrote in message
news:OOSFPi1OIHA.4688@xxxxxx
Quote:

> Thank you fro you reply, Jon,
>
> I looked back to the code a again, what I found the value is in the
> $tempString,
> but what refer to the $sqlString, then I found
>
> $sqlString="select id from urlScreenLog where screennedURL=''".
>
> I already put the function in front making call.
>
> let me do more test and try different way.
>
>
> Peter
>
>
> "Jon" <Email_Address@xxxxxx> wrote in message
> news:e64eiS1OIHA.5980@xxxxxx
Quote:

>> Looking at it again, I think it's more of an order issue....
>>
>> Define your function before you call it - that's one of the
>> idiosyncracies of PowerShell
>>
>> ie
>>
>>
>> Function QueryScreenLog([string]$queyString)
>> {
>> $mycommand.CommandText = $queyString
>> $myreader = $mycommand.ExecuteReader()
>> }
>>
>> $sqlString="select id from urlScreenLog where screennedURL='$tempString'"
>> $ScreenlogID = QueryScreenLog $sqlString
>>
>>
>>
>> --
>> Jon
>>
>>
>> "Jon" <Email_Address@xxxxxx> wrote in message
>> news:e$Hc$K1OIHA.5264@xxxxxx
Quote:

>>> Try an 'escape character' (small tick below the top left 'esc' key on
>>> the keyboard) before the single quotes eg
>>>
>>> $sqlString = "select id from urlScreenLog where
>>> screennedURL=`'$tempString`'"
>>>
>>> --
>>> Jon
>>>
>>>
>>> "Peter Sun" <koarla@xxxxxx> wrote in message
>>> news:%23tf9aE1OIHA.4440@xxxxxx
>>>> Hi,
>>>>
>>>> Here I have a code that do not pass the value to the function, which is
>>>> below
>>>>
>>>> $tempString='http://xxx.com'
>>>>
>>>> $sqlString="select id from urlScreenLog where
>>>> screennedURL='$tempString'"
>>>> $ScreenlogID = QueryScreenLog $sqlString
>>>>
>>>> Function QueryScreenLog([string]$queyString)
>>>> {
>>>> $mycommand.CommandText = $queyString
>>>> $myreader = $mycommand.ExecuteReader()
>>>> }
>>>>
>>>> in the function, $queyString is always "select id from urlScreenLog
>>>> where screennedURL=''", not like what I want
>>>>
>>>> "select id from urlScreenLog where screennedURL='http://xxx.com'"
>>>>
>>>>
>>>> Any help? I appreciated it!
>>>>
>>>> Peter
>>>>
>>>
>>
>
>
>
My System SpecsSystem Spec
Old 12-10-2007   #6 (permalink)
Peter Sun


 
 

Re: Why the Value not able to Pass to a Function

Hi, Jon,

Thank you so much, and I know here always have a lot of kinds of people and
helpful.

I figured the problem out, it come from the statement of calling function, I
was using

$ScreenlogID = QueryScreenLog $a,$sqlString, $b

So, powershell just pass the first one varible $a.

Thanks again.

Peter




"Jon" <Email_Address@xxxxxx> wrote in message
news:OkqFrs1OIHA.5360@xxxxxx
Quote:

> Yeah give it another go. Post back if you can't get it resolved. There are
> many helpful people in this group, who I'm sure will be able to get it
> running smoothly, if not.
>
> --
> Jon
>
>
> "Peter Sun" <koarla@xxxxxx> wrote in message
> news:OOSFPi1OIHA.4688@xxxxxx
Quote:

>> Thank you fro you reply, Jon,
>>
>> I looked back to the code a again, what I found the value is in the
>> $tempString,
>> but what refer to the $sqlString, then I found
>>
>> $sqlString="select id from urlScreenLog where screennedURL=''".
>>
>> I already put the function in front making call.
>>
>> let me do more test and try different way.
>>
>>
>> Peter
>>
>>
>> "Jon" <Email_Address@xxxxxx> wrote in message
>> news:e64eiS1OIHA.5980@xxxxxx
Quote:

>>> Looking at it again, I think it's more of an order issue....
>>>
>>> Define your function before you call it - that's one of the
>>> idiosyncracies of PowerShell
>>>
>>> ie
>>>
>>>
>>> Function QueryScreenLog([string]$queyString)
>>> {
>>> $mycommand.CommandText = $queyString
>>> $myreader = $mycommand.ExecuteReader()
>>> }
>>>
>>> $sqlString="select id from urlScreenLog where
>>> screennedURL='$tempString'"
>>> $ScreenlogID = QueryScreenLog $sqlString
>>>
>>>
>>>
>>> --
>>> Jon
>>>
>>>
>>> "Jon" <Email_Address@xxxxxx> wrote in message
>>> news:e$Hc$K1OIHA.5264@xxxxxx
>>>> Try an 'escape character' (small tick below the top left 'esc' key on
>>>> the keyboard) before the single quotes eg
>>>>
>>>> $sqlString = "select id from urlScreenLog where
>>>> screennedURL=`'$tempString`'"
>>>>
>>>> --
>>>> Jon
>>>>
>>>>
>>>> "Peter Sun" <koarla@xxxxxx> wrote in message
>>>> news:%23tf9aE1OIHA.4440@xxxxxx
>>>>> Hi,
>>>>>
>>>>> Here I have a code that do not pass the value to the function, which
>>>>> is below
>>>>>
>>>>> $tempString='http://xxx.com'
>>>>>
>>>>> $sqlString="select id from urlScreenLog where
>>>>> screennedURL='$tempString'"
>>>>> $ScreenlogID = QueryScreenLog $sqlString
>>>>>
>>>>> Function QueryScreenLog([string]$queyString)
>>>>> {
>>>>> $mycommand.CommandText = $queyString
>>>>> $myreader = $mycommand.ExecuteReader()
>>>>> }
>>>>>
>>>>> in the function, $queyString is always "select id from urlScreenLog
>>>>> where screennedURL=''", not like what I want
>>>>>
>>>>> "select id from urlScreenLog where screennedURL='http://xxx.com'"
>>>>>
>>>>>
>>>>> Any help? I appreciated it!
>>>>>
>>>>> Peter
>>>>>
>>>>
>>>
>>
>>
>>
>

My System SpecsSystem Spec
Old 12-10-2007   #7 (permalink)
Peter Sun


 
 

Re: Why the Value not able to Pass to a Function

I should use
$ScreenlogID = QueryScreenLog $a $sqlString $b
No Comma


"Peter Sun" <koarla@xxxxxx> wrote in message
news:O1c%23qp2OIHA.5524@xxxxxx
Quote:

> Hi, Jon,
>
> Thank you so much, and I know here always have a lot of kinds of people
> and helpful.
>
> I figured the problem out, it come from the statement of calling function,
> I was using
>
> $ScreenlogID = QueryScreenLog $a,$sqlString, $b
>
> So, powershell just pass the first one varible $a.
>
> Thanks again.
>
> Peter
>
>
>
>
> "Jon" <Email_Address@xxxxxx> wrote in message
> news:OkqFrs1OIHA.5360@xxxxxx
Quote:

>> Yeah give it another go. Post back if you can't get it resolved. There
>> are many helpful people in this group, who I'm sure will be able to get
>> it running smoothly, if not.
>>
>> --
>> Jon
>>
>>
>> "Peter Sun" <koarla@xxxxxx> wrote in message
>> news:OOSFPi1OIHA.4688@xxxxxx
Quote:

>>> Thank you fro you reply, Jon,
>>>
>>> I looked back to the code a again, what I found the value is in the
>>> $tempString,
>>> but what refer to the $sqlString, then I found
>>>
>>> $sqlString="select id from urlScreenLog where screennedURL=''".
>>>
>>> I already put the function in front making call.
>>>
>>> let me do more test and try different way.
>>>
>>>
>>> Peter
>>>
>>>
>>> "Jon" <Email_Address@xxxxxx> wrote in message
>>> news:e64eiS1OIHA.5980@xxxxxx
>>>> Looking at it again, I think it's more of an order issue....
>>>>
>>>> Define your function before you call it - that's one of the
>>>> idiosyncracies of PowerShell
>>>>
>>>> ie
>>>>
>>>>
>>>> Function QueryScreenLog([string]$queyString)
>>>> {
>>>> $mycommand.CommandText = $queyString
>>>> $myreader = $mycommand.ExecuteReader()
>>>> }
>>>>
>>>> $sqlString="select id from urlScreenLog where
>>>> screennedURL='$tempString'"
>>>> $ScreenlogID = QueryScreenLog $sqlString
>>>>
>>>>
>>>>
>>>> --
>>>> Jon
>>>>
>>>>
>>>> "Jon" <Email_Address@xxxxxx> wrote in message
>>>> news:e$Hc$K1OIHA.5264@xxxxxx
>>>>> Try an 'escape character' (small tick below the top left 'esc' key on
>>>>> the keyboard) before the single quotes eg
>>>>>
>>>>> $sqlString = "select id from urlScreenLog where
>>>>> screennedURL=`'$tempString`'"
>>>>>
>>>>> --
>>>>> Jon
>>>>>
>>>>>
>>>>> "Peter Sun" <koarla@xxxxxx> wrote in message
>>>>> news:%23tf9aE1OIHA.4440@xxxxxx
>>>>>> Hi,
>>>>>>
>>>>>> Here I have a code that do not pass the value to the function, which
>>>>>> is below
>>>>>>
>>>>>> $tempString='http://xxx.com'
>>>>>>
>>>>>> $sqlString="select id from urlScreenLog where
>>>>>> screennedURL='$tempString'"
>>>>>> $ScreenlogID = QueryScreenLog $sqlString
>>>>>>
>>>>>> Function QueryScreenLog([string]$queyString)
>>>>>> {
>>>>>> $mycommand.CommandText = $queyString
>>>>>> $myreader = $mycommand.ExecuteReader()
>>>>>> }
>>>>>>
>>>>>> in the function, $queyString is always "select id from urlScreenLog
>>>>>> where screennedURL=''", not like what I want
>>>>>>
>>>>>> "select id from urlScreenLog where screennedURL='http://xxx.com'"
>>>>>>
>>>>>>
>>>>>> Any help? I appreciated it!
>>>>>>
>>>>>> Peter
>>>>>>
>>>>>
>>>>
>>>
>>>
>>>
>>
>
>

My System SpecsSystem Spec
Old 12-10-2007   #8 (permalink)
Shay Levi


 
 

Re: Why the Value not able to Pass to a Function

Hi Peter

You can safely expand '$tempString' as long as it's embeded in a double quoted
string.
So this is acceptable:

PS> $tempString='http://xxx.com'
PS> $sqlString="select id from urlScreenLog where screennedURL='$tempString'"

PS> $sqlString
PS> select id from urlScreenLog where screennedURL='http://xxx.com'

As you can see $sqlString contains the expanded value of $tempString.
But you can't do it the opposite way, single quoted strings disables variable
expansion:

PS> $tempString='http://xxx.com'
PS> $sqlString='select id from urlScreenLog where screennedURL="$tempString"'

PS> $sqlString
select id from urlScreenLog where screennedURL="$tempString"


As Jon said, you should declare your functions prior to calling them.
Another issue, generally (depend on what your goal is), when passing arguments
to a function you should delimit each argument
with a space (positional parameter syntax), as in:

$ScreenlogID = QueryScreenLog $a $sqlString $b

To avoid arguments mismatch you can write the full syntax to your function:

$ScreenlogID = QueryScreenLog -queyString $sqlString

Which should be -queryString ;-) (typo)


Lastly, check out PowerShell help:

help about_parameter



Hope This Helps


-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic


Quote:

> Hi, Jon,
>
> Thank you so much, and I know here always have a lot of kinds of
> people and helpful.
>
> I figured the problem out, it come from the statement of calling
> function, I was using
>
> $ScreenlogID = QueryScreenLog $a,$sqlString, $b
>
> So, powershell just pass the first one varible $a.
>
> Thanks again.
>
> Peter
>
> "Jon" <Email_Address@xxxxxx> wrote in message
> news:OkqFrs1OIHA.5360@xxxxxx
>
Quote:

>> Yeah give it another go. Post back if you can't get it resolved.
>> There are many helpful people in this group, who I'm sure will be
>> able to get it running smoothly, if not.
>>
>> -- Jon
>>
>> "Peter Sun" <koarla@xxxxxx> wrote in message
>> news:OOSFPi1OIHA.4688@xxxxxx
>>
Quote:

>>> Thank you fro you reply, Jon,
>>>
>>> I looked back to the code a again, what I found the value is in the
>>> $tempString,
>>> but what refer to the $sqlString, then I found
>>> $sqlString="select id from urlScreenLog where screennedURL=''".
>>>
>>> I already put the function in front making call.
>>>
>>> let me do more test and try different way.
>>>
>>> Peter
>>>
>>> "Jon" <Email_Address@xxxxxx> wrote in message
>>> news:e64eiS1OIHA.5980@xxxxxx
>>>
>>>> Looking at it again, I think it's more of an order issue....
>>>>
>>>> Define your function before you call it - that's one of the
>>>> idiosyncracies of PowerShell
>>>>
>>>> ie
>>>>
>>>> Function QueryScreenLog([string]$queyString)
>>>> {
>>>> $mycommand.CommandText = $queyString
>>>> $myreader = $mycommand.ExecuteReader()
>>>> }
>>>> $sqlString="select id from urlScreenLog where
>>>> screennedURL='$tempString'"
>>>> $ScreenlogID = QueryScreenLog $sqlString
>>>> -- Jon
>>>>
>>>> "Jon" <Email_Address@xxxxxx> wrote in message
>>>> news:e$Hc$K1OIHA.5264@xxxxxx
>>>>
>>>>> Try an 'escape character' (small tick below the top left 'esc'
>>>>> key on the keyboard) before the single quotes eg
>>>>>
>>>>> $sqlString = "select id from urlScreenLog where
>>>>> screennedURL=`'$tempString`'"
>>>>>
>>>>> -- Jon
>>>>>
>>>>> "Peter Sun" <koarla@xxxxxx> wrote in message
>>>>> news:%23tf9aE1OIHA.4440@xxxxxx
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> Here I have a code that do not pass the value to the function,
>>>>>> which is below
>>>>>>
>>>>>> $tempString='http://xxx.com'
>>>>>>
>>>>>> $sqlString="select id from urlScreenLog where
>>>>>> screennedURL='$tempString'"
>>>>>> $ScreenlogID = QueryScreenLog $sqlString
>>>>>> Function QueryScreenLog([string]$queyString)
>>>>>> {
>>>>>> $mycommand.CommandText = $queyString
>>>>>> $myreader = $mycommand.ExecuteReader()
>>>>>> }
>>>>>> in the function, $queyString is always "select id from
>>>>>> urlScreenLog where screennedURL=''", not like what I want
>>>>>>
>>>>>> "select id from urlScreenLog where screennedURL='http://xxx.com'"
>>>>>>
>>>>>> Any help? I appreciated it!
>>>>>>
>>>>>> Peter
>>>>>>

My System SpecsSystem Spec
Old 12-10-2007   #9 (permalink)
Jon


 
 

Re: Why the Value not able to Pass to a Function



--
Jon


"Peter Sun" <koarla@xxxxxx> wrote in message
news:%23OOy602OIHA.3556@xxxxxx
Quote:

>I should use
> $ScreenlogID = QueryScreenLog $a $sqlString $b
> No Comma
>
>
> "Peter Sun" <koarla@xxxxxx> wrote in message
> news:O1c%23qp2OIHA.5524@xxxxxx
Quote:

>> Hi, Jon,
>>
>> Thank you so much, and I know here always have a lot of kinds of people
>> and helpful.
>>
>> I figured the problem out, it come from the statement of calling
>> function, I was using
>>
>> $ScreenlogID = QueryScreenLog $a,$sqlString, $b
>>
>> So, powershell just pass the first one varible $a.
>>
>> Thanks again.
>>
>> Peter
>>
>>
>>
>>
>> "Jon" <Email_Address@xxxxxx> wrote in message
>> news:OkqFrs1OIHA.5360@xxxxxx
Quote:

>>> Yeah give it another go. Post back if you can't get it resolved. There
>>> are many helpful people in this group, who I'm sure will be able to get
>>> it running smoothly, if not.
>>>
>>> --
>>> Jon
>>>
>>>
>>> "Peter Sun" <koarla@xxxxxx> wrote in message
>>> news:OOSFPi1OIHA.4688@xxxxxx
>>>> Thank you fro you reply, Jon,
>>>>
>>>> I looked back to the code a again, what I found the value is in the
>>>> $tempString,
>>>> but what refer to the $sqlString, then I found
>>>>
>>>> $sqlString="select id from urlScreenLog where screennedURL=''".
>>>>
>>>> I already put the function in front making call.
>>>>
>>>> let me do more test and try different way.
>>>>
>>>>
>>>> Peter
>>>>
>>>>
>>>> "Jon" <Email_Address@xxxxxx> wrote in message
>>>> news:e64eiS1OIHA.5980@xxxxxx
>>>>> Looking at it again, I think it's more of an order issue....
>>>>>
>>>>> Define your function before you call it - that's one of the
>>>>> idiosyncracies of PowerShell
>>>>>
>>>>> ie
>>>>>
>>>>>
>>>>> Function QueryScreenLog([string]$queyString)
>>>>> {
>>>>> $mycommand.CommandText = $queyString
>>>>> $myreader = $mycommand.ExecuteReader()
>>>>> }
>>>>>
>>>>> $sqlString="select id from urlScreenLog where
>>>>> screennedURL='$tempString'"
>>>>> $ScreenlogID = QueryScreenLog $sqlString
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Jon
>>>>>
>>>>>
>>>>> "Jon" <Email_Address@xxxxxx> wrote in message
>>>>> news:e$Hc$K1OIHA.5264@xxxxxx
>>>>>> Try an 'escape character' (small tick below the top left 'esc' key
>>>>>> on the keyboard) before the single quotes eg
>>>>>>
>>>>>> $sqlString = "select id from urlScreenLog where
>>>>>> screennedURL=`'$tempString`'"
>>>>>>
>>>>>> --
>>>>>> Jon
>>>>>>
>>>>>>
>>>>>> "Peter Sun" <koarla@xxxxxx> wrote in message
>>>>>> news:%23tf9aE1OIHA.4440@xxxxxx
>>>>>>> Hi,
>>>>>>>
>>>>>>> Here I have a code that do not pass the value to the function, which
>>>>>>> is below
>>>>>>>
>>>>>>> $tempString='http://xxx.com'
>>>>>>>
>>>>>>> $sqlString="select id from urlScreenLog where
>>>>>>> screennedURL='$tempString'"
>>>>>>> $ScreenlogID = QueryScreenLog $sqlString
>>>>>>>
>>>>>>> Function QueryScreenLog([string]$queyString)
>>>>>>> {
>>>>>>> $mycommand.CommandText = $queyString
>>>>>>> $myreader = $mycommand.ExecuteReader()
>>>>>>> }
>>>>>>>
>>>>>>> in the function, $queyString is always "select id from urlScreenLog
>>>>>>> where screennedURL=''", not like what I want
>>>>>>>
>>>>>>> "select id from urlScreenLog where screennedURL='http://xxx.com'"
>>>>>>>
>>>>>>>
>>>>>>> Any help? I appreciated it!
>>>>>>>
>>>>>>> Peter
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>
>>
>>
>
>
My System SpecsSystem Spec
Old 12-10-2007   #10 (permalink)
Jon


 
 

Re: Why the Value not able to Pass to a Function

Sorry pressed the wrong button there.


Yes, that's correct separate them by spaces, or use the naming technique, as
Shay mentions below eg


#------------------------------------
function WhatisA {

param([string]$a)


"A is $a"

}

WhatisA -a "apple"

#------------------------------------

--
Jon

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Get variable data from function to pass back to main for use. VB Script
Set a variable in a function then pass it off? PowerShell
Re: Is anything major missing from this first-pass freeware filing system by FUNCTION (not by brand)? Vista installation & setup
how to pass *properties* to a function PowerShell
Howto: pass all args to a sub function? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46