ajl7519
asked on
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
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
ASKER
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
ASKER
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.
ASKER
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.
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
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
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
ASKER
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
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?
Maybe a bug?
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(arrf ield(f,0))
Check using if item.type=1024
Would mean longer code but covers multiple situations.
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"
'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(arrf
Check using if item.type=1024
Would mean longer code but covers multiple situations.
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