Lotus Notes: Comparing two fields - lotus-notes

I have two dialoglist fields Cutt_Start and Cutt_End, both of the fields has example choices of: January | 1
February | 2
March | 3
...
December | 12
Now, what I want to happen is that, when you select January on the Cutt_Startand March on the Cutt_End, it should prompt an error that Month2 should be next to Month1. I tried this code, but nothing happens.
If Cutt_Start = "January" & Cutt_End <> "February" Then
Msgbox "Month2 should be next to Month1"
Else
Msgbox "January to February selected"
End If
Can you help me?

As already mentioned, the stored field values are the ones right of the pipe. BUT: such fields are always text- fields!!!!
To do a computation, you need to transform the text to numbers...
_start := #TextToNumber( Cutt_Start );
_end := #TextToNumber( Cutt_End );
_res := _end - #Modulo(_start; 12)
#If( !#IsError(_res) &_res != 1; #Failure( "your message" ); #Success)
This goes into the field validation of the Cutt_end- field.
If you need LotusScript (to have it in the QuerySave or the OnChange-Event of the field, then the code would be:
Option declare
Dim ws as New NotosUiWorkspace
Dim doc as NotesDocument
Set doc = ws.CurrentDocument.Document
If Cint(doc.Cutt_End) - CInt(doc.Cutt_Start) <> 1 then
messagebox "your Message"
End if
This code does NOT contain any errror handler.
And as mentioned in the other comments: this for sure is not the right way to do it. If cut_end always has to be one month later, then simply change it to computed and write as value:
#If(Cutt_Start = ""; ""; #Text(#Modulo(#TextToNumber( Cutt_Start ); 12) + 1))
Then you would not need to make your check...

The number to the right of the pipe character is the value of the field. The name to the left of the pipe is what is displayed to the user.
So if you just test that the numbers are sequential, and add a special case for Dec to Jan (1 comes after 12) then you should get the result you are looking for.
Note that the number value is still in text format so you'll need to cast it to a number first
If Cutt_End - Cutt_Start <> 1 Then Msgbox "Error!"
That said, if the Cutt_End must always be 1 month after Cutt_Start, then why have that field at all? Just calculate that field and make the user just choose the start month.

Please check the following and put your code into the onchange event. For web and the notes client the onchange function behavior is different.

Related

visual basic: user inputs a % sign after text

Private Sub btnBillSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBillSearch.Click
If Me.txbBILL_NR.Text = "" Or Me.txbBILL_NR.TextLength >= 4 Then
Try
Search()
If Me.bsBillGrid.Current IsNot Nothing Then
Me.dgvBill.Focus()
End If
Catch ex As Exception
Utility.ExceptionManager.HandleException(ex)
End Try
Else
MessageBox.Show("enter at least 4 numbers")
End If
End Sub
I have this method for search button in my app.
So, I already wrote the If condition for where user enters a minimum number of characters is 4 to select entries.
I need to one more validation for % sign. I figured out, that is kinda startWidth(), but I do not understand how I can get those situations:
I think about using startWith/endWith or regex maybe.
Could anyone please give me some advice where to look at.
user adds “%” sign after txbBILL_NR - the system does not add additional “%” in the background,
txbBILL_NR with identical part number are found and reflected in the list.
the user has not added the “%” sign after the txbBILL_NR - the system adds an additional “%” in the background,
txbBILL_NR with identical no. parts are found and listed.
The "%" character does not need to be represented by the user;
3.user added “%” sign at the beginning or middle of txbBILL_NR - the system does not add an additional “%” in the background,
txbBILL_NR with identical part number are found and reflected in the list (no changes required);
The "%" system only needs to be marked if the user has entered at least 4 characters in the txbBILL_NR field (assuming that the invoice number cannot be shorter than 4 characters.
If the user has entered at least 4 characters (whether they are starting characters or from the middle) and "%" is added to the beginning or middle of these symbols, the system does not add an additional "%" in the background
the invoice (s) with the identical part (symbol) part are found and reflected in the list.
'Get raw user entry.
Dim searchText = txbBILL_NR.Text
'Get user entry without wildcards.
Dim cleanSearchText = searchText.Replace("%", String.Empty)
If cleanSearchText.Length = 0 OrElse cleanSearchText.Length >= 4 Then
If searchText = cleanSearchText Then
'There are no wildcards so append one.
searchText &= "%"
End If
'Use searchText here.
End If
I think this function meets your requirements.
Private Function SearchCriterium(ByVal Crit As String) As String
' 295
Const Mark As String = "%"
Dim Fun As String ' function return value
Fun = Crit
Do While (Len(Fun) >= 4) And (Right(Fun, 1) = Mark)
Fun = Left(Fun, Len(Fun) - 1)
Loop
If Len(Fun) < 4 Then
MsgBox "Enter at least 4 characters.", _
vbExclamation, "Invalid search crterium"
SearchCriterium = Crit
Else
If InStr(Fun, Mark) = 0 Then Fun = Fun & Mark
End If
SearchCriterium = Replace(Fun, Mark, "*")
End Function
Observe that it replaces the % sign with VBA's wild card character *. You can remove that feature if you don't need it at that point.
The function removes any existing trailing placeholder and then adds one if none exists elsewhere in the string. Here is a list of the tests I ran.
Private Sub Test_SearchCriterium()
Debug.Print SearchCriterium("Item")
Debug.Print SearchCriterium("It%em")
Debug.Print SearchCriterium("%Item")
Debug.Print SearchCriterium("Ite%")
Debug.Print SearchCriterium("It%%")
End Sub

Lotus Notes: Sum of hours

I have two editable time/date fields, TimeIn and TimeOut, and one computed for display field hoursWorked, what it does is get the difference between TimeIn and TimeOut and display it in hours:minutes, e.g (02:30 hrs). I decided to have another editable time/date fieldTimeIn_1 and TimeOut_1 field and computed for display field hoursWorked and another computed for display field totalHours, which displays the total/sum of hours of hoursWorked and hoursWorked_1. I tried this code:
thours:=#If(hoursWorked=null | hoursWorked_1=null; #Return(""); "" );
seconds := hoursWorked+hoursWorked_1;
hours := #Integer(seconds/3600);
minutes := #Integer(#Modulo(seconds;3600)/60);
output := #Right("00" + #Text(hours); 2) + ":" + #Right("00" + #Text(minutes); 2);
#TextToTime(output)
but nothing happens. Can you help me?
I assume that you calculated your fields hoursWorked and hoursWorked_1 the same way like in this formula shown. If that is the case, the fields hoursWorked and hoursWorked_1 are from type "Date/Time" in document no matter how you define the fields in form.
That's why your formula should look like this:
thours:=#If(#IsNull(hoursWorked) | #IsNull(hoursWorked_1); #Return(""); "" );
nullTime := #ToTime("00:00");
seconds := (#ToTime(hoursWorked) - nullTime)+ (#ToTime(hoursWorked_1) - nullTime);
hours := #Integer(seconds/3600);
minutes := #Integer(#Modulo(seconds;3600)/60);
output := #Right("00" + #Text(hours); 2) + ":" + #Right("00" + #Text(minutes); 2);
#TextToTime(output)
Only first three lines are different to your formula.
I don't believe the first test of hoursWorked=null is correct. I think you need #IsNull(hoursWorked). That said I would think the result would still be false and the formula would continue.
It might be worthwhile to see just what output produces without the #TextToTime.

Formatting strings in a text field in Crystal Reports XI

Good morning!
I'm hoping someone can help me with what is probably a simple question but I just cant get things to work the way I would like. I am currently working with a report that has a "catch-all" text field. In this field the user can input anything they want, and on occasion, will input information in a column format (ex. 1.1). This field allows carriage returns which are used to create "rows" in this field. The problem is that the user wants the "columns" in this field to line up on the report without having to count spaces between the columns when the information is entered (ex. 1.2). The problem is that even when this type of information is entered there is no set protocol or formatting guidelines. There may be multiple "subtitles", rows, rows separated by subtitles, etc.. The carriage return (Chr(10)) at the end of each line (or beginning of each new line) is the only thing that can be relied on consistantly.
I am currently trying to seperate each individual row, format each as desired, and put it back together like so:
Dim output As String
Dim sections as String
Dim returnCount as Int
Dim leftText as String
Dim rightText as String
Dim sectionTogether as String
Dim totalText as String
Dim textLength as Int
output = {table.textfield}
sections = ExtractString(output, Chr(10), Chr(10))
If Instr(sections," ") > 0 Then
leftText = Left(sections, Instr(sections, " "))
textLength = Length(Left(sections, Instr(sections, " "))
rightText = Right(sections, Instr(sections, " "))
Replace(sections," "," ")
sectionTogether = rightText + (Space(20) - (textLength - 3)) + leftText
totalText = totalText + sectionTogether
formula = totalText
else
formula = output
This is the gist of what I'm trying to do. A couple of notes:
1) I know I am missing a loop of some kind to format every section but I dont know how to set that up in crystal
2) I have VB programming experience, but I am noob in crystal and its limited tools so I feel hamstringed and I'm having trouble finding the methods and tools I would use in Visual Studio
3) My syntax may also be off in a few places because I am still learning how to set this up and I REALLY miss a debugger.
I hope someone can help me, I have been researching for over a week and it feels like I'm just beating my head against a wall.
Thank you in advance.
The output examples
ex. 1.1
"Your current charges are:
Jan 12.89
Feb 117.44
Mar 15.02
Apr 4.17"
ex. 1.2
"Your current charges are:
Jan 12.89
Feb 117.44
Mar 15.02
Apr 4.17"
The first thing you're going to want to do is split up your rows via split(), like this:
local stringvar array wallOText := split({table.textfield},chr(10));
This will give you an array of strings where each array entry is a "row". Now you can loop over your rows with the following:
for i := 1 to ubound(wallOText) step 1 do <some stuff to wallOText[i]>
Now, getting the columns right-justified is a little trickier, but here's some code to get you started. You can adjust the column widths to whatever you may need (in this case, 20 spaces). Also note, you have to use a fixed-width font.
local stringvar output;
local stringvar array row;
local numbervar i;
local numbervar j;
local stringvar array wallOText := split({#some text},chr(10));
local stringvar elem;
for i := 1 to ubound(wallOText) do //loop over lines
(row := split(wallOText[i]," ");
for j := 1 to ubound(row) do //loop over words
(elem := trim(row[j]); //get current element and cut white space
if not(elem="") then
output := output + space(20-len(elem)) + elem); //build output string
output := output + chr(10));
output

Using multiple values field in Lotus Notes

I am trying to write a logging system for a form in Lotus Notes but I am at the part where I am not sure how I can append the information about the fields that are changed in the log fields. There are 3 fields that I use Log_Date (date), Log_User and Log_Actions (Text, allow multiple values).
I thought if I add comma to the log field it will create a new line when displaying the form but I am still getting a type mismatch on the case 2 line.
How can I append the new values to the log fields?
Sub Querysave(Source As Notesuidocument, Continue As Variant)
' Compare the values in the form after it is saved with its original values when the document is not a new document.
Dim doc As NotesDocument
Set doc = Source.Document
Dim session As New NotesSession
Dim user As String
user = session.CommonUserName
If newDoc Then
doc.Log_Date = Now()
doc.Log_User = user
doc.Log_Actions = "New document created."
Else
' Load fields value to the array
lastValues(0) = doc.QCR_No(0)
lastValues(1) = doc.QCR_Mobile_Item_No(0)
lastValues(2) = doc.QCR_Qty(0)
' Compared each value in the array to see if there is any difference
Dim i As Integer
For i = 0 To 2
If lastValues(i) <> originalValues(i) Then
Select Case i
Case 2 : doc.Log_Actions = doc.Log_Actions & "," & "Field QCR_Qty is changed"
End Select
End If
Next
End If
End Sub
doc.Log_Actions returns the notesitem. To access the value you need to use doc.Log_Actions(0)
In LotusScript back-end classes (e.g. NotesDocument, NotesItem), a multi-valued field is represented by an array with one value per element of the array. For setting the value of a field, doc.Log_Actions is shorthand (they call it 'extended syntax' in the Domino Designer help) for assigning the first (i.e., zero subscript) element of the array, but that does not work for getting the value. To get the first value, you have to use doc.Log_Actions(0). To get or set the second value, you have to use doc.Log_Actions(1).
So, your Case 2 code could look like this:
doc.Log_Actions(1) = "Field QCR_Qty is changed"
My guess, however, is that you really want to be able to continually append to the end of the list of values each time this code runs. You are also going to want your code to be robust and not blow up on you if (for any reason!) the Log_Actions item does not exist in the document. For that, you are going to want to do this:
dim actionsItem as NotesItem
if doc.hasItem("Log_Actions") then
set actionsItem = doc.getFirstItem("Log_Actions")
call actionsItem.AppendToTextList("Field QCR_Qty is changed")
end if
Or,
If (Not doc.HasItem("LogActions")) Then
doc.LogActions = "Field QCR_Qty is changed"
Else
doc.LogActions = ArrayAppend(doc.LogActions,"Field QCR_Qty is changed")
End If
This is equivalent to the NotesItem method by rhsatrhs, which you use is matter of preference.

how to save null value in subsonic

Dim xbg As Rm
xbg.LobId = cmb_lob.SelectedValue
xbg.Mobile = mobno.Text
xbg.BusinessFax = faxno.Text
xbg.BusinessPhone = phno.Text
xbg.Save()
I have a combo box, which is not mandatory while input in the module. therefore user can select blank value in combo cox for which i want to save null in Oracle Database for that record. I had trid with following condition but fails to get result. you are requested to please help
if cmb_lob.selectedindex=-1 then
xbg.lob=dbnull
else
xbg.LobId = cmb_lob.SelectedValue
Actual Problem arises when first user save record with selection in Combo box then user edit that record and select blank from Combo box. now i have to replace value of combox box with null at database.
Set it to null or whatever VB considers null - it will be set in the DB that way.
try:
if cmb_lob.selectedindex <> -1 then
xbg.LobId = cmb_lob.SelectedValue
else
xbg.LobId = Nothing 'suggested by John Shean (see comments)
So that if the value is selected only then assign it to field else leave it as it is (null)
Try xbg.LobId = Nothing instead –
By John Sheehan

Resources