Avatar billede oyejo Nybegynder
13. oktober 2003 - 19:16 Der er 11 kommentarer og
1 løsning

Hjelp Noen som kjenner Lotus Approach?

Benytter en Lotus Approach database, nå ønsker jeg å lage et script som setter inn en ny post (record) når jeg trykker på "+" tasten.
Noen som kan hjelpe.
Jeg vet ingen til om dette, så jeg håper på en forklaring  for dummies :-)
Avatar billede oyejo Nybegynder
15. oktober 2003 - 16:20 #1
Lukker spørsmålet da jeg fikk svar på en annen internettside.
http://mailman.anu.edu.au/mailman/listinfo/approach

Jeg stilte følgende spørsmål:

I try to check what key is pressed when a field in a form got the focus?
I use:

Sub Keydown(Source As Fieldbox, Charcode As Long, Repeats As Integer, _
                    Flags As Integer, Overridedefault As Integer)
End Sub

The problem:
How to check what key is pressed, and if a special key is pressed
( the "+" ), then I want to cancel the key before the field got the value.

****************************************************************

Det første  svaret jeg fikk:

In Approach you have to remove the char from the field as soon as the
key is released. Therefore, use the Keyup event because when Keydown
fires, the char isn't entered in the field yet. Second problem is that
you can't modify a fieldbox's properties while it has focus. Draw a line
object just next to the field, name it lneTmp say, and give it the same
colour as the form background so it can't be seen. Then this will remove
any + signs entered into the field:

Sub Keyup(Source As Fieldbox, Charcode As Long, Repeats As Integer,
Flags As Integer, Overridedefault As Integer)
If Charcode = 107 Then
CurrentView.Body.lneTmp.SetFocus
Source.Text = Left$(Source.Text, Len(Source.Text) - 1)
Source.SetFocus
Sendkeys "{END}"
End If
End Sub

If you type a long sequence like 66++5+55+++6++66+66++665++ etc ~very~
quickly you may defeat it but for normal data entry it should be fine.

Note this only traps the + keystroke, not a + pasted into the field.

Paul Bent
Northwind IT Systems
www.northwindit.co.uk

******************************************************
MITT 2. SPØRSMÅL:

Paul, Thanks for the answer.

Before I try to use your code. I'll ask you if it possible to do it in
an
easier way, when you know that.
When the keypress is the "+" nothing should be enterd in the field. The
field should keep it's standardvalue. (1)
You wrote. " when the keydown fires, the char isn't enterd in the field
yet."
But is it possibele to check the Charcode  before the characther is
enterd
in the field?
Or do I have to make a line object as you said? ( I have to do this for
a
lot of fields )

Øyvind
************************************************************
DET 2. SVARET

Keydown returns the Charcode just before it appears in the field but
there is no way to intercept the character and discard it. In Visual
Basic the parameter is KeyAsc and you can set it to 0 but this doesn't
work in Approach.

You only need to create one line object and one global sub to serve all
fields:

Public Sub sRemovePlus( _
dspObj As Display, Byval intCharCode As Integer)

If intCharcode = 107 Then
  With dspObj
  CurrentView.Body.lneTmp.SetFocus
  .Text = Left$(.Text, Len(.Text) - 1)
  .SetFocus
  Sendkeys "{END}"
  End With
End If

End Sub

Then paste this statement into the Keyup event of each fieldbox to call
the sub:

sRemovePlus Source, Charcode

Paul Bent
Northwind IT Systems
www.northwindit.co.uk
Avatar billede oyejo Nybegynder
16. oktober 2003 - 06:42 #2
Spørsmål 3
Paul, thanks again

I forgot to tell that the format of the field is double.
When the "+" enter the field, will it cause any problem?
When I try to place an "+" in the field, I got the message:
< The "+" isn't a number >

Øyvind
**********************************************************
Svar 3
Well if the fieldbox is bound to a non-text field there's no point in
using the Keyup script; Approach will only allow + to be entered in a
text or memo field.

Paul Bent
Northwind IT Systems
www.northwindit.co.uk
*********************************************************
Paul, thanks again

