This should be the method:
Public Function
CheckEnvironmentVariableExist(strEnvironmentKeyName,bolIsObject)
On Error Resume Next
Err.Clear()
Dim tempVariable
If bolIsObject Then
Set tempVariable = Environment(strEnvironmentKeyName)
Else
tempVariable = Environment(strEnvironmentKeyName)
End If
If Err.Number <> 0 Then
CheckEnvironmentVariableExist = False
Else
CheckEnvironmentVariableExist = True
End If
On Error GoTo 0
End Function
On Wed, Jan 9, 2013 at 8:13 PM, Manoj Gupta <[email protected]> wrote:
> On Error Resume Next
>
> Err.Clear()
>
> username = environment.Value("uname") password = environment.Value("pwd")
>
> If Err.Number <> 0 Then
> Msgbox "something wrong with env"
> Else
> Msgbox username
> Msgbox password
> End If
> On Error GoTo 0
>
> Better is to put similar code in a method. This method would return true
> or false on the basis of err.number value.
>
> Cheers,
> Manoj
> On Jan 9, 2013 4:59 PM, "vamsi reddy" <[email protected]> wrote:
>
>>
>> Hi All,
>>
>> I Faced a question in an interview
>> "How can I check if a environment variable exist or not"
>>
>> I created Environment variables in File--Settings--Environment--User
>> defined(Or through .ENV File)
>> And Iam accessing in QTP through below statements
>>
>> username = environment.Value("uname")
>> password = environment.Value("pwd")
>>
>> Msgbox username
>> Msgbox password
>>
>>
>> But How can I check whether the Env exist or not?
>>
>>
>>
>>
>> --
>> Vamsi Reddy
>> *
>> *
>>
>> * *
>>
>>
>> --
>> You received this message because you are subscribed to the Google
>> "QTP - HP Quick Test Professional - Automated Software Testing"
>> group.
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/MercuryQTP?hl=en
>>
>
--
You received this message because you are subscribed to the Google
"QTP - HP Quick Test Professional - Automated Software Testing"
group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/MercuryQTP?hl=en