Forum Discussion

joffre's avatar
joffre
Regular Contributor
12 years ago

Assign user's typed value to a variable

Is it possible to show dialog boxes where user can input values ​​for certain attributes?


In programming - java basic -, would be something like:

JOptionPane.showInputDialog (null, "Enter the database name to be used.");


Then the TestComplete takes the value typed by the user and assigns to a variable previously created by me.

10 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Joffre,



    You can use BuiltIn.InputBox(), but note that the test will hang if executed unattended (as there will be no user to enter data and close the dialog).
  • joffre's avatar
    joffre
    Regular Contributor
    Hi Alex. Thanks for your fast answer.



    That is exactly my idea. When I run the script, some windows will be shown so the user can type some informations that will change for each execution.

    I was browsing the Online User Guide and I didn't find results about BuiltIn.InputText.



    Could you please be more specific?



    PS.: I'm using TestComplete 7.52
  • joffre's avatar
    joffre
    Regular Contributor
    Because of that too. Thanks.

    And I was looking for on the wrong place (Here instead of here).



    One more thing.

    I want the user to type the values and I need this values to be used any placa on the script. Not just on the script that will call the BuiltIn.InputBox.



    Is it possible to do that?



    Thank you once again.
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Joffre,



    Create a global or Project (or ProjectSuite) variable and assign a value to it. Even more: if you create persistent Project or ProjectSuite variable, then it will be possible to preserve the value between different test runs.
  • joffre's avatar
    joffre
    Regular Contributor
    Like this?



      ProjectSuite.Variables.ServerName = BuiltIn.InputBox("Input Data", "Type the server name:", "")

      Log.Message(ServerName)
  • Hi,



    I'd rewrite it like below, but you've got the idea:

    ProjectSuite.Variables.ServerName = BuiltIn.InputBox("Input Data", "Type the server name:", "");

    if(ProjectSuite.Variables.ServerName != "")

    Log.Message(ProjectSuite.Variables.ServerName);

    else

    Log.Warning("Nothing entered");





    This is because you probably want to know whether a user pressed OK or Cancel in the dialog. Also, you can set a meaningful default value which you can use as a default server name if the user didn't enter anything.
  • joffre's avatar
    joffre
    Regular Contributor
    By doing that I'll be able to call the 'ServerName' variable from wherever I want inside my project? On any script file?



    Thank you so much for the assistance!
  • Hi,



    You'll be able to access 'ServerName' anywhere within your entire project suite since it is a project suite variable.