I forgot to tell that the format of the field is double.
When the "+" enter the field, will it cause any problem?
When I try to place an "+" in the field, I got the message:
< The "+" isn't a number >

Øyvind
Avatar billede oyejo Nybegynder
16. oktober 2003 - 09:56 #3
You can also try this API solution, as it seems to be
a bit more robust than the setfocus technique.

'Declares, put in Globals, Declarations
Declare Function GetFocus Lib "user32" () As Long

Declare Function SendMessageLong Lib "user32" Alias
"SendMessageA"( _
Byval hwnd As Long, _
Byval wMsg As Long, _
Byval wParam As Long, _
Byval lParam As Long) As Long

Const EM_UNDO = &HC7


'Put into your Keypress sub (not Keyup)
    If Charcode = 43 Then
        SendMessageLong GetFocus, EM_UNDO, 0&, 0&
    End If

Watch for wrapping when you paste these into
Approach...

Regards,

Keith Seeley
Avatar billede oyejo Nybegynder
17. oktober 2003 - 07:58 #4
Thanks for Your Solution Keith

With your solution it seems to me that the field could be a number field.
Is it correct?

I also want to test, what value the Field have before it got the focus.
When the field got the focus, I have 4 different choises.
1- I just press Enter-> then the field keep it's old value and the next
field got the focus
2- I set an new valut and press enter
3-I press "+", -> then I want to keep the old value in the field, and so get
a new record
( CurrentWindow.NewRecord)
4- I set a new value in the field and press "+", to get a new record

It's only point 3 that's a problem now. I have to set in the old value again
before I press "+" else the field got emty

Regards
Oyvind Johnsen
Avatar billede oyejo Nybegynder
17. oktober 2003 - 16:44 #5
> With your solution it seems to me that the field
> could be a number field.
> Is it correct?

Yes, that's correct.

> 3-I press "+", -> then I want to keep the old value
> in the field, and so get
> a new record
> ( CurrentWindow.NewRecord)
> 4- I set a new value in the field and press "+", to
> get a new record
>
> It's only point 3 that's a problem now. I have to
> set in the old value again
> before I press "+" else the field got emty

Would it be acceptable to set the cursor to the end of
the text in the fieldbox (so that the text is not
highlighted) when the field recieves focus?
If so, add the following to your script, then call the
sub sGotoEnd in the "Gotfocus" event of your fieldbox.

'Declares
'Note that you're already using some of these!

Declare Function GetFocus Lib "user32" () As Long

Declare Function SendMessageLong Lib "user32" Alias
"SendMessageA"( _
Byval hwnd As Long, _
Byval wMsg As Long, _
Byval wParam As Long, _
Byval lParam As Long) As Long

Const EM_UNDO = &HC7
Const EM_SETSEL = &HB1
Const EM_LINELENGTH = &HC1
Const EM_GETLINECOUNT = &HBA
Const EM_LINEINDEX = &HBB

'Once a fieldbox has focus, call this sub
'to put the cursor at the end of the text

Sub sGotoEnd
   
Dim lngNumLines As Long
Dim lngLength As Long
Dim lngCharsBeforeLastLine As Long
Dim lngCharsTotal As Long
   
On Error Resume Next

'Get the number of lines in the textbox...
lngNumLines = SendMessageLong(GetFocus,
EM_GETLINECOUNT, 0&, 0&)
   
'Count the number of characters BEFORE the last
line...
lngCharsBeforeLastLine = SendMessageLong(GetFocus,
EM_LINEINDEX, lngNumLines - 1, 0&)
   
'Count the number of characters IN the last line...
lngLength = SendMessageLong(GetFocus, EM_LINELENGTH,
lngNumLines, 0&)
   
'Get the total character count...
lngCharsTotal = lngCharsBeforeLastLine + lngLength

Yield

'Set the cursor position at the end of the last
line...
Call SendMessageLong(GetFocus, EM_SETSEL,
lngCharsTotal, lngCharsTotal)
   
End Sub


Finally, add a line to the Keypress event to create
the new record.
If Charcode = 43 Then
    SendMessageLong GetFocus, EM_UNDO, 0&, 0&
    CurrentWindow.NewRecord
