numeric input via an onscreen 10-key or calculator type interface

G

geoff

I want to convert a form that accepts numeric input via
that keyboard to one that accepts the values from the
screen via a popup calculator style interface that the
users operate with mouse clicks or stylus, is there an
easy way to do this in access(2002)? thanks

geoff.
 
J

Jeff Bennett

geoff said:
I want to convert a form that accepts numeric input via
that keyboard to one that accepts the values from the
screen via a popup calculator style interface that the
users operate with mouse clicks or stylus, is there an
easy way to do this in access(2002)? thanks

geoff.

OK, yes this is easy.

Put 10 button controls as a control array on the form
with captions 0 through 9 and index values 0 through 9.
Let's say they are all named cmdCalcNumButton.
Add a label ontrol on the form, we'll call it lblCalcValue.
Add the following code
Sub cmdCalNumButton_Click ( Index as Integer)
lblCalcValue.caption = lblCalcValue.caption & trim(Index)
End Sub
That's it. You are done.
If you like you can add other buttons ( not in control array ) to
support a decimal point
Sub cmdCalDecButton_Click ( )
lblCalcValue.caption = lblCalcValue.caption & "."
End Sub
and a backspace function
Sub cmdCalcBackButton_Click ( )
lblCalcValue.caption = left$( lblCalcValue.caption , _
len(lblCalcValue.Caption)-1 )
End Sub
and a clear button
Sub cmdCalcClearButton_Click ( )
lblCalcValue.caption = ""
End Sub



I hope this is helpful to you



-----

Jeff Bennett
(e-mail address removed)

* Bennet-Tec Information Systems, Inc
* 50 Jericho Tpk, Jericho, NY 11753
* Phone 516 997 5596, Fax - 5597
* RELIABLE Components Make You Look Sharp!
* TList/Pro * ALLText HT/Pro * MetaDraw *
* Custom Software Development Services Too.
* WWW.Bennet-Tec.Com

=================== ===================
 
J

Jeff Bennett

My appologies.
In my note below I proposed using control arrays.
I do more work in VB than in Access VBA and I didn't realize it,
but apparently Access VBA doesn't support control arrays.

