[Solved] Button for macros

Creating and using forms

[Solved] Button for macros

Postby dewayne ashley » Fri Mar 03, 2017 4:51 am

Hello,

I am trying to design a form that has 10 push buttons to insert the numbers 0-9 into the text field, more or less like a number data entry pad built into the form, ""think calculator buttons""

Example#1 = if i push button 1, it inserts 1 into the field.
Example #2 = if I push button 1 and then button 2 and then button 5, I should then see 125 in the text field.

I am trying to find examples of how to do this with macros.
The form will also have a ok button to save the record in the database field.

Any insight on how to do this would be greatly appreciated as this is for a touchscreen database form.

Thanks, 8-)
Last edited by dewayne ashley on Sat Mar 18, 2017 10:54 pm, edited 1 time in total.
Libreoffice 5.1.6.2 on Linux Mint 18
User avatar
dewayne ashley
 
Posts: 11
Joined: Fri Mar 03, 2017 4:25 am

Re: button macros

Postby Zizi64 » Fri Mar 03, 2017 8:08 am

You can assign your macro to the click event of the button.
And you can get the Event in the macro routine - to determine, which one of the buttons was clicked. Then you can get the Label of the clicked button (0; 1; 2; 3; ...9). And then you need get the Text field object, and append the actual character to the existing text content of the Text field.

You need study and use the API (Application Programming interface) functions of the office suite...
Tibor Kovacs, Hungary; LO4.4.7, LO5.3.6 on Win7x64Prof.
PortableApps, WinPenPack: LO3.3.0-LO5.4.2 and AOO4.1.3
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 5910
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Button for macros

Postby Zizi64 » Fri Mar 03, 2017 9:24 am

Here is a small example for Draw application (I never used the Base, but I want to show you an example outside the "trivial" Writer or Calc applications).

Buttons_and_Events.odg
(11.24 KiB) Downloaded 40 times


The macro code:
Code: Select all   Expand viewCollapse view
REM  *****  BASIC  *****

Sub Put_a_char(oEv as object)

Dim oButton as object
Dim oButModel as Object
Dim oParent as Object
Dim oTextBox as Object
Dim sChar as String
   
   oButton = oEv.Source
   oButModel = oButton.Model   
   oParent = oButModel.getParent()
   
   oTextBox = oParent.GetbyName("Text Box 1")
   
   sChar = oButton.Model.Label
   oTextBox.Text = oTextBox.Text & sChar

End Sub



Sub Del_a_char(oEv as object)

Dim oButton as object
Dim oButModel as Object
Dim oParent as Object
Dim oTextBox as Object
Dim sChar as String
   
   oButton = oEv.Source
   oButModel = oButton.Model   
   oParent = oButModel.getParent()
   
   oTextBox = oParent.GetbyName("Text Box 1")
   
   oTextBox.Text = Left(oTextBox.Text,Len(oTextBox.Text)-1)

End Sub



Sub Enter_button(oEv as object)

Dim oButton as object
Dim oButModel as Object
Dim oParent as Object
Dim oTextBox as Object
Dim sText as String
Dim iNumber as Long
   
   oButton = oEv.Source
   oButModel = oButton.Model   
   oParent = oButModel.getParent()
   
   oTextBox = oParent.GetbyName("Text Box 1")
   sText = oTextBox.Text
   iNumber = Val(sText)
Print "What to do with the entered string '", stext, "' and the converted ", inumber, " number?"

End Sub
Tibor Kovacs, Hungary; LO4.4.7, LO5.3.6 on Win7x64Prof.
PortableApps, WinPenPack: LO3.3.0-LO5.4.2 and AOO4.1.3
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 5910
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Button for macros

Postby dewayne ashley » Sat Mar 04, 2017 3:46 am

Thanks for the reply and suggestions Zizi64 , but it doesn't seem to work correctly
in a base form, its close though. The data i input with the buttons does show up in the text box. But after having set the data source in the properties of the form and text box to the correct table and column of the database, the record navigation indicates I have entered nothing at all, I think this is the key to the problem ,,,if i enter the data with a real keyboard the save icon instantly indicates that data has been entered , whereas with the onscreen buttons it doesn't , even after refreshing the form and checking the table to see if the record has changed, nothing to save and no entry made into the underlying table data.
Ideally, I need a way to mimic real keyboard input of data with onscreen buttons, My OS "Linux Mint" does have onscreen keyboard capabilities, but it seems a awful waste of screen real estate
and ill suited, as all I need is the 0-9 buttons and a decimal point button.
Any and all suggestions are appreciated,,, THANKS
Libreoffice 5.1.6.2 on Linux Mint 18
User avatar
dewayne ashley
 
Posts: 11
Joined: Fri Mar 03, 2017 4:25 am

Re: Button for macros

Postby Zizi64 » Sat Mar 04, 2017 8:34 am

Ideally, I need a way to mimic real keyboard input of data with onscreen buttons, My OS "Linux Mint" does have onscreen keyboard capabilities, but it seems a awful waste of screen real estate
and ill suited, as all I need is the 0-9 buttons and a decimal point button.

There are full featured virtual keyboard emulator softwares, and there are virtual numpads too.
Google it.
Tibor Kovacs, Hungary; LO4.4.7, LO5.3.6 on Win7x64Prof.
PortableApps, WinPenPack: LO3.3.0-LO5.4.2 and AOO4.1.3
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 5910
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Button for macros

Postby Zizi64 » Sat Mar 04, 2017 9:10 am

Thanks for the reply and suggestions Zizi64 , but it doesn't seem to work correctly

It was a simple example code only. You can modify, and adapt the macro code for your task (or you can write an another one) based on my idea - and based on the API functions.

As I wrote: I never used the BASE application, but if you upload YOUR example .odb file here (with the form, buttons and the text field), maybe somebody will help you.
Tibor Kovacs, Hungary; LO4.4.7, LO5.3.6 on Win7x64Prof.
PortableApps, WinPenPack: LO3.3.0-LO5.4.2 and AOO4.1.3
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 5910
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Button for macros

Postby dewayne ashley » Sat Mar 04, 2017 10:55 pm

Thank You Zizi64,
I think the macros you wrote for the Buttons_and_Events.odg are "OUTSTANDING" , and are precisely what I am looking for, with the only exception being that after many experiments, and many errors, I am unable to add to the macro code anything that puts the "button-input" into the underlying database table, but the macro code does put data into the text box on the form beautifully :super: .

I have put together a example for you, and anyone else for that matter, To tinker with and examine what could be the issue, as to what code needs to be added or settings tweaked.

Please try input into # box with both the onscreen buttons and a physical keyboard, Paying close attention to the record navigation icons at the bottom of the form, Specifically "Save Record" icon.

THANKS :D
Attachments
Button Test.odb
(14.07 KiB) Downloaded 44 times
Libreoffice 5.1.6.2 on Linux Mint 18
User avatar
dewayne ashley
 
Posts: 11
Joined: Fri Mar 03, 2017 4:25 am

Re: Button for macros

Postby Zizi64 » Sun Mar 05, 2017 2:25 pm

As I wrote: I never used the Base application... I can not switch the form control element od the form to Edit mode.
(I can to do it in Calc or in Writer...)
Therefore I can not see, what 'bulit-in' or 'user defined' function is assigned to the event/key "Enter" of the # box, and how it was assigned.

Sorry... I can not help you.
Tibor Kovacs, Hungary; LO4.4.7, LO5.3.6 on Win7x64Prof.
PortableApps, WinPenPack: LO3.3.0-LO5.4.2 and AOO4.1.3
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 5910
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Button for macros

Postby Arineckaig » Sun Mar 05, 2017 4:40 pm

as to what code needs to be added or settings tweaked.

At the end of the "Enter_button" macro add these lines:
Code: Select all   Expand viewCollapse view
   oForm = oParent
   oCol = oForm.findColumn("Number")
   oForm.updateString(oCol, sText)
   oForm.insertRow()

Remove the After Record action and change events from the Form as they will tend to be triggered rather too frequently.
When this issue has been resolved, it would help other users of the forum if you add the word - [Solved] - to the Subject line of your 1st post (edit button top right).
OOo 4.1.1 on MS Windows XP MySQL and HSQLDB
Arineckaig
Volunteer
 
Posts: 825
Joined: Fri Nov 30, 2007 10:58 am
Location: Scotland

Re: Button for macros

Postby Villeroy » Sun Mar 05, 2017 6:27 pm

ByteButtons.odt
(11.45 KiB) Downloaded 60 times
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24399
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Button for macros

Postby Arineckaig » Sun Mar 05, 2017 8:29 pm

Many thanks Villeroy for posting this fascinating Writer file - ByteButtons
When this issue has been resolved, it would help other users of the forum if you add the word - [Solved] - to the Subject line of your 1st post (edit button top right).
OOo 4.1.1 on MS Windows XP MySQL and HSQLDB
Arineckaig
Volunteer
 
Posts: 825
Joined: Fri Nov 30, 2007 10:58 am
Location: Scotland

Re: Button for macros

Postby Villeroy » Mon Mar 06, 2017 2:02 pm

You're welcome.
Arineckaig wrote:Many thanks Villeroy for posting this fascinating Writer file - ByteButtons
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24399
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Button for macros

Postby F3K Total » Tue Mar 07, 2017 1:03 am

Hello Villeroy,
would you mind to explain, why in this code
Code: Select all   Expand viewCollapse view
Sub NumboxModified(e)
'mri = createUnoService("mytools.Mri")
'mri.inspect(e)
x = e.Source.Value
frm = e.Source.Model.Parent
for each n in Array(1,2,4,8,16,32,64,128)
   btn = frm.getByName("Btn_"& n)
   btn.State = iif(x and n, 1,0)
next
End Sub

especially by this line
Code: Select all   Expand viewCollapse view
btn.State = iif(x and n, 1,0)
only the correct buttons were pressed?
I do not understand why
Code: Select all   Expand viewCollapse view
x and n
give true or not.
    MMove 1.0.6
  • Extension for easy, exact positioning of shapes, pictures, controls, frames ...
    my current system
  • Windows 7 OOo, AOO, LOLinux Mint OOo, AOO, LO
F3K Total
Volunteer
 
Posts: 890
Joined: Fri Dec 16, 2011 8:20 pm

Re: Button for macros

Postby Villeroy » Tue Mar 07, 2017 9:24 am

Basic help > Command Reference > Run-time functions > Logical Operators
The following logical operators are supported by OpenOffice Basic.
Logical operators combine (bitwise) the contents of two expressions or variables, for example, to test if specific bits are set or not.
[...]


7 and 4 => 4

0 1 1 1
0 1 0 0
--------
0 1 0 0
Last edited by Villeroy on Tue Mar 07, 2017 9:45 am, edited 2 times in total.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24399
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Button for macros

Postby F3K Total » Tue Mar 07, 2017 9:43 am

Thank you, got it, that's really tricky!
    MMove 1.0.6
  • Extension for easy, exact positioning of shapes, pictures, controls, frames ...
    my current system
  • Windows 7 OOo, AOO, LOLinux Mint OOo, AOO, LO
F3K Total
Volunteer
 
Posts: 890
Joined: Fri Dec 16, 2011 8:20 pm

Re: Button for macros

Postby Villeroy » Tue Mar 07, 2017 9:46 am

(x and n) returns either 0 (False) or n. Every non-zero number in evaluates to True.
More explicitly:
if x and n = n then
btn.State = 1
else
btn.State = 0
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24399
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Button for macros

Postby dewayne ashley » Thu Mar 09, 2017 1:47 am

Arineckaig wrote:
as to what code needs to be added or settings tweaked.

At the end of the "Enter_button" macro add these lines:
Code: Select all   Expand viewCollapse view
   oForm = oParent
   oCol = oForm.findColumn("Number")
   oForm.updateString(oCol, sText)
   oForm.insertRow()

Remove the After Record action and change events from the Form as they will tend to be triggered rather too frequently.


Did not work for me.
Libreoffice 5.1.6.2 on Linux Mint 18
User avatar
dewayne ashley
 
Posts: 11
Joined: Fri Mar 03, 2017 4:25 am

Re: Button for macros

Postby UnklDonald418 » Thu Mar 09, 2017 2:15 am

I've been following this and I put together a little demonstration based on the code that was posted on this thread. Perhaps it will help you.
Hopefully, I commented out all of my debugging code. Form1 uses a basic MainForm/SubForm arrangement and stores the value entered in an integer field in Table1. Form 2 uses a Dialog to get the data entry but it only displays the entered data in a text box on the Form after the Dialog ends.
Attachments
Demo05.odb
(26.45 KiB) Downloaded 47 times
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the subject line
Apache OpenOffice 4.1.3 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 546
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Button for macros

Postby dewayne ashley » Thu Mar 09, 2017 2:40 am

Looks Really Promising :D ,Give me a little while to shoehorn the code into a test copy of my .ODB ,,, and we will see how it goes...
Libreoffice 5.1.6.2 on Linux Mint 18
User avatar
dewayne ashley
 
Posts: 11
Joined: Fri Mar 03, 2017 4:25 am

Re: Button for macros

Postby Arineckaig » Thu Mar 09, 2017 12:40 pm

dewayne ashley:
Did not work for me.

Strange. The attached file is simply a copy of the one that you posted with the suggestions applied.

The suggested code was relevant to insertion of new records and thus applicable to Form1 of your posted file that was set for new entries only. If the macro is to apply also to updating existing records then a somewhat more complex code will be required:
Code: Select all   Expand viewCollapse view
oForm = oParent
   With oForm
      oCol = .findColumn("Number")
      .updateString(oCol, sText)
      IF .IsNew THEN
         .insertRow()
      ELSE .updateRow()
      END IF
   End With
Attachments
Button Test - ChangedCopy.odb
4 lines of code added: Form events removed
(14 KiB) Downloaded 45 times
When this issue has been resolved, it would help other users of the forum if you add the word - [Solved] - to the Subject line of your 1st post (edit button top right).
OOo 4.1.1 on MS Windows XP MySQL and HSQLDB
Arineckaig
Volunteer
 
Posts: 825
Joined: Fri Nov 30, 2007 10:58 am
Location: Scotland

Re: Button for macros

Postby dewayne ashley » Sat Mar 18, 2017 10:52 pm

dewayne ashley wrote:Looks Really Promising :D ,Give me a little while to shoehorn the code into a test copy of my .ODB ,,, and we will see how it goes...
I can now confirm that UnklDonald418's and Arineckaig's solutions both work for me, Many THANKS to UnklDonald418 and Arineckaig :bravo: I will mark as Solved.
Libreoffice 5.1.6.2 on Linux Mint 18
User avatar
dewayne ashley
 
Posts: 11
Joined: Fri Mar 03, 2017 4:25 am


Return to Forms

Who is online

Users browsing this forum: Google [Bot] and 5 guests