Lotusscript Array Question

Hi I have the following code that loops through a group of fields to see if they have been completed and displays a message if not. Question is, I want to be able to use the loop to also go to the incomplete field after it finds a field not completed using Call uidoc.GotoField( "Field" )

Not sure it Lotusscript what is the best way to accomplish this. I am assuming we need to match the array value with the corresponding field.

Thanks in advance.

A


Sub Click(Source As Button)
	
	Dim uiws As New NotesUIWorkspace 
	Dim s As New NotesSession 
	Dim uidoc As NotesUIDocument
	Dim doc As NotesDocument
	Dim arr() As String
	Dim arrField() As String
	Dim strStatus As String
	Dim i As Integer
	Redim arr(16)
	
	Set db=s.currentdatabase
	Set uidoc = uiws.CurrentDocument
	Set doc=uidoc.document
	
	arr(0) = uidoc.FieldGetText("BDateInt1")
	arr(1) = uidoc.FieldGetText("BDateInt2")
	arr(2) = uidoc.FieldGetText("BFingerDate")
	arr(3) = uidoc.FieldGetText("BAtdDate")
	arr(4) = uidoc.FieldGetText("BOrderDate")
	arr(5) = uidoc.FieldGetText("BITDate")
	arr(6) = uidoc.FieldGetText("BBCDate")
	arr(7) = uidoc.FieldGetText("BNPDate")
	arr(7) = uidoc.FieldGetText("BAddDate")
	arr(8) = uidoc.FieldGetText("BDSDate")
	arr(10) = uidoc.FieldGetText("BBlazeDate")
	arr(11) = uidoc.FieldGetText("BTCDate")
	arr(12) = uidoc.FieldGetText("BI9Date")
	arr(13) = uidoc.FieldGetText("BW4Date")
	arr(14) = uidoc.FieldGetText("BNEDate")
	arr(15) = uidoc.FieldGetText("BPOLDate")
	arr(16) = uidoc.FieldGetText("BBEDate")
	
	strStatus = uidoc.FieldGetText("EmpType")
	
	If strStatus = "Employee" Then
		For i =  Lbound(arr) To Ubound(arr)
			If  arr(i) = "Not Complete" Then
				Messagebox( "New Hire cannot be closed with open items." )
				Exit Sub
			End If
		Next i
	End If
	
	If strStatus = "Temp - Oasis" Then
		Redim Preserve arr(12)
		For i =  Lbound(arr) To Ubound(arr)
			If  arr(i) = "Not Complete" Then
				Messagebox( "New Hire cannot be closed with open items." )
				Exit Sub
			End If
		Next i
	End If
	
	If strStatus = "Temp - Other" Then
		Redim Preserve arr(14)
		For i =  Lbound(arr) To Ubound(arr)
			If  arr(i) = "Not Complete" Then
				Messagebox( "New Hire cannot be closed with open items." )
				Exit Sub
			End If
		Next i
	End If
	
	Messagebox( "New Hire  marked as closed." )
	
	Call uidoc.FieldSetText("BStatus","Completed")
	Call uidoc.Refresh
	Call uidoc.Save
	
End Sub

Open in new window

LVL 1
ajl7519Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

doninjaCommented:
I would recommend changing your array to not hold the field values but the field names instead.

Then use the arrays to get the value each time using the array field name.
Then if an incomplete is found you can pop the message up, use uidoc.gotfield(arr(i)) and then exit sub to stop processing at that point.

A little slower due to multiple fieldgettext but is more useful
0
ajl7519Author Commented:
I think I see what you are saying. I am actually applying this to a different part of the form. This code seems to work okay.




For f = Lbound(arrField) To Ubound(arrField) 
		If  uidoc.FieldGetText(arrField(f)) = "" Then
			Call uidoc.GotoField( arrField(f))
			Messagebox( arrField(f) + " is required" )
			Exit Sub
		End If
	Next f

Open in new window

0
ajl7519Author Commented:
Only problem is the the message box is going to give the field name which not as descriptive as I would like. I need to figure how use the array to get string I want, I could use a generic.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

ajl7519Author Commented:
Here we go.

This works. I set the For loop from 0 to the Ubound and then divide by 2, that way it will always go through the only the Fields for the loop. Later I added 5 to array so it goes to the field description in the message box. This way I can keep adding to the array later If need be.




Dim uiws As New NotesUIWorkspace 
   Dim s As New NotesSession 
   Dim uidoc As NotesUIDocument
   Dim doc As NotesDocument
   Dim arrField() As String
   Dim f As Integer
   Redim arrField(9)

        arrField(0) = "EmpType"
	arrField(1) = "Name"
	arrField(2) = "HireDate"
	arrField(3) = "DAI"
	arrField(4) = "EmpID"
	arrField(5) = "Employee Type"
	arrField(6) = "Name"
	arrField(7) = "Hire Date"
	arrField(8) = "DAI"
	arrField(9) = "Employee ID"
	
	strStatus = uidoc.FieldGetText("EmpType")
	
	For f =  0 To Ubound(arr) / 2
		If  uidoc.FieldGetText(arrField(f)) = "" Then
			Call uidoc.GotoField( arrField(f))
			Messagebox( arrField(f + 5) + " is required" )
			Exit Sub
		End If
	Next f

Open in new window

0
doninjaCommented:
You can also use a multi dimensional array which would be neater
value 0 holds field value 1 holds description. no dividing your bound rules.

i.e.

Redim arrField(5,2)
arrField(0,0) = "EmpType"
arrField(0,1) = "Employee Type"
arrField(1,0) = "Name"
arrField(1,1) = "Name"
arrField(2,0) = "HireDate"
arrField(2,1) = "Hire Date"
arrField(3,0) = "DAI"
arrField(3,1) = "DAI"
arrField(4,0) = "EmpID"
arrField(4,1) = "Employee ID"

etc
0
ajl7519Author Commented:
I see. That's what I was originally trying to do. So you still keep the bounds from lower to upper, but would be the syntax in the loop?
0
doninjaCommented:
I think this should work in your example


Dim uiws As New NotesUIWorkspace 
   Dim s As New NotesSession 
   Dim uidoc As NotesUIDocument
   Dim doc As NotesDocument
   Dim arrField() As String
   Dim f As Integer
   Redim arrField(5,2)
   arrField(0,0) = "EmpType"
   arrField(0,1) = "Employee Type"
   arrField(1,0) = "Name"
   arrField(1,1) = "Name"
   arrField(2,0) = "HireDate"
   arrField(2,1) = "Hire Date"
   arrField(3,0) = "DAI"
   arrField(3,1) = "DAI"
   arrField(4,0) = "EmpID"
   arrField(4,1) = "Employee ID"
	
   strStatus = uidoc.FieldGetText("EmpType")
	
	For f =  0 To Ubound(arr)
		If  uidoc.FieldGetText(arrField(f,0)) = "" Then
			Call uidoc.GotoField( arrField(f,0))
			Messagebox( arrField(f,1) + " is required" )
			Exit Sub
		End If
	Next f 

Toggle HighlightingOpen in New WindowSelect All

    

 Please take a moment to respond  
    Did this comment work for you?  Yes  Partially  No Was the comment complete?  Yes  Partially  No Was the comment easy to understand?  Yes  Partially  No Overall, how would you rate this comment?  Excellent  Good  Average  SubmitCancel  
   
 ID:37382982Author:doninjaDate:05/01/12 07:01 PMYour Comment

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
doninjaCommented:
To hopefully finalise this question you can use lbound and ubound on multi dimensial arrays.

By default the returned value will be first dimension defined.
in above ubound(arr) returns 4
there is an aptioonal value can be added to ubound or lbound to satte which dimension you require.
So to get second dimension in above
ubound(arr,2) returns 1

lbopund in both exampels would return 0 and can be used in loop script to define start position.
0
ajl7519Author Commented:
Thanks doninja. Your code works perfect, but I have a bizarre problem that only happens with the multidimensional array. I have a function that sets the date and time for fields in the form and for some reason I am receiving an error, "Unable to Interpret Date or Time." I click Ok and it sets the time and date okay, so I am not sure why that error would popup.

Maybe a bug?
0
doninjaCommented:
Are you collecting the date/time into an array that you have dimensioned to be a string ???
Are you saving information back into a field that is a date field ?

You need to collect date as string when getting value (.getfieldtext is ok here) and then do a convert to date CDAT when saving back to field if you want to keep the date format.
To know which field is a string either
Add an extra dimension to array that defines type
arrField(0,2)=1 or arrField(0,2)=2
..
..
if arrField(f,2)=1 then
  'is text work normally
else
  'is date convert text to date
end if

you could look and see if field name has date in it's name but that only works if your 100% sure all fields named that way
if instr(arrfiled(f,0),"date")>0 then
  'is a date
else

  'not a date
end if
Not good idea normally as just one field named slightly different and it stops working


Most compatible would be to get the field from the backend doc and check it's type
Would need to get doc=uidoc.document
Then on each filed get item=doc.getfirstitem(arrfield(f,0))
Check using if item.type=1024
Would mean longer code but covers multiple situations.

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.