Control the Location of an Input Box

LibreOffice 7.3.7.2 in Ubuntu 22.04.1

I am new to LibreOffice. Andrew Pitonyak’s guide suggests a method to control the location of an InputBox.

Listing 190. Demonstrate InputBox.

Sub ExampleInputBox
  Dim sReturn As String     'Return value
  Dim sMsg As String        'Holds the prompt
  Dim sTitle As String      'Window title
  Dim sDefault As String    'Default value
  Dim nXPos As Integer      'Twips from left edge
  Dim nYPos As Integer      'Twips from top edge
  nXPos = 1440 * 2          'Two inches from left edge of the window
  nYPos = 1440 * 4          'Four inches from top of the window
  sMsg  = "Please enter some meaningful text"
  sTitle = "Meaningful Title"
  sDefault = "Hello"
  sReturn = InputBox(sMsg, sTitle, sDefault, nXPos, nYPos)
  If sReturn <> "" Then
    REM Print the entered string surrounded by double quotes
    Print "You entered """;sReturn;""""
  Else
    Print "You either entered an empty string or chose Cancel"
  End If
End Sub

The code runs as expected, but changing the nXPos and nYPOs factors of the InputBox has no effect on its location,

Am I mis-understanding the code?

Stephen

The code works for me (after changing the " signs of your original post) in my LO 6.4.7, LO 7.4.5, and LO 7.5.1 versions on Win10 - when I change the position in the code, next run of the macro works with the new values.

Sub ExampleInputBox

 Dim sReturn As String 'Return value
 Dim sMsg As String 'Holds the prompt
 Dim sTitle As String 'Window title
 Dim sDefault As String 'Default value
 Dim nXPos As Integer 'Twips from left edge
 Dim nYPos As Integer 'Twips from top edge

	nXPos = 1440 * 2 'Two inches from left edge of the window
	nYPos = 1440 * 2 'Four inches from top of the window
	sMsg = "Please enter some meaningful text"
	sTitle = "Meaningful Title"
	sDefault = "Hello"
	sReturn = InputBox(sMsg, sTitle, sDefault, nXPos, nYPos)
	If sReturn <> "" Then
		REM Print the entered string surrounded by double quotes
		Print "You entered: " & sReturn
	Else
		Print "You either entered an empty string or chose Cancel"
	End If
End Sub

Thank you for your reply.

I wonder if the difference is in the underlying platforms (in your case Windows 10 and in my case Ubuntu 22.04).

No. Just ran on Ubuntu 22.04 with:

Version: 7.5.0.3 (X86_64) / LibreOffice Community
Build ID: c21113d003cd3efa8c53188764377a8272d9d6de
CPU threads: 8; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: threaded

.
No issues.

Thank you for testing it.

I wonder if there is a problem with my build/environment.

Here are the details. Any advice would be welcome.

Version: 7.3.7.2 / LibreOffice Community
Build ID: 30(Build:2)
CPU threads: 8; OS: Linux 5.19; UI render: default; VCL: gtk3
Locale: en-GB (en_GB.UTF-8); UI: en-GB
Ubuntu package version: 1:7.3.7-0ubuntu0.22.04.1
Calc: threaded

@swaatacba
Instead of grasping, how about posting a sample of what you have that is not working.

I attach a screen shot of the InputBox. Notice that the box is located dead centre of the screen. However the input box position should be -

  nXPos = 1440 * 1
  nYPos = 1440 * 1

I have amended the values to make it clear whether location of the InputBox has been moved. This has not been implemented.

@swaatacba
Screenshot is typically of little help and none here. Attach a sample please.

The screen shot derives from the Andrew Pitonyak’s original code (see my first post) with the “top” and “left” coordinate values changed to make them even further off-centre. You will see from my image that the input box is (more or less) dead centre after running the code.

Curiously, I also retain an earlier version of LibreOffice (4.2.8.2). When I process the same code through that environment, the InputBox presents off-centre as expected. On the other hand processing equivalent code through Excel in Windows 7 and Windows 10 produces a variety of positional results which are difficult to explain.

I suspect that there is no definitive solution for my query.

Tested for the same version:

Version: 7.3.7.2 / LibreOffice Community
Build ID: 30(Build:2)
CPU threads: 4; OS: Linux 5.19; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Ubuntu package version: 1:7.3.7-0ubuntu0.22.04.1
Calc: threaded

No issues.