Lotus string illegal array bound - lotus-notes

If use number can work
Dim tablelabels(9) As String
But I need use variable [count] ,[count] is number,because there is no fixed value
Dim tablelabels(count) As String <----
n=0
While Not (doc Is Nothing)
tablelabels(n) = doc.GetItemValue ("Reply")(0)
n=n+1
Set doc = view.GetNextDocument (doc)
Wend
Thanks a lot for help

Use this:
Dim tablelabels() As String
ReDim tablelabels(count)

Related

How to get an part of string which matches an List() result?

So, here's the code. What am I trying to do is to get the str variable, check if it contains an entry of strList and if it does return that entry (so I can use it in IF statements etc etc). Oh, and yes, I need to use variable names in the List(). So how cloud I get that?
Dim strList As New List(Of String)
Dim str As String = "SomeFancyStringThere"
strList.Add(somefancystringname, "Fancy")
What have I tried:
Dim strList As New List(Of String)
Dim str As String = "SomeFancyStringThere"
strList.Add(somefancystringname, "Fancy")
If str.Contains(strList.Any) Then
Dim strFound As String = strList. 'and I am completely stuck there.
End If
Thanks in advance,
DDev.
What i understand of your want is that u are trying to filter a list of string.Or in simple words,you are trying to find out if your List(Of String contains a specific string, right ?? Well, here's the most easiest solution for that :
Private MylistOfString As New List(Of String)
Private Function CheckIfExists(byval myStr as string) As String
For each item As String in MylistOfString
If item = myStr Then
Return myStr
End if
Next
Return ""
End Function
Hope this helps :)

String with 2 apostrophes - remove one of the apostrophes from the string

So I have a a little issue....
I have a string that looks like this...
O''Neil
is there a way for me to remove one of the apostrophes? Basically I'd like to convert it back to
O'Neil
Hopefully this can help you:
Note - I left the Error handling to you.
Imports System
Public Module Module1
Public Sub Main()
Dim data As String = "O''Neil"
Dim in1 As Integer = data.IndexOf("'"C) ' get the index of first quote
Dim in2 As Integer = data.IndexOf("'"C, in1 + 1) ' get the index of second
Dim result As String = data.Remove(in2, 1) ' remove the second quote
Console.WriteLine(result)
End Sub
End Module

Lotus notes : how to sort a multi valued field in descending order

I am a beginner in Lotus notes. I have a keyword look-up form and an edit history field. Every change is recorded in the edit history field. The edit history is displayed as shown below:
DATE: 02/10/2016
USER: (name)
FROM: keyword::keyword values
TO: keyword::keyword values
DATE: 05/29/2016
USER: (name)
FROM: keyword::keyword values
TO: keyword::keyword values
The append in the edit history is below the previous edit so it is displayed in ascending order. How can I sort the edit history in descending order? Or is it possible to insert new edit history above the previous edit history to make it in descending order? If yes, how can I do this? Thank you in advance for all your help. :)
In my EditHistory multivalued field, I have this code:
#If(#IsDocBeingLoaded & #IsNewDoc; #Return(""); #True);
#If(!#IsDocBeingSaved; #Return(#Sort(EditHistory;[Descending]));
#Trim(#Subset(#Sort(EditHistory;[Descending]) ; -100)))
In declarations:
Dim FieldValues() As String
In my form I have these:
Sub EditHistorylist
Dim session As New NotesSession
Dim workspace As New NotesUIWorkspace
Dim source As NotesUIDocument
Dim fieldnum As Integer
Dim entry As String
Dim histo As Variant
Set source = workspace.CurrentDocument
For fieldnum = 0 To Ubound(FieldValues)
If FieldValues(fieldnum,1) <>source.fieldgettext(FieldValues(fieldnum,0)) Then
entry = Chr(10) + "DATE:" + Date$+Chr(10)+ "USER:" + session.CommonUserName +_
Chr(10)+ "FROM:" + FieldValues(fieldnum,0) + "::" + FieldValues(fieldnum,1)+_
Chr(10)+ "TO:" + FieldValues(fieldnum,0) + "::" + source.fieldgettext(FieldValues(fieldnum,0)) +_
Chr(10) + Chr(95) + Chr(95) + Chr(95)
Call source.FieldAppendText("EditHistory",Chr(10)+entry)
End If
Next
End Sub
Document events:
Sub Querysave(Source As Notesuidocument, Continue As Variant)
If Not Source.IsNewDoc Then
Call EditHistorylist
End If
End Sub
Sub Postmodechange(Source As Notesuidocument)
'build array of current values
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim form As NotesForm
Dim fieldnum As Integer
Dim counter As Integer
Set db = session.CurrentDatabase
Set doc = Source.Document
Set form = db.GetForm(doc.Form(0))
fieldnum = Ubound(form.fields)
Redim FieldValues(fieldnum,1)
counter = 0
Forall field In form.fields
FieldValues(counter,0) = field
FieldValues(counter,1) = source.fieldgettext(field)
counter = counter + 1
End Forall
End Sub
To begin with, each line in the history is a string, even if you sort those lines, the result would be sorted in lexicographical order, meaning that 02/10/2016 will still be before 05/29/2016, which would be before 05/29/2015.
Sorting this list after it was completed does not seems the way to go.
is it possible to insert new edit history above the previous edit history to make it in descending order?
Yes of course it is
how can I do this?
It all depend on how the new line is added to the field. With #Formula it would be fairly simple, maybe just
history := newLine : history
In LotusScript, you could grab the existing lines with history = document.getItemValue("history"), which would yield an array. You could then use some array-fu to prepend the new line, something along the lines of
redim preserve history(ubound(history)+1)
for i = ubound(history) down to 1
history(i) = history(i-1)
next
history(0) = newLine
call document.replaceItemValue("history", history)
Now, handling dynamic arrays in LotusScript can be tricky, so arm yourself with patience, and check the help built in Domino Designer.
Try this:
Dim newRow(0) As String
newRow(0) = "new history line"
If document.History(0) = "" Then
document.History=newRow
Else
document.History = Arrayappend(newRow, document.history)
End If

How to speed up the comparision of 2 collections in VBA?

I have written a macro that gets a collection of collection and than takes two of the collections and gives me the similarity.
Now if I compare the two collections with a simple for loop it will take hours to compare all 854 collection that are contained in pCol.
Here is my code:
Function CompareCollections(ByVal pCol As Collection) As Collection
Dim outer As Long
Dim inner As Long
'collections that will be compared to each other
Dim inCol As Collection
Dim outCol As Collection
'collection used for return values
Dim retCol As Collection
'result of single comparison
Dim res As CompResult
'comparison variables
Dim iIdx As Long
Dim oIdx As Long
Dim same As Long
Set retCol = New Collection
For outer = 1 To pCol.Count - 1
Set outCol = pCol(outer)
For inner = outer + 1 To pCol.Count
Set inCol = pCol(inner)
Set res = New CompResult
res.LeftTable = outCol(1) 'index 1 contains a header
res.RightTable = inCol(1)
'compare the two collections <== PART I WANT TO SPEED UP
same = 0
For oIdx = 2 To outCol.Count 'starting with 2 to ignore the header
For iIdx = 2 To inCol.Count
If inCol(iIdx) = outCol(oIdx) Then same = same + 1
Next iIdx
DoEvents
Next oIdx
res.Result1 = same / (outCol.Count - 1)
res.Result2 = same / (inCol.Count - 1)
retCol.Add res
Set res = Nothing
Set inCol = Nothing
DoEvents
Next inner
Set outCol = Nothing
DoEvents
Next outer
Set CompareCollections = retCol
End Function
I really hope you guys can help me.
EDIT:
The CompResult class is a simple structure, because I could not add a custom type to the collection:
Private mLeftTable As String
Private mRightTable As String
Private mResult1 As Double
Private mResult2 As Double
Public Property Get LeftTable() As String
LeftTable = mLeftTable
End Property
Public Property Let LeftTable(value As String)
mLeftTable = value
End Property
Public Property Get RightTable() As String
RightTable = mRightTable
End Property
Public Property Let RightTable(value As String)
mRightTable = value
End Property
Public Property Get Result1() As Double
Result = mResult1
End Property
Public Property Let Result1(value As Double)
mResult1 = value
End Property
Public Property Get Result2() As Double
Result = mResult2
End Property
Public Property Let Result2(value As Double)
mResult2 = value
End Property
A first tip: try to precalculate outCol.Count, inCol.Count and pCol.Count in order to avoid unnecessary calculations.
Second tip: if in your object CompResult the res.Result1 and res.Result2 are integers, use "\" instead of "/".
Third tip: try to use integers instead of long values wherever you can.
Fourth tip: try to replace for loops by a "for each" loops when looping for every column. It seems a little faster.
A last tip might be transform collections (ranges) in arrays and iterate through them, as it seems faster than iterate through ranges.

Can I Evaluate An Excel VB Constant That Is In String Format?

Is it possible to Evaluate a String which contains a valid Excel VB Constant's Name
to return that Constant's Value?
eg
Dim ConstantName as String
Dim ConstantValue as Long
ConstantName="xlValues"
ConstantValue= UnknownFunction(ConstantName)
'would set ConstantValue=-4163
Fun!
Option Explicit
Function getConstantValue(constStr As String) As Variant
Dim oMod As VBIDE.CodeModule
Dim i As Long, _
num As Long
Set oMod = ThisWorkbook.VBProject.VBComponents("Module1").CodeModule
For i = 1 To oMod.CountOfLines
If oMod.Lines(i, 1) = "Function tempGetConstValue() As Variant" Then
num = i + 1
Exit For
End If
Next i
oMod.InsertLines num, "tempGetConstValue = " & constStr
getConstantValue = Application.Run("tempGetConstValue")
oMod.DeleteLines num
End Function
Function tempGetConstValue() As Variant
End Function
All code must be in a module called Module1. That can be changed pretty simply by changing the text "Module1" in the routine.
You'll need to add a reference to Microsoft Visual Basic for Applications Extensibility x.x
There are a number of ways this could fail. Let me know if you have any problems with it :)
Instead of using constants, you could use a dictionary
Dim dict As Object
Sub InitialiseDict()
Set dict = CreateObject(Scripting.Dictionary)
dict("xlValues") = -4163
dict("const1") = value1
...
dict("constN") = valueN
End Sub
ConstValue = dict("xlValues")
Is using the string value necessary?
Dim anyConstant as Long
anyConstant = xlValues
msgbox anyConstant
Set anyConstant to any xl constant you please, they are all enumerated Long values.
The first solution offered is indeed much more fun however.

Resources