Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Get around Hard Coding the Host Session ID in vbScript or VBA code

Status
Not open for further replies.

AMRICE

IS-IT--Management
Nov 6, 2019
4
US
I have novice knowledge working with PCOMM on the AS400. I have written 15 VBA scripts in Excel which calls AS400 Macros. To get the programs to work the AS400 has to be at the Login Screen and the Active Host Session MUST be set at "D". It is the Host Session that is giving me the blues. As there are many using the same PC, I never know which Host Session the AS400 will active at any point in time... sometimes "A", sometimes "B", or there may be multiple open sessions on the same screen.

The top few lines of my VBA script is below. Is there a way I can define the script to avoid using the Host Session ID ("D" in this case) so my script will work with any ID ("A" or "B", etc)

Sub APVCHDET()
Set autECLSession = CreateObject("PCOMM.autECLSession")
autECLSession.SetConnectionByName ("D")
> enter image description here
SessionIDJPG_ylcnfx.jpg
 
Thanks to a brilliant AS400 developer I was able to resolve my problem with how to get around Hard Coding the Host Session ID in vbScript or VBA code... The PCCOMM code below solved my problem:

'This section is test to avoid identifying the SetConnectionName ("D")
Dim SessObj As Object
Dim autECLConnList As Object

Set autECLConnList = CreateObject("PCOMM.autECLConnList")
Set SessObj = CreateObject("PCOMM.autECLSession")

' Initialize the session
autECLConnList.Refresh
SessObj.SetConnectionByHandle (autECLConnList(1).Handle)
'SessObj.StopCommunication()
'This Ends section to test to avoid identifying the SetConnectionName ("D")

Hopefully others can use this solution, if necessaty

Al
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top