Lotus Notes - Numbering sequence in script reaches limit

captain
captain used Ask the Experts™
on
Hi

this is a code we have been using in a Notes Document to generate a number for use in a document, based on a +1 increment from the previous number used.

The code was discussed in this Question

It has been working great until now that we have reached sequential number 32767, which according to IBM is the maximum value limit to integers being used in additions.

According to the above KB, the workaround is to use a '1.0' instead of a '1' to add, but this does not work in the code below.


Function GenSeqNo() As String      
	Dim session As New NotesSession
	Dim w As New NotesUIWorkspace
	Dim db As NotesDatabase
	Dim lookupView As NotesView
	Dim doc As NotesDocument, lookupDoc As NotesDocument
	Dim nextNum As Integer      
	
	Set db = session.CurrentDatabase
	
      'This is how you get current document, not using session
	Set doc = w.CurrentDocument.Document
	
	'If doc.IsNewNote Then        'Exit if this is not a new document
	Set lookupView = db.GetView( "SeqNoView" )      'get the view containing the dummy doc
	Set lookupDoc = lookupView.GetFirstDocument( )      'only one doc in view            
	Call lookupDoc.Lock( )
	nextNum = Cint( lookupDoc.SeqNo(0) ) + 1.0      'retrieve next number            
	lookupDoc.SeqNo = Cstr( nextNum )                  'increment existing number in dummy doc
	Call lookupDoc.Save( True, False, True )
	Call lookupDoc.Unlock( )
	
	GenSeqNo = Cstr( nextNum )
'End If
	
End Function

Open in new window


MQ: Is it possible to amend the code to use the workaround? If so how?

Thx
capt.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Sjef BosmanGroupware Consultant
Commented:
Use a Long instead of an Int.
Do you need 32767 or more? Can it wrap round with code such as

if   Cint( lookupDoc.SeqNo(0) ) = 32767
    nextNum = 1
else
    nextNum = Cint( lookupDoc.SeqNo(0) ) + 1
End if

I don't know too much about notes but I assume the workaround suggests add 1.0 to nextnum so that the inferred datatype is long and not integer. However in your code nextnum is explictly dimmed as an integer. As sjef say use long - Dim nextNum As long

You wouldn't need 1.0 as longs are bigger than integers
captainTechnical Director

Author

Commented:
Perfect idea, let me try.
captainTechnical Director

Author

Commented:
Thanks both that did the trick!
Thanks for first Notes points :-P
Sjef BosmanGroupware Consultant

Commented:
Danke Herr Kapitän!

@Andy, happy to have shared some with you! :)
:-)
captainTechnical Director

Author

Commented:
Hi Guys

This has stopped working today, I am getting lock errors and overflow errors, not sure why and how.

New Q opened, see here

Thx
capt.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial