Virtual Numpad

Creating a macro - Writing a Script - Using the API

Virtual Numpad

Postby soomeesaan » Wed Jul 31, 2019 9:11 pm

Hi guys,

I would like a virtual numpad in my calc file that I can use on a device without physical keyboard.

I have a POS with touchscreen and I don't want to use the on screen keyboard Windows provides.

I tried to do buttons that insert numbers and dot, a button that clears a cell, and an OK buttons that acts like the Enter button but it didn't work properly.

Thanks!
Attachments
prtscr.png
OpenOffice 4.1.6
Windows 10
soomeesaan
 
Posts: 6
Joined: Wed Jul 31, 2019 8:52 pm

Re: Virtual Numpad

Postby Zizi64 » Wed Jul 31, 2019 10:44 pm

Please upload your macros and the .ods sample file here.
Tibor Kovacs, Hungary; LO6.1.6 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.5; AOO4.1.6
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.
User avatar
Zizi64
Volunteer
 
Posts: 8353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Virtual Numpad

Postby Villeroy » Wed Jul 31, 2019 11:32 pm

Code: Select all   Expand viewCollapse view
Sub appendChar(e)
   s = e.Source.Model.Tag
   view = ThisComponent.getCurrentController()
   cell = view.getSelection()
   c = cell.getString()
   cell.setFormula(c & s)
End Sub

Button properties:
Repeat = Yes
Take focus = No
Additional info = the character to be appended
Execute Action Event = the above macro

The spreadsheet selection needs to be a single cell.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27219
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Virtual Numpad

Postby soomeesaan » Fri Aug 02, 2019 12:46 pm

Hi,

Right now the dot isn't working. I can "type" in a cell .2, but it doesn't work for 1.2 or 0.2.

Code: Select all   Expand viewCollapse view
Rem Attribute VBA_ModuleType=VBAModule
Option VBASupport 1
Sub RoundedRectangle1_Click()
ActiveCell.Value = ActiveCell.Value & "1"

End Sub
Sub RoundedRectangle2_Click()
ActiveCell.Value = ActiveCell.Value & "2"
End Sub
Sub RoundedRectangle3_Click()
ActiveCell.Value = ActiveCell.Value & "3"
End Sub
Sub RoundedRectangle5_Click()
ActiveCell.Value = ActiveCell.Value & "5"
End Sub
Sub RoundedRectangle4_Click()
ActiveCell.Value = ActiveCell.Value & "4"
End Sub
Sub RoundedRectangle6_Click()
ActiveCell.Value = ActiveCell.Value & "6"
End Sub
Sub RoundedRectangle7_Click()
ActiveCell.Value = ActiveCell.Value & "7"
End Sub
Sub RoundedRectangle8_Click()
ActiveCell.Value = ActiveCell.Value & "8"
End Sub
Sub RoundedRectangle9_Click()
ActiveCell.Value = ActiveCell.Value & "9"
End Sub
Sub RoundedRectangle0_Click()
ActiveCell.Value = ActiveCell.Value & "0"
End Sub
Sub RoundedRectangle11_Click()

ActiveCell.Value = ActiveCell.Value & "."



End Sub
Sub RoundedRectangle12_Click()
ActiveCell.Value = ""
End Sub
Sub RoundedRectangle13_Click()

Activecell.value=CDbl(Activecell.value)


If activeCell.Value = "" then
   activeCell.value = ""
end if

If ActiveCell.Column = 1 Then
    ActiveCell.Offset(1, 0).Select
   
End If

End Sub
Attachments
Cash reconciliation.ods
(19.46 KiB) Downloaded 18 times
Last edited by robleyd on Fri Aug 02, 2019 1:31 pm, edited 1 time in total.
Reason: Add code tags
OpenOffice 4.1.6
Windows 10
soomeesaan
 
Posts: 6
Joined: Wed Jul 31, 2019 8:52 pm

Re: Virtual Numpad

Postby JeJe » Fri Aug 02, 2019 1:18 pm

You could use a publicly declared variable and clear it back to 0 on OK

Code: Select all   Expand viewCollapse view
dim v
Option VBASupport 1
Sub RoundedRectangle1_Click()
v = v & "1"
ActiveCell.Value =v
End Sub

'etc etc
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 584
Joined: Wed Mar 09, 2016 2:40 pm

Re: Virtual Numpad

Postby soomeesaan » Fri Aug 02, 2019 2:02 pm

JeJe wrote:You could use a publicly declared variable and clear it back to 0 on OK

Code: Select all   Expand viewCollapse view
dim v
Option VBASupport 1
Sub RoundedRectangle1_Click()
v = v & "1"
ActiveCell.Value =v
End Sub

'etc etc

The variable should clear back to 0 on OK or if I select another cell. How do you do that?
OpenOffice 4.1.6
Windows 10
soomeesaan
 
Posts: 6
Joined: Wed Jul 31, 2019 8:52 pm

Re: Virtual Numpad

Postby JeJe » Fri Aug 02, 2019 4:08 pm

Right click on the tab for the sheet... pick "Sheet Events"... try setting back to 0 on selection changed event...
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 584
Joined: Wed Mar 09, 2016 2:40 pm

Re: Virtual Numpad

Postby soomeesaan » Tue Aug 06, 2019 12:32 pm

Everything works fine so far, thank you all for your help.

I have one more question. I want the C button to clear two or more selected cells.
OpenOffice 4.1.6
Windows 10
soomeesaan
 
Posts: 6
Joined: Wed Jul 31, 2019 8:52 pm

Re: Virtual Numpad

Postby JeJe » Tue Aug 06, 2019 1:03 pm

You can use the macro recorder to find solutions like this...

Code: Select all   Expand viewCollapse view
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Flags"
args2(0).Value = "A"

dispatcher.executeDispatch(document, ".uno:Delete", "", 0, args2())


Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 584
Joined: Wed Mar 09, 2016 2:40 pm

Re: Virtual Numpad

Postby soomeesaan » Tue Aug 06, 2019 2:28 pm

JeJe wrote:You can use the macro recorder to find solutions like this...
[/code]

I hoped the answer would have been something like " activecellselection.value = "" " because anything more complicated exceeds my "coding" capability (wich is almost inexistent).

Sadly, I can't understand anything from the macro recorder.

After I manually select two or more cells, I would like the C button to do the same thing the backspace button does, or change the value of every selected cell to "". If there's a simple command to be written, I appreciate if you tell me.

Righ now the C button does this:
Code: Select all   Expand viewCollapse view
Sub RoundedRectangle12_Click()
ActiveCell.Value = ""
v= 0
End Sub
OpenOffice 4.1.6
Windows 10
soomeesaan
 
Posts: 6
Joined: Wed Jul 31, 2019 8:52 pm

Re: Virtual Numpad

Postby soomeesaan » Tue Aug 06, 2019 3:33 pm

Thiscomponent.CurrentSelection.ClearContents(1 OR 2 OR 4 OR 8 OR 16 OR 32 OR 64 OR 128 OR 256 OR 512)

Code: Select all   Expand viewCollapse view
Sub RoundedRectangle12_Click()
ActiveCell.Value = ""
Thiscomponent.CurrentSelection.ClearContents(1 )
v= 0
End Sub


Everything is working perfectly.
Thank you guys very much for your help!
OpenOffice 4.1.6
Windows 10
soomeesaan
 
Posts: 6
Joined: Wed Jul 31, 2019 8:52 pm

Re: Virtual Numpad

Postby JeJe » Tue Aug 06, 2019 3:40 pm

You don't have to understand anything from the macro recorder - that's the point of it. The above was what you get when you press the delete key and choose delete all from the pop up dialog. Here's what you get when you press the backspace... note the similarity to your post...


Code: Select all   Expand viewCollapse view
sub whateveryouwanttocallthesub
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:ClearContents", "", 0, Array())


end sub

Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 584
Joined: Wed Mar 09, 2016 2:40 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 4 guests