I am trying to return an ArrayList from a function in VBScript. The code goes through mails and extracts the Subject and Sender from them and stores them into An ArrayList. Then I Set the ArrayList to the name of the function to return it. But no returns are being output as arguments.
I execute the VBScript through CMD and only shows
C:\Users\XXXXXX\Documents>cscript DetailSaver.vbs Microsoft (R) Windows Script Host Version 5.812 Copyright (C) Microsoft Corporation. All rights reserved.
Function getDetails()
Set outlook = createobject("outlook.application")
Set session = outlook.getnamespace("mapi")
session.logon
Set inbox = session.getdefaultfolder(6).Folders("Clasification")
Set newFolder = inbox.Folders("Devs")
Set detailList = CreateObject("System.Collections.ArrayList")
Dim emailSubject
Dim emailSender
Dim emailObject
For Each m In newFolder.items
If m.unread Then
emailSubject = m.Subject
emailSender = m.Sender.GetExchangeUser().PrimarySmtpAddress
emailObject = emailSender & "|.|" & emailSubject
detailList.Add emailObject
m.Unread = False
End If
Next
session.logoff
Set outlook = Nothing
Set CaseTitle = Nothing
Set session = Nothing
'Set detailList = Nothing
Set getDetails = detailList
End Function
Call getDetails()
WScript.Quit
getDetails()function, then exits. It doesn't do anything with the returned list. What are you expecting? Also, note that usingSystem.Collections.ArrayListwill only work on systems with .Net 2 or 3.5 on them. It will fail on systems with just .Net 4.x (like Win10).Why not use a type that VBScript understands natively, likeDictionary? - RnoSystem.Collections.ArrayListat all and not VBScript's native Array? - Hel O'Weenwscript.echo join(detailList.ToArray(), vbCrLf)but the Windows Script Host Window appears when executed. I was trying to return value without using echo. & Thanks! For sure will tryDictionary- silver_lynxSystem.Collections.ArrayListwill try with VBScript native Arrays :) - silver_lynxInteger:WScript.Quit someExitCode, wheresomeExitCodeis anInteger. It's been ages since I used it so I may be wrong. PowerShell can do it. Or you could perhaps write the desired output to some file. - Rno