Anyway the idea then is pretty much the same,
the difference is that you'll need code in the
click event for each button. ( If access supported
control arrays, all the numeric buttons could have
the same name and would generate the same event,
distinguished only by an Index for each control -
It's a nice feature in VB but you can live without it. )

Instead of 10 buttons with the same name in a control
array with code:

Sub cmdCalNumButton_Click ( Index as Integer)
lblCalcValue.caption = lblCalcValue.caption & trim(Index)
End Sub
You'll have 10 buttons with distinct names and events
Sub cmdCalcNumButton0_Click ( Index as Integer)
lblCalcValue.caption = lblCalcValue.caption & "0"
End Sub
Sub cmdCalcNumButton1_Click ( Index as Integer)
lblCalcValue.caption = lblCalcValue.caption & "1"
End Sub
Sub cmdCalcNumButton2_Click ( Index as Integer)
lblCalcValue.caption = lblCalcValue.caption & "2"
End Sub
Sub cmdCalcNumButton3_Click ( Index as Integer)
lblCalcValue.caption = lblCalcValue.caption & "3"
End Sub

etc

Jeff Bennett
(e-mail address removed)

* Bennet-Tec Information Systems, Inc
* 50 Jericho Tpk, Jericho, NY 11753
* Phone 516 997 5596, Fax - 5597
* RELIABLE Components Make You Look Sharp!
* TList/Pro * ALLText HT/Pro * MetaDraw *
* Custom Software Development Services Too.
* WWW.Bennet-Tec.Com

=================== ===================
 
M

Marshall Barton

geoff said:
I want to convert a form that accepts numeric input via
that keyboard to one that accepts the values from the
screen via a popup calculator style interface that the
users operate with mouse clicks or stylus, is there an
easy way to do this in access(2002)?


I don't know what you may think is easy, but Jeff's second
idea can be made a little easier.

First, I would suggest using a text box instead of a label
control to store the entered value (not a big deal, but a
litlle easier to manipulate). Next, you don't have to have
10 Click event procedures. You can get away with one
Function instead:

Public Function CalNumButton(N As Integer)
txtValueEntered = txtValueEnterd * 10 + N
End Function

Then, set the OnClick property of the buttons to
=CalNumButton(0)
=CalNumButton(1)
. . .
=CalNumButton(9)

Now that we have the easy stuff out of the way, what about
all the other buttons that are normally found on a
calculator?
 
D

Douglas J. Steele

You can make it even easier than that, Marshall.

You can determine what button was clicked using Me.ActiveControl.Name. I'm
assuming that the caption for each button is the digit it represents (If
not, since the 10 buttons are named cmdCalcNumButton0 through
cmdCalcNumButton9, the button number is the right-most character of name)

That means your function is:

Public Function CalNumButton()

txtValueEntered = CInt(Nz(txtValueEntered)) * 10 + _
CInt(Me.ActiveControl.Caption)

End Function

and the OnClick property for all 10 buttons is =CalNumButton(). (I find this
easier since you can select all 10 buttons at once, and set their OnClick
property to the same thing in one step, rather than having to set the
OnClick property for each button separately)
 
J

Jeff Bennett

One more update I had still left reference to non existing
INDEX values in my correction. Also forgot Access requires
focus shift back to textbox before changing it. ( and Marshall
is correct that it's better to use Textbox than lable.

You'll have 10 buttons with distinct names and events

Sub cmdCalcNumButton0_Click()
lblCalcValue.SetFocus
lblCalcValue.Text = lblCalcValue.Text & "0"
End Sub
Sub cmdCalcNumButton1_Click()
lblCalcValue.SetFocus
lblCalcValue.Text = lblCalcValue.Text & "1"
End Sub
Sub cmdCalcNumButton2_Click()
lblCalcValue.SetFocus
lblCalcValue.Text = lblCalcValue.Text & "2"
End Sub
Sub cmdCalcNumButton3_Click()
lblCalcValue.SetFocus
lblCalcValue.Text = lblCalcValue.Text & "3"
End Sub

Sub cmdCalcNumButton4_Click()
lblCalcValue.SetFocus
lblCalcValue.Text = lblCalcValue.Text & "4"
End Sub
Sub cmdCalcNumButton5_Click()
lblCalcValue.SetFocus
lblCalcValue.Text = lblCalcValue.Text & "5"
End Sub
Sub cmdCalcNumButton6_Click()
lblCalcValue.SetFocus
lblCalcValue.Text = lblCalcValue.Text & "6"
End Sub
Sub cmdCalcNumButton7_Click()
lblCalcValue.SetFocus
lblCalcValue.Text = lblCalcValue.Text & "7"
End Sub
Sub cmdCalcNumButton8_Click()
lblCalcValue.SetFocus
lblCalcValue.Text = lblCalcValue.Text & "8"
End Sub
Sub cmdCalcNumButton9_Click()
lblCalcValue.SetFocus
lblCalcValue.Text = lblCalcValue.Text & "9"
End Sub

' and here we can add in the code for a clear button and
a back button

Sub cmdCalcBackButton_Click()
lblCalcValue.SetFocus
If Len(lblCalcValue.Text) > 0 then
lblCalcValue.Text = Left(lblCalcValue.Text,
Len(lblCalcValue.Text) - 1)
End If
End Sub

Sub cmdCalcClearButton_Click()
lblCalcValue.SetFocus
lblCalcValue.Text = ""
End Sub

Note that I have attached an Access MDB with a working sample on the
form.


I hope this is helpful to you.



PS - think of us for any future need
of Active X components,
or programming services


Jeff Bennett
(e-mail address removed)

* Bennet-Tec Information Systems, Inc
* 50 Jericho Tpk, Jericho, NY 11753
* Phone 516 997 5596, Fax - 5597
* RELIABLE Components Make You Look Sharp!
* TList/Pro * ALLText HT/Pro * MetaDraw *
* Custom Software Development Services Too.
* WWW.Bennet-Tec.Com

=================== ===================
 
M

Marshall Barton

Douglas said:
You can make it even easier than that, Marshall.

You can determine what button was clicked using Me.ActiveControl.Name. I'm
assuming that the caption for each button is the digit it represents (If
not, since the 10 buttons are named cmdCalcNumButton0 through
cmdCalcNumButton9, the button number is the right-most character of name)

That means your function is:

Public Function CalNumButton()

txtValueEntered = CInt(Nz(txtValueEntered)) * 10 + _
CInt(Me.ActiveControl.Caption)

End Function

and the OnClick property for all 10 buttons is =CalNumButton(). (I find this
easier since you can select all 10 buttons at once, and set their OnClick
property to the same thing in one step, rather than having to set the
OnClick property for each button separately)


Good point Doug.
 
D

Douglas J. Steele

A couple of things, Jeff.

You don't need to set the focus to a text box to change its value if you set
its Value property rather than its Text property. (Value is the default
property, which is why Marshall & I were just using txtValueEntered: to be
precise, we should have been using txtValueEntered.Value)

And check the refinements Marshall & I suggested regarding having a single
function, rather than a different one for each button. That makes it much
easier to maintain the code.

Thanks for your participation in these newsgroups, though. Still very
impressed with your TList control!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top