SPONSORS:






User Tag List

Results 1 to 9 of 9
  1. #1
    Junior Member
    Join Date
    Mar 2002
    Location
    Campbell, CA, USA
    Posts
    9
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Type casting a string to a window

    Does anybody know if there is a good way to type cast a string to a window?

    Here is what I would like to do:

    VOID fClickCycle (STRING sLink)
    sLink.Click ()
    Browser.Back.Click ()

    testcase blah ()
    fClickCycle (MyApp.Link1)
    fClickCycle (MyApp.Link2)
    fClickCycle (MyApp.Link3)
    ...etc

    Is there a good way to do this and similar things? I want to save lines of code by passing the link to a function. The problem with this is that I get the compiler error:
    Type mismatch -- Expecting a window.

    So should I typecast? Or is there a better way to do this.

    Thanks a lot,

    -Marc

    ------------------

  2. #2
    Senior Member
    Join Date
    Mar 2000
    Location
    pisctaway, NJ USA
    Posts
    188
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Type casting a string to a window

    Just define your input paramter to be of type WINDOW (or 'anytype'). Otherwise, you must use the reference operator to reference a window.

    Anthony

    ------------------

  3. #3
    Member
    Join Date
    May 2001
    Location
    Rochester, NY, USA
    Posts
    61
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Type casting a string to a window

    Marc,
    The easiest way is to use the reference operator "@".

    From the SilkTest help files:
    "The reference operator (@expression) lets you refer to functions and variables indirectly, by name. It uses the value of its operand to refer to variable, the fields in a record, function, method, property or child window."

    Here is an example:
    [ ] STRING sWindow = "ApplicationWindow"
    [ ] @sWindow.SetActive()

    Hope this helps,
    Steve


    ------------------
    Steven P. Blunt
    Software Automation Technical Lead
    NASG Sales Force Productivity
    Steven P. Blunt
    Software Automation Technical Lead
    NASG Sales Force Productivity

  4. #4
    Junior Member
    Join Date
    Mar 2002
    Location
    Campbell, CA, USA
    Posts
    9
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Type casting a string to a window

    Thanks. That helped a lot!

    ------------------

  5. #5
    Member
    Join Date
    Jun 2002
    Location
    california
    Posts
    60
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Type casting a string to a window

    i have a question why is it when i use the reference operation, it fails and i get an error that the variable Dialog1.Text1 is not defined. I actually did a windows declaration.

  6. #6
    Senior Member
    Join Date
    Feb 2000
    Posts
    1,497
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Type casting a string to a window

    Like this?

    </font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">main()
    {
    Print(w.sVar) ;
    Print(w.@(w.sVar)) ; // note syntax
    }

    window MainWin w // dummy window
    {
    tag &quot;#1&quot; ;
    string sVar = &quot;stuff&quot; ; // reference to a variable named 'stuff'
    string stuff = &quot;abc&quot; ;
    }</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">John

  7. #7
    Member
    Join Date
    Jun 2002
    Location
    california
    Posts
    60
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Type casting a string to a window

    yes. the thing is in my code it fails when it executes the line with the @reference...

    The way I have is this way....
    </font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">string sWindow = &quot;Dialog1.Text1&quot; //&lt;--- I am reading off this info from a text file.

    @(sWindow).SetFocus() //&lt;-- this line fails to execute </pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">

  8. #8
    Member
    Join Date
    Apr 2003
    Location
    Fremont, CA, USA
    Posts
    61
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Type casting a string to a window

    try this ....
    STRING sDialog = "Dialog1"
    STRING sWindow = "Text1"
    @(sDialog).@(sWindow).SetFocus()

  9. #9
    Member
    Join Date
    Jun 2002
    Location
    california
    Posts
    60
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Type casting a string to a window

    Thanks, Rajesh. That worked but I run into another problem. Please see my post on "@ as string."

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin 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 12:50 PM.

Copyright BetaSoft Inc.