End If


If you tab into the field this works well.  If you
click into the field you can inadvertantly highlight
some text, in which case you may still have some
problems.  I think I know a way around this, but I
won't pursue it unless this is the way you want to go.

Regards,

Keith Seeley
Avatar billede oyejo Nybegynder
21. oktober 2003 - 11:01 #6
The following script restores the default data on the
first keypress only (which I think is what you're
talking about).
To do this, you need to store it in a variable when
the field gets focus.  If the "+" key is the first key
pressed you can then restore the original text and tab
to the next field (or create a new record).  Due to
timing issues I don't think you'll be able to use a
single global variable to do this, so make sure you
dimension the variables locally in the "Declarations"
section of every fieldbox you place the script into:

'"Declarations" script of every
'fieldbox where this script is used
Dim intFirst As Integer
Dim strValue As String




'Gotfocus sub...

'Set the flag...
intFirst = True

'Store the current value in the fieldbox...
strValue = Source.Text






'Keypress sub...
   
If Charcode = 43 Then
'Check to see if this is the first keypress after
'  the fieldbox recieves focus...
If intFirst = True Then
'Change the text back to the original value...
SetWindowText GetFocus, strValue
Else
'Undo the last change to the fieldbox...
SendMessageLong GetFocus, EM_UNDO, 0&, 0&
End If
'Determine the course of action here...
       
'Create a new record...
'CurrentWindow.NewRecord
' OR...       
'Tab to the next field in the tab order...
CurrentWindow.TabNext
End If
   
'After the first keypress, clear the flag...
If intFirst = True Then intFirst = False
   


Regards,

Keith Seeley
Avatar billede oyejo Nybegynder
21. oktober 2003 - 11:04 #7
My apologies, I forgot to add the declare for
SetWindowText to my last message...

'Put in Globals, Declarations
Declare Function SetWindowText Lib "user32" Alias
"SetWindowTextA" ( _
Byval hwnd As Long, _
Byval lpString As String) As Long


Regards,

Keith Seeley
Avatar billede oyejo Nybegynder
21. oktober 2003 - 11:04 #8
Keith

Your last solution is PERFECT, THANKS!!!!

Best Regards
Øyvind Johnsne

PS! I hope you can help me on the next questinon also.
I want to test if an calculating field is greater than 0 before I go to a
new record
it's at the same field as this question.
Pleas see: Check the value of a formula field before allowed to go to a new
record
Avatar billede oyejo Nybegynder
22. oktober 2003 - 06:21 #9
In a form I use the keypress event to get a new record when I press the "+"

Before the CurrentWindow.NewRecord action,
I want to check that a formula field in the form got a value > 0

If the value isn't > 0, the I want to start over in the same record,
to correct the values.

For more info, look at the question :
Approach script, Event Keydown, check before uppdate
Avatar billede oyejo Nybegynder
22. oktober 2003 - 06:22 #10
If the calculated field isn't already on the form, add
it.  If you don't want it visible you can create a
temporary Sub in which you set the fields' visible
property to False.

Once the calculated field is on the view you'll have
to figure out it's Object name.  For normal fields the
name is listed on the Macro's tab of the Properties
dialog box, but for some reason you can't access a
calculated fields Object name.  It's almost always the
same as the name of the calculated field, but it can
be different.  If you can't figure out the calc fields
object name then post back for a way to retrieve it.

Once that's done, use an If...Then statement in you
sub:

If Val(CurrentView.Body.OBJ_NAME.Text) > 0  Then
    CurrentWindow.NewRecord
Else
    CurrentWindow.TabTo(1)           
End If


- Change OBJ_NAME to the object name of your
calculated field.

- Change the .TabTo() to the tab position that you
want to return to.
Avatar billede oyejo Nybegynder
22. oktober 2003 - 06:22 #11
I final question:
when I want to check if a field is emty, ( not filled ) how to I write the
code?
objName.Text = Null ?
Avatar billede oyejo Nybegynder
22. oktober 2003 - 06:23 #12
objName.Text = ""

where "" is two quotes with no space between them.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Computerworld tilbyder specialiserede kurser i database-management

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester