WIN32OLE inputbox with carriage-returns in the message

I have a problem using the Windows “Inputbox” function.
I’m trying to do what I sometimes do in VBScript to create a
multiple-choice scenario within a windowless application. Via the
various built-in messagebox / inputbox functions of Windows. The way to
do this is to pass newlines into the inputbox message, allowing for
multiple lines, each with a numbered option.

I have attached the module I wrote (mostly plagiarised) to facilitate
this in Ruby.

This works fine in VBScript:

inputbox “1 - Test” & Chr(13) & “2 - Testy” & vbCrLf & “3 - Testa”

However, this fails in Ruby:

irb(main):001:0> load ‘WinBoxes.rb’
=> true
irb(main):002:0> include WinBoxes
=> Object
irb(main):003:0> inputbox “1 - Test\n2 - Testy\n3 - Testa”
WIN32OLERuntimeError: (in OLE method eval': ) OLE error code:800A0409 in Microsoft VBScript compilation error Unterminated string constant HRESULT error code:0x80020009 Exception occurred. from C:/Users/Joel/Desktop/Files/Projects/bin/WinBoxes.rb:29:inmethod_missing’
from C:/Users/Joel/Desktop/Files/Projects/bin/WinBoxes.rb:29:in
inputbox' from (irb):3 from C:/Ruby200/bin/irb:12:in

I’ve tried this with “\r”, “\r\n”, 10.chr, and 13.chr as well. I’m at a
loss as to how to get around this without having to package a full GUI
into my program, something I’m reluctant to do because of the size

D’oh, just after asking this I realised something. VBScript is
interpreting the carriage-returns as a part of the script rather than
part of the message, I need to escape them first:

Doing this inside the inputbox method has fixed the problem.
message = message.gsub( /\n/, ‘" & vbCrLf & "’ )

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs