Author Topic: Input dialog with multi-line prompt  (Read 686 times)

PeteEA

  • EA Novice
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Input dialog with multi-line prompt
« on: May 21, 2020, 10:24:53 pm »
I'd like to create an input dialog with the prompt on multiple lines. I'm using DLGInputBox from EAScriptLib.JScript-Dialog.
I've tried including \n or String.fromCharCode(10) within the prompt parameter. Both cause the same error "Unterminated string constant" on the vbe.eval line.

As far as I can tell from VBScript info, including either CR or LF within the prompt should give a multi-line prompt

Just to be sure, I created the code manually without using the library code, with no change:
      var vbe = new ActiveXObject("ScriptControl");
      vbe.Language = "VBScript";
      DLGInputBox('A'+String.fromCharCode(10)+'B',"Title","Def");

Is there a way to get a multi-line dialog to work? I'm not restricted to this VB dialog if there is an alternative that will work (I have tried Session.Input and that silently ignores the newline.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 11201
  • Karma: +412/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Input dialog with multi-line prompt
« Reply #1 on: May 21, 2020, 10:55:34 pm »
That makes sense.

If you look at the DLGInputBox method you see the following:

Code: [Select]
return vbe.eval( "InputBox(\"" + promptText + "\",\"" + title + "\",\"" + defaultText + "\")");
So what happens is that your input is used to create a bit of VBScirpt code, that is then executed.

So If i where to type it manually the input for vbe.eval would be

Code: [Select]
InputBox("A
B","Title","Def")

This code, when executed would indeed throw a syntax error. This is because your string that is used as promptText is not closed properly (the string doesn't continue on the next line)

If I wanted to do something like that in VBScript I would write:

Code: [Select]
InputBox("A" & vbNewLine & "B", "Title","Def")
Now I'm not familiar with JScript, but I'm guessing something like this should work:

Code: [Select]
DLGInputBox("A\" & vbNewLine & \"B","Title","Def");
Geert

PeteEA

  • EA Novice
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile
Re: Input dialog with multi-line prompt
« Reply #2 on: May 22, 2020, 12:51:06 am »
That suggestion works perfectly. I used to know a bit of VB, but it's long escaped my memory!