InputBox digit grouping

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
akrogun
Posts: 11
Joined: Sat Jun 03, 2017 12:38 pm

InputBox digit grouping

Post by akrogun »

Hi...
I have a InputBox that input a numeric like here:

Code: Select all

InputVal = InputBox("Please enter value:", "Input Value")
My question:
1. How to restrict only number that can input in the field?
2. Is it possible to make auto digit grouping whatever I enter in the field? If possible, how to do it?

Thanks in advance
Last edited by MrProgrammer on Tue Jan 11, 2022 9:45 pm, edited 1 time in total.
Reason: Removed confusing [WTA] from subject, since akrogun has declined to say what it means
Windows 7 64Bit
LibreOffice 5.1.42 (x64)
User avatar
robleyd
Moderator
Posts: 5079
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: [WTA] InputBox digit grouping

Post by robleyd »

What is "[WTA]" in relation to your question?
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
akrogun
Posts: 11
Joined: Sat Jun 03, 2017 12:38 pm

Re: [WTA] InputBox digit grouping

Post by akrogun »

robleyd wrote:What is "[WTA]" in relation to your question?
Sorry, 2 questions in my post
Windows 7 64Bit
LibreOffice 5.1.42 (x64)
User avatar
robleyd
Moderator
Posts: 5079
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: [WTA] InputBox digit grouping

Post by robleyd »

All an Input Box can do is return the string entered; you'll need to post-process the string and manipulate it as necessary.
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
akrogun
Posts: 11
Joined: Sat Jun 03, 2017 12:38 pm

Re: [WTA] InputBox digit grouping

Post by akrogun »

Perhaps with another method rather than using InputBox. Just like we using desk calculator, a normal calculator. You know, if we hit 4 digit then the display showing us 3,675 for an example. How to do it?
Windows 7 64Bit
LibreOffice 5.1.42 (x64)
User avatar
Zizi64
Volunteer
Posts: 11358
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: [WTA] InputBox digit grouping

Post by Zizi64 »

You can create your own InputBox by usage the form control element named Text Box on a Form, and its Event "Canged" or "Text modified" in a macro code. Then you will examine all of typed character, you will able to add thousand separator after typing every three caracters, you can delete the non-numeric characters, ... etc.
Finally you can manage the typed characters on the event "When losing focus" or "Key pressed' (if it was the 'Enter'). (Or you can use a dedicated Button located on your Form for the manager routine.)
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
akrogun
Posts: 11
Joined: Sat Jun 03, 2017 12:38 pm

Re: [WTA] InputBox digit grouping

Post by akrogun »

Zizi64 wrote:You can create your own InputBox by usage the form control element named Text Box on a Form, and its Event "Canged" or "Text modified" in a macro code. Then you will examine all of typed character, you will able to add thousand separator after typing every three caracters, you can delete the non-numeric characters, ... etc.
Finally you can manage the typed characters on the event "When losing focus" or "Key pressed' (if it was the 'Enter'). (Or you can use a dedicated Button located on your Form for the manager routine.)
Thanks, Zizi, I will try it
Windows 7 64Bit
LibreOffice 5.1.42 (x64)
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: [WTA] InputBox digit grouping

Post by JeJe »

An input box is just a modal dialog - you can create your own dialog and put a text box or other dialog control on it and restrict the input.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [WTA] InputBox digit grouping

Post by Villeroy »

Yesterday's pattern field example: https://ask.libreoffice.org/uploads/sho ... BLAZGB.odb (open the embedded input form).
Pattern fields can be attached to dialogs and spreadsheets as well. [Calc, Basic] Formatted form controls to sheet cells.
Pattern field for phone numbers: download/file.php?id=19462
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: [WTA] InputBox digit grouping

Post by JeJe »

Pressing the button in the attached document shows a modal dialog with a textbox which will remove any typed input which isn't a number. Code:

Code: Select all

Sub ModalDialog
dlg = loaddialog("Standard","Dialog1")
dlg.execute
msgbox dlg.getcontrol("TextField1").model.text
End Sub

sub Textboxkeypress(ev)
dim st,sel,a

select case ev.keychar
case "0","1","2","3","4","5","6","7","8","9"
case else
st = ev.source.model.text
sel = ev.source.selection
a = instr( st,chr(ev.keychar)
if a  then mid(st,a,1)= ""
ev.source.model.text=st
ev.source.selection=sel
end select
end sub


Function LoadDialog(oLibraryName as String, oDialogName as String)
	Dim oLib as Object
	DialogLibraries.LoadLibrary(oLibraryName)
	oLib = DialogLibraries.GetByName(oLibraryname)
	LoadDialog() =  CreateUnoDialog(oLib.GetByName(oDialogName))
End Function



Edit: changed code to catch some missed input
Attachments
modal dialog with numbers only textbox.odt
(12.56 KiB) Downloaded 142 times
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
akrogun
Posts: 11
Joined: Sat Jun 03, 2017 12:38 pm

Re: [WTA] InputBox digit grouping

Post by akrogun »

JeJe wrote:Pressing the button in the attached document shows a modal dialog with a textbox which will remove any typed input which isn't a number. Code:
Thanks for the code example
Windows 7 64Bit
LibreOffice 5.1.42 (x64)
akrogun
Posts: 11
Joined: Sat Jun 03, 2017 12:38 pm

Re: [WTA] InputBox digit grouping

Post by akrogun »

Villeroy wrote:Yesterday's pattern field example: https://ask.libreoffice.org/uploads/sho ... BLAZGB.odb (open the embedded input form).
Pattern fields can be attached to dialogs and spreadsheets as well. [Calc, Basic] Formatted form controls to sheet cells.
Pattern field for phone numbers: download/file.php?id=19462
Sorry, I can't understand what you're saying because my limited programming. Why I can't open odb files? And what did you mean with pattern field can be attached to dialogs and spreadsheet?
Windows 7 64Bit
LibreOffice 5.1.42 (x64)
Post Reply