Extracting data from external database

Hi,

I’m working on an agent that will pull data from fields in a form in one database to fields in a for in another database.

I grabbed some example code from help and am trying to modify it to suit my needs.

See code below:

Sub Initialize

Dim s As New NotesSession

Dim db As NotesDatabase

Dim respDoc As NotesDocument

Dim doc As NotesDocument

Dim view As NotesView

Dim message As String



Set db = s.GetDatabase("nDPCTest00", "parlimentstagingstaging")

Set view = db.GetView( "Questions" )

Set doc = view.GetFirstDocument	



While Not(doc Is Nothing)

’ Forall subject In Uidoc.FieldGetText(“FinalQNo”)

	message = doc.FieldGetText("FinalQNo")

	Messagebox message

’ End Forall

	Set doc = view.GetNextDocument(doc)

Wend

End Sub

Basically I’m just trying to display the field FinalQNo in a message box for each document in the database, however it doesn’t work (I get ‘Type Mismatch’) unless I have the forall statement in there. Teh field isn’t an array, it just holds a single value.

Thanks in advance.

Subject: Extracting data from external database

Give this while statement a try:

While Not(doc Is Nothing)

message = doc.FinalQNo(0)

Messagebox message

Set doc = view.GetNextDocument(doc)

Wend

Subject: Extracting data from external database

And always include Option Declare in the Options section, when coding in LotusScript. You can choose to automatically add that through the progrmmer’s pane’s properties.

Subject: RE: Extracting data from external database

Hi, thanks for that tip - what exactly will adding Option Declare do for me?

Subject: RE: Extracting data from external database

It will force you to explicitly declare each an every variable before you can use it.

If you don’t (and Option Declare is not enabled), the LS compiler will tread each new variable name as a Variant (unless it has a postfix indicating the datatype). This way your code will often seem to save and compile just fine, while in reality it still is full of errors, that could be found at compile time with stricter type checking.

A variant can hold plain everything: Notes product objects, objects form user defined classes, user defined types simple types, lists or arrays of all the above, even arrays of Variants. this might look convenient at first, but since a variant variable could contain almost everything, the compiler cannot judge if what you put in it (or forgot to put in it) was on purpose or not.