Page 1 of 1 1
Topic Options
#204976 - 2012-04-26 08:05 AM trouble converting VB script using COM to kix
Sam_B Offline
Getting the hang of it

Registered: 2005-10-25
Posts: 68
Loc: Bern, Switzerland
Hi Kix experts,

I'm currently developing a script that automates the user setup for a Lotus Notes Client. Works quite well for about 80 % of the work to be done, but now I'm stuck

I was quite able to convert below VB code to kix but I'm stuck now at line

strName = domDocument.GetItemValue("FullName")(0)

I assume that GetItemValue method returns a two dimensional array?

I tried $strName = $domDocument.GetItemVale["FullName",0] but this doesn't work, a empty string is returned...

I know that Notes is not that popular and using KIX together with Notes either, but it's worth a try to post my problem here, you never know...

Greetings from Switzerland!

Samuel



 Code:
Dim domSession As New Domino.NotesSession   
Dim domDatabase As New Domino.NotesDatabase
Dim domDocument As NotesDocument
Dim domViewEntry As NotesViewEntry
Dim domView As NotesView
Dim domViewNav As NotesViewNavigator
Dim strName As String

domSession.Initialize
Set domDatabase = domSession.GetDatabase("", _
"names.nsf")  
Set domView = domDatabase.GetView("Contacts")
' This view contains the list of names
Set domViewNav = domView.CreateViewNav
Set domViewEntry = domViewNav.GetFirstDocument()
Set domDocument = domViewEntry.Document

strName = domDocument.GetItemValue("FullName")(0)
MsgBox strName

Set domViewEntry = Nothing
Set domViewNav = Nothing
Set domView = Nothing
Set domDocument = Nothing
Set domDatabase = Nothing
Set domSession = Nothing


Edited by Mart (2012-04-26 09:48 AM)
Edit Reason: Please use code tags when posting code.

Top
#204978 - 2012-04-26 01:58 PM Re: trouble converting VB script using COM to kix [Re: Sam_B]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well.
there is no setting in kix. and variables start always with a $-sign.

you could try getitemvalue("FullName")[0]

if it is an array, that should work.

can you modify your script and post it as kix script and we can get going from there way easier.
_________________________
!

download KiXnet

Top
#204980 - 2012-04-26 02:52 PM Re: trouble converting VB script using COM to kix [Re: Lonkero]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Try this:
 Code:
$strName = $domDocument.GetItemValue("Fullname")
? $strName[0]

Top
#204982 - 2012-04-26 03:46 PM Re: trouble converting VB script using COM to kix [Re: Arend_]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
which is the same as mine.

anyways, it might not be an array and it would be nice to hear back from Samuel and would be awesome if we get a snippet of kixtart code instead of vbs.
_________________________
!

download KiXnet

Top
#204990 - 2012-04-26 08:14 PM Re: trouble converting VB script using COM to kix [Re: Lonkero]
Sam_B Offline
Getting the hang of it

Registered: 2005-10-25
Posts: 68
Loc: Bern, Switzerland
Sorry guys not to include the scriptlet at the beginning, I had it not available this morning. See below in bold where the script crashes.
 Code:
; ------------------------------------------------------------------------------------
; Change Mail File Location from "on Server" to "on local" for all location documents
; ------------------------------------------------------------------------------------
Function SetMailFileLocationToLocal($oNotesSession)
  Dim $oBook            ; Adress book object
  Dim $ret              ; Return value of function call
  Dim $LocationView     ; Location view
  Dim $LocationDocument ; Location document
  Dim $valueArray
  ;
  $SetMailFileLocationToLocal = 0
  ; -------------------------------------------------------------------------------------
  ; For The Current User in The Current Session, Get All The NABs
  ; -------------------------------------------------------------------------------------
  For Each $oBook in $oNotesSession.addressbooks
    ; -----------------------------------------------------------------------------------
    ; Check If The Current NAB is Private or Public
    ; If The NAB Is Private, Than It Should Be Your Personal NAB
    ; -----------------------------------------------------------------------------
    ? "Name of adressbook: " $oBook.filename
    If $oBook.isprivateaddressbook 
      ; ---------------------------------------------------------------------------------
      ; Verify if The NAB is Open, If Not, Open it
      ; ---------------------------------------------------------------------------------
      If Not ($oBook.isopen)
        $ret = $oBook.open("", $oBook.filename) ;Now Get All The Docs in The Location View
      EndIf
      $LocationView = $obook.getview("Locations")
      $LocationDocument = $LocationView.getfirstdocument 
      While @ERROR = 0
        $valueArray = $LocationDocument.GetItemValue("MailType")
        ? "Mailtype: " $ValueArray[0]
here I get

[b]ERROR : Error in expression: this type of array not supported in expressions.!
Script: I:\Scripting\SDSDeploy\CH\CH_SetupClient\Work\test3.KIX
Line  : 62[/b]

        $LocationDocument = $LocationView.getnextdocument($LocationDocument)
      Loop
    EndIf
  Next
EndFunction
; ----------------------------------------------------------------------------------------
; Start Notes Session
; ----------------------------------------------------------------------------------------
Function StartNotesSession()
  ;Die Session starten
  $StartNotesSession = CreateObject("Notes.NotesSession")
  If @ERROR <> 0
    $ret = MessageBox("Error starting Notes, unable to continue", "Problem with Notes configuration", 48)
    Exit 1
  EndIf
EndFunction
; =======================================================================================
; M A I N
; =======================================================================================
$PreviousState = SetOption("Explicit", "on")
Break on
Dim $Ret
Dim $MailServer
Dim $MailFileName
Dim $CSCDircatFileName
Dim $oNotesSession
Global $GloIniFile               ; INI file that controlls the parameters
;
$GloIniFile         = @SCRIPTDIR + "\NotesSetup.ini"
$Mailserver         = "<Name of Mailserver goes here>"
$MailFileName       = "<Path to mailfile goes here>"
; --------------------------------------------------------------------------------------
; read name of Notes directory to replicate
; ------------------------------------------------------------------------------------
$CSCDirCatFileName = ReadProfileString($GloIniFile, "Setup", "NotesDirectory")
If @ERROR <> 0
  $ret = MessageBox("Error reading value for NotesDirectory from " + $GloIniFile + ", unable to continue", "Problem with Notes configuration", 48)
  Exit
EndIf
; --------------------------------------------------------------------------------------
; Try to start Lotus Notes
; --------------------------------------------------------------------------
$oNotesSession = StartNotesSession()
$ret = SetMailFileLocationToLocal($oNotesSession)
;=========================================================================================



I've also found the documentation for GetItemValue, the method returns an array with (I suppose) one element of string, but I'm unable to grab it...

Thanks again for your help and support!!!


GetItemValue method
Example

Given the name of an item, returns the value of that item in a document.

Defined in

NotesDocument

Syntax

valueArray = notesDocument.GetItemValue( itemName$ )

Parameters

itemName$


String. The name of an item.


Return value

value


The value or values contained in the specified name. The data type of the value depends on the data type of the item.
Notes item type Value return type
Rich text Array of strings. The text in the item, rendered into plain text
Text or text list (includes Names, Authors, and Readers item types) Array of strings
Number or number list Array of doubles
Date-time or range of date-time values Array of variants of type Date
When GetItemValue returns an array, each element in the array corresponds to a value in the item. If the item contains a single value, the array has just one element.








Edited by Mart (2012-04-26 09:59 PM)
Edit Reason: Please use code tags when posting code.

Top
#204993 - 2012-04-26 11:44 PM Re: trouble converting VB script using COM to kix [Re: Sam_B]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ok.
add this part in there and let us know what it says:
vartypename($valuearray)

it might actually collection, so accessing it might require you to do something like:
$valuearray.items(0)

anyways, in some cases com-objects don't actually give the array they produce for kixtart to use. we never found out the reason (iirc) but some microsoft produced objects are like that.
_________________________
!

download KiXnet

Top
#204996 - 2012-04-27 05:01 PM Re: trouble converting VB script using COM to kix [Re: Lonkero]
Sam_B Offline
Getting the hang of it

Registered: 2005-10-25
Posts: 68
Loc: Bern, Switzerland
Result of Vartype($Valuearry) is.... String[] Will do further tests on monday and let you know
Top
#204997 - 2012-04-27 05:11 PM Re: trouble converting VB script using COM to kix [Re: Sam_B]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
I think I ran into something similar just recently, and got around it by using .value on the end.

$valueArray = $LocationDocument.GetItemValue("MailType").value

I guess this is worth a shot.

Top
#204998 - 2012-04-27 05:31 PM Re: trouble converting VB script using COM to kix [Re: Allen]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yeap, that's probably the only possible workable solution.

not sure why, but kixtart can't handle primitive type arrays coming from com-objects.
they need to be type variant. or something similar. and I just remembered where I've met the exact issue before.
_________________________
!

download KiXnet

Top
#204999 - 2012-04-28 08:28 AM Re: trouble converting VB script using COM to kix [Re: Lonkero]
Sam_B Offline
Getting the hang of it

Registered: 2005-10-25
Posts: 68
Loc: Bern, Switzerland
Thanks to you all, I've found the solution for my problem in the meantime. Allens hint with the .value pushed me in the right direction. I found a a post of a user with the same problem:

http://www-10.lotus.com/ldd/nd6forum.nsf/0/d2aaeebd3c340f7f852572730069702c?OpenDocument

and the solution:

"Hi there,

i had the same problem and i was very near to kill somebody...
But, in the last second, i found the solution:

The GetItemValue returns an array which seems not to be compatible with vbscript! Try this instead:

yourdoc.GetFirstItem("itemname").Text

sure, multivalue fields are not very funny, because the values are joined with ; to one string, but you will get some values back...

For me, its all i want :)"

GetFirstItem("itemname").Text works perfectly for me as well, thanks a lot to all of you taking care of my problem, this site is THE BEST source for posting such kind of problems, no doubt about it!

Top
#205001 - 2012-04-28 04:18 PM Re: trouble converting VB script using COM to kix [Re: Sam_B]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
oh, vbscript couldn't get to the array either?

for future postings, please try to use code-tags so Mart doesn't need to go editing your posts.
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 456 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.069 seconds in which 0.033 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org