Check numeric field lotusscript - lotus-notes

I have a field on a form called "fin_Paiement". What I want to do is: the field value to accept only numbers and points and to replace any other character by a point. I did it for alphabetic values with replace funciton but it doesn't work.
I tried this :
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim db As NotesDatabase
Set uidoc = workspace.CurrentDocument
Set doc = uidoc.Document
doc.fin_Paiement = Replace(doc.fin_Paiement_Montant(0), "*[a-z,A-Z]*", ".")
I will appreciate your help! Thanks

Create a function which changes all non-digits to dots
Function ToDigitsAndDots(orig As String) As String
Dim i As Integer
Dim char As String
For i=1 To Len(orig)
char = Mid(orig, i, 1)
If Not char Like "#" Then char = "."
JustDigitsAndDots = JustDigitsAndDots & char
Next
End Function
and change your code line to
doc.fin_Paiement = ToDigitsAndDots(doc.fin_Paiement_Montant(0))

LotusScript's Replace method doesn't support regular expressions. You would have to make the second parameter an array of all letters, for example:
doc.fin_Paiement = Replace(
Cstr(doc.fin_Paiement_Montant(0)),
Split("a, b, c, d, e, f, g, h, i, j, you get the idea...", ", "),
"."
)
Note, I haven't tested this but in theory it should do the trick.

Please relieve me of an awful doubt : your field is of type "Number", isn't it ? In which case, no code is needed, it accepts only numbers, and the decimal separator is specified in its properties. By default, the locale settings for a field are those of the Notes client, which, by default, are those of the operating system, so normally not something you should worry about.
Anyway, this is the kind of thing you typically don't do in LotusScript !
Most straightforward is to use #functions in one of the field's events.
Check your Designer Help, here is some hint , and you may want to review this.

Related

Lotus Notes Database Search

i am trying to write a code to open VBA and do search based on the cell value in A1 (integer). i managed to write a code up to point where i can open the lotus notes and go to specific database. I tried many online codes but couldn't manage to find the code to search in that database. "Lotus.NotesSession" doesn't work the excel version i use. Could you please help me to finish this code. Code is below:
Sub macro4()
Dim uiWs As Object
Dim dbname As String
Dim serverName As String
Dim db As NotesDatabase
Dim doccol As NotesDocumentCollection
Dim varA As Integer
dbname = "***"
serverName = "***"
Set uiWs = CreateObject("Notes.NotesUIWorkSpace")
Call uiWs.OpenDatabase(serverName, dbname)
Set db = uiWs.GetDatabase(serverName, dbname) ---->where i get the error
varA.Value = Sheets("sheet1").Range("A1").Value
Set doccol = db.FTSearch(varA, Nothing, 0)
End Sub
In Notes there are two "parent"- classes to derive everything from. The NotesUIWorkspace is the class for the "frontend": It contains everything that you SEE in the client. The NotesSession is the class for the backend. NotesDatabase is a backend- class. To correctly get your database, you need to use NotesSession:
Set ses = CreateObject("Notes.NotesSession")
Set db = ses.GetDatabase(serverName, dbname)
You mixed up COM and OLE Integration. The thing you tried to use (Lotus.NotesSession) is for COM only and you need to include Notes in your project to use this.
For your example to work you need to use the OLE integration: Notes.NotesSession
Now to your "Search"- Code:
There are two different ways to search a NotesDatabase:
There is the Fulltextsearch and the "normal" search.
The Fulltextsearch just searches for your value everywhere in all documents and returns a collection. A search for "Tom" in a mailfile will find all mails / calendar entries that where:
sent by Tom
received by Tom
have the word "Tom" in subject or body or an attachment of the mail.
The syntax for FTSearch is:
Set doccol = db.FTSearch( YourSearchValue )
You can restrict the search to one certain field by using a special syntax for your search. e.G. to only search in the "From" field you could write
[From] = "YourSearchValue"
In FTSearch the "=" always means "contains"
The normal search uses a Formula (in #Formula- syntax) to search for a document. It needs the right syntax, otherwise it will not find anything. A formula to search all documents that come from "Tom" would be:
#Contains( From ; "Tom" )
The syntax for search is:
Set doccol = db.Search( YourQueryAsExampleAbove, Nothing, 0 )
With Nothing = Cutoffdate (if given only return documents created or modified after the date) and 0 = max. number of documents to return (0 = return everything).
So your example code for the could be something like:
strQuery = "FieldToSearch = " & Sheets("sheet1").Range("A1").Value
Set doccol = db.Search( strQuery, Nothing, 0 )
After calling OpenDatabase successfully, you can use
set uiDb = uiWS.CurrentDatabase
That will get a NotesUIDatabase object, and then you can use
set db= uiDb.Database
That will get you the NotesDatabase object that you need in order to call the FTSearch method.

How do I search an online document for specific string and it's value?

Example, Online document: [removed link as no longer needed]
Which outputs:
Value1=1
Value2=5
The rest of this document would have random text to ignore.
I would like to search for Value1 and Value2, then output it's value [I need this to be expandable if I decide to add new information in the future]
[the output may be longer than one character, and might be text rather than a number]
Dim Value1Result as Integer = [value from online file] '1 in this case
Dim Value2Result as Integer = [value from online file] '5 in this case
Edit: Added logic to strip the version number. Very basic but as long as the format doesn't change it should work. You'll need to handle parsing to int, double, etc if you ever use "1.2" or whatever for a version.
If I understand your question correctly, you just need to download the file, store it in a local variable, and then do something with it. Comment if this is not the case and I will adjust.
I would do this by creating a WebClient, downloading the data, converting it to a string, and then operating on it. I did not add any headers - dropbox doesn't require it, but something to keep in mind for production... Small example below:
Dim bResult() As Byte
Dim sUrl As String = "https://dl.dropboxusercontent.com/s/bus2q71wsn9txuz/Test.txt?dl=0"
Using client As New WebClient
bResult = client.DownloadData(sUrl)
End Using
Dim retData As String = Encoding.UTF8.GetString(bResult)
Dim retList As List(Of String) = retData.Split(Environment.NewLine).ToList()
Dim sMin = retList(0).Split("=").Last()
Dim sNew = retList(1).Split("=").Last()

Option Explicit - Not sure how to dim this

I have an existing macro that I use to format columns. I've been using this without problems. Now, I'm looking to learn how to use Option Explicit and I am running into a problem with defining my variable.
What should I be dim'ing Level as? I tried Dim Level As String but that didn't work. I'm trying to get a better understanding so any feedback would be appreciated.
Option Explicit
Sub adviseformat()
Dim Form As Worksheet
Set Form = Sheets("Formatting")
With Form
Level = WorksheetFunction.Match("Level", .Rows("1:1"), 0)
.Columns(Level).Delete
.Columns("D:E").Delete
.Range("U:U").Value = Range("E:E").Value
.Columns("E").EntireColumn.Delete
.Columns("F:I").Delete
.Columns("I").Delete
.Columns("L").Delete
.Columns("M").Delete
Form.Range("A:B").EntireColumn.Insert
Form.Range("A1").Value = "Owner"
Form.Range("B1").Value = "Comment"
Form.Range("A1").Interior.Color = 65535
Form.Range("B1").Interior.Color = 65535
Form.Range("O1").Interior.Color = 65535
End With
End Sub
As you type the WorksheetFunction.Match part, the VBA editor should pop up and give you a clue to the return type. It should say something like:
Match(Arg1, Arg2, [Arg3]) as Double
The "As Double" part tells you the return type of the Match function. This is the type you should use to declare your Level variable.
Looking on MSDN, I found this :
MATCH returns the position of the matched value within lookup_array, not the value itself.
For example, MATCH("b",{"a","b","c"},0) returns 2, the relative position of "b" within the array {"a","b","c"}.
So my guess is that you should use Dim Level As Variant

lotus notes domino designer text field contains special characters?

My Lotus notes field allows special characters to be stored in the text box for example Franco Martínez, José Ramó this name has special character í, é, ó How do i not allow user to paste such character ?
Also, when i create a view can I convert this to a simple string using a method so that it does not contain special characters ?
Over the input validation of an field you can use a #Fomular to post an failure when the User use one of these characters. Use something like this
#If( #Contains(Field_1;"í");#Failure("no í");#Contains(Field_1;"é");#Failure("no é");#Contains(Field_1;"ó");#Failure("no ó");#Success)
If you like to change the characters of exsitings doc, you can use an LS Agent which change characters of the marked documents in a view.
Dim session As New NotesSession
Dim doccol As NotesDocumentCollection
Dim doc As NotesDocument
Dim eval As variant
Set doccol =session.Currentdatabase.Unprocesseddocuments
If doccol.Count =0 Then
MsgBox "please mark docs" ,0, "please mark docs"
Exit sub
End If
Set doc = doccol.Getfirstdocument()
Do Until doc Is Nothing
eval = Evaluate({#Replacesubstring(Field_1;"í":"ó":"é";"i":"o":"e")}, doc)
Call doc.Replaceitemvalue("Field_1", eval)
Call doc.Save(true,false, true)
Set doc = doccol.Getnextdocument(doc)
Loop
To change the characters in a view column just take
#Replacesubstring(columnvalue;"í":"ó":"é";"i":"o":"e")

How to change the alterrowcolor and Header Style using Lotus script?

My requirement is, I am having a hundreds of views. I want to make them as standard colors and UI. Simple I am using for changing the font color for column header and column values by NotesViewColumn class. But I do not know that which class is having the property for action bar and View alternate color and Heaer style and etc.,
In javascript is also welcome., But it should change its property as a designer level.
Thanks in advance
You have 3 options:
The easiest one: Go and buy ezView from Ytria. Should take you less than an hour to sort your views out
Create one view that looks the way you want your views to look and then go through all the views in a script, rename them, create a new view based on your view template and copy the view columns from the old views and adjust the view selection formulas (all in LotusScript)
Export your views in DXL and run some XSLT or search/replace to adjust the properties
Hope that helps
I just ran this agent, to change all the views in my (small) test database to having alternate row colours, and it worked.
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim exporter As NotesDXLExporter
Dim importer As NotesDXLImporter
Dim out As String
Dim infile As string
Dim pointer As long
Dim filenum As Integer
Dim altrow As integer
Dim unid As String
Dim doc As notesdocument
Set db = session.currentdatabase
Set exporter = session.Createdxlexporter
Set importer = session.Createdxlimporter
Dim count As Integer
count = 1
ForAll v In db.views
unid = v.UniversalID
Set doc = db.getdocumentbyunid(unid)
out = exporter.Export(doc)
altrow = instr(out, "altrowcolor")
If altrow > 0 Then
pointer = InStr(altrow, out, "=")
out = Left(out,pointer) & "'#f7f7f7'" & Mid(out, pointer+10)
else
pointer = InStr(out, "bgcolor=")
pointer = InStr(pointer, out, " ")
out = Left(out,pointer) & "altrowcolor='#f7f7f7' " & Mid(out, pointer+1)
End if
Call importer.setinput(out)
Call importer.setoutput(db)
importer.Designimportoption = 5
importer.Documentimportoption = 5
Call importer.Process()
out = ""
infile = ""
count = count + 1
End ForAll
Print count & " views processed"
End Sub
If your view designs are much bigger, you might want to use a NotesStream instead of String for "out". In that case, from the Help Files, I believe that the stream has to be closed and re-opened before you can use it for import.
For further research, I suggest writing "out" to a file, and examining the xml to find other "hidden" parameters.
Have fun, Phil
I can also recommend ezView. Makes it a piece of cake to modify views. I also use actionBarEZ to modify action bars across applications.
I blogged about a few different development tools I use in Domino Designer, you can find the entry here: http://www.bleedyellow.com/blogs/texasswede/entry/mydevelopmenttools

Resources