.Bat or .Ps1 Running Process to Listbox

jstevens
GoldLounger
Posts: 2618
Joined: 26 Jan 2010, 16:31
Location: Southern California

.Bat or .Ps1 Running Process to Listbox

Post by jstevens »

Is it possible to populate a Userform Listbox of batch file that are running?

As an example a batch file kicks off 12 different batch files. Each of the 12 will end at different times so the Listbox will be populated with 12 at first and as they end the Listbox will show one less until it is empty.

Your suggestions are appreciated.
Regards,
John

jstevens
GoldLounger
Posts: 2618
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: .Bat or .Ps1 Running Process to Listbox

Post by jstevens »

I have attached a sample workbook containing the Userform and code I have been testing with. I'm having a challenge with 'AddressOf' compiling: error - Invalid use of AddressOf operator.

The majority of the code is Private and associated with the Userform.

Code: Select all

Private Sub UserForm_Initialize()
    Dim TimerProcPtr As LongPtr
    TimerProcPtr = VBAPtrSafe(AddressOf TimerProc)    'AddressOf encounter a compile error:  Invalid use of AddressOf operator.
    SetTimer Me.hwnd, TIMER_ID, TIMER_INTERVAL, TimerProcPtr 'start the timer
End Function
Your suggestions are appreciated.
Test_ListBox_BatchFile_Load.xlsm
You do not have the required permissions to view the files attached to this post.
Regards,
John

User avatar
SpeakEasy
4StarLounger
Posts: 536
Joined: 27 Jun 2021, 10:46

Re: .Bat or .Ps1 Running Process to Listbox

Post by SpeakEasy »

Important to check the documentation:

AddressOf procedurename

The required procedurename specifies the procedure whose address is to be passed. It must represent a procedure in a standard module in the project in which the call is made.

Also - it looks like you have copied and pasted some VB6 code for this, which means when you get past this AddressOf error you will lean that a VBA UserForm does not have an hWnd ...
Last edited by SpeakEasy on 28 Mar 2023, 10:54, edited 1 time in total.

snb
4StarLounger
Posts: 548
Joined: 14 Nov 2012, 16:06

Re: .Bat or .Ps1 Running Process to Listbox

Post by snb »

For what purpose are you using .bat files ?
You can run every .bat file command in VBA using the 'wscript.shell' library.

It looks as if you are overcomplicating things.

User avatar
SpeakEasy
4StarLounger
Posts: 536
Joined: 27 Jun 2021, 10:46

Re: .Bat or .Ps1 Running Process to Listbox

Post by SpeakEasy »

Here's a minor rewrite of your code that should be close to what you want:
Test_ListBox_BatchFile_Load2.xlsm
You do not have the required permissions to view the files attached to this post.