Question

I'm using LotusScript to clean and export values from a form to a csv file. In the form there are multiple date fields with names like enddate_1, enddate_2, enddate_3, etc. These date fields are Data Type: Text when empty, but Data Type: Time/Date when filled.

To get the values as string in the csv without errors, I did the following (working):

If Isdate(doc.enddate_1) Then 
    enddate_1 = Format(doc.enddate_1,"dd-mm-yyyy") 
Else
    enddate_1 = doc.enddate_1(0)
End If

But to do such a code block for each date field didnt feel right.

Tried the following, but that isnt working.

For i% = 1 To 9
    If Isdate(doc.enddate_i%) Then 
        enddate_i% = Format(doc.enddate_i%,"dd-mm-yyyy") 
    Else
        enddate_i% = doc.enddate_i%(0)
    End If
Next

Any suggestions how to iterate numbered fields with a for loop or otherwise?

Was it helpful?

Solution 2

Combined solution of Dmytro, clarification of Richard Schwartz with my block of code to a working solution. Tried it as an edit on solution of Dmytro, but was rejected.

My problem was not only to iterate the numbered fields, but also store the values in an iterative way to easily retrieve them later. This I found out today trying to implement the solution of Dmytro combined with the clarification of Richard Schwartz. Used a List to solve it completely.

The working solution for me now is:

Dim enddate$ List
For i% = 1 To 9
    itemName$ = "enddate_" + CStr(i%)
    If Isdate(doc.GetItemValue(itemName$)) Then 
        enddate$(i%) = Format(doc.GetItemValue(itemName$),"dd-mm-yyyy") 
    Else
        enddate$(i%) = doc.GetItemValue(itemName$)(0)
    End If
Next

OTHER TIPS

To iterate numbered fields with a for loop or otherwise?

valueArray = notesDocument.GetItemValue( itemName$ )

however do you know that there is a possibility to export documents in CSV format using Notes Menu?

File\Exort

Also there is a formula:

@Command([FileExport]; "Comma Separated Value"; "c:\document.csv")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top