SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 8 of 8
  1. #1
    Junior Member
    Join Date
    Oct 2006
    Posts
    2
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    ReadOnly variables

    Does QTP support ReadOnly variables?

    I tried declaring ReadOnly variables as followed:
    ReadOnly roVariable As Integer = 3

    But i only get a syntax error.

    I can't use Const variables, since they only accept literals.

    Are there any other options? or am i declaring ReadOnly variables incorrectly?
    Thanks for any help.

  2. #2
    Member
    Join Date
    Sep 2002
    Location
    Bradenton, FL
    Posts
    71
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: ReadOnly variables

    What are you trying to accomplish?

    One thing to remember with QTP is that QTP is based on VBScript. If you can do it in VBScript, then you can probably do it in QTP.

    In VBScript, you don't have to declare your variables. Plus, every variable is technically of a type "Variant"
    If you type in the code:

    Dim someVar as Integer

    you will get an error because VBScript does not let you assign a type to a variable.

    Mike

  3. #3
    Moderator
    Join Date
    Jul 2005
    Location
    Delhi
    Posts
    15,575
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    7 Thread(s)
    Total Downloaded
    0

    Re: ReadOnly variables

    You can use Const

    Const roVariable=2

  4. #4
    Junior Member
    Join Date
    Oct 2006
    Posts
    2
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: ReadOnly variables

    Sorry, I guess i was little vague on my problem.
    This is a simple example of something i wish to accomplish

    anumber = 4
    asecondnumber = 6
    answer = anumber + asecondnumber
    ReadOnly roVariable = answer

    roVariable is now = 10 and cannot be changed.

    Using 'Const' doesn't work, since Const can only be initialized with literals (integers, strings,..) not other variables.
    Doing something like the following isn't even allow
    Const num1 = 1
    Const num2 = num1 <- Error.

    Hope this clears up the question a bit.

  5. #5
    Moderator
    Join Date
    Sep 2001
    Location
    Doncaster, UK
    Posts
    5,788
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: ReadOnly variables

    [ QUOTE ]
    ReadOnly variables

    [/ QUOTE ]

    Thats illogical and almost an oxymoron.

    You want to write to a readonly field, why would you want to do that, perhaps there is another way to achieve your goal.

    Let us know why you need to do that.

    Mark Smith.

  6. #6
    Moderator
    Join Date
    Sep 2001
    Location
    Doncaster, UK
    Posts
    5,788
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: ReadOnly variables

    If your numbers are a small finite range you could do something crude like this but for all intents and purposes it's not efficient enough for more than 20 numbers:

    '=================================================
    a=4
    b=6
    c=a+b
    Select Case c
    Case 1
    Const myConst = 1
    Case 2
    Const myConst = 2
    '
    ' etc
    ' etc
    '
    Case 10
    Const myConst = 10
    End Select
    MsgBox myConst
    '=================================================

    And if anyone suggests this is the kind of code I always write I shall not be held responsible for the punch on the nose they receive [img]/images/graemlins/wink.gif[/img]

    Mark Smith.

  7. #7
    Senior Member
    Join Date
    Feb 2003
    Location
    FL, USA
    Posts
    3,646
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Total Downloaded
    0

    Re: ReadOnly variables

    I am not a QTP person but I wondered if you want variables who contents will never change/be updated why don't you just program so that they are not changed?

    A variable by its name is something that can change same as a content is something that doesn't change. If other restrictions require you to use a variable as a constant just program not to change the variable data.
    Lynne

    I have not failed. I've just found 10,000 ways that won't work" --Thomas Edison

  8. #8
    Moderator
    Join Date
    Jul 2005
    Location
    Delhi
    Posts
    15,575
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    7 Thread(s)
    Total Downloaded
    0

    Re: ReadOnly variables

    well i think the solution should strike

    Dim x
    x=3
    Execute "Const readOnlyVar=" & x

    msgbox readOnlyVar
    readOnlyVar=4

    the last assignment will give you an error

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 7.14%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 10:04 PM.

Copyright BetaSoft Inc.