ListBox addItem not working? - full code

Note:
The addItem instruction seems to do nothing?
The ListBox read-only option is set to No.
I can get values from the ListBox.
The “\” is a temporary Return key substitute.

Sub Run_Cmd
    BasicLibraries.LoadLibrary("Tools")
    oDialog1 = LoadDialog("Standard", "cmd")
    oDialog1Model = oDialog1.Model
    rslt = oDialog1.GetControl("ListBox1")
    cmd  = oDialog1.GetControl("TextField1").Text
    
    if instr(cmd,"\") > 0 then
		cmd = "/home/june/lgr.sh" & " '" & left(cmd,len(cmd) - 1) & "'"
		msgbox(cmd)
		shell("/usr/bin/bash",0,cmd, true)

        open "/home/june/lst" for input as 1	
	    While Not eof(1)
	        Input #1, sLine
    		iCount = rslt.ItemCount
     		msgbox(iCount)
    		rslt.addItem(sLine,iCount)
          Wend
	    Close #1
    end  if
end sub

How do you know there are no added elements in your rslt? I don’t see a single line oDialog1.execute() or oDialog1.setVisible(True) in the code. Or do you expect to see all these elements in design mode? This is a futile wait.

Thks Vladyslav,

I had already tried execute…

what I’m trying to do is to dynamically add items to a Listbox based on
User input into a Textbox, so I suppose I want an update method,
execute and visible both present a new instance of the Dialog.

The purpose is to simulate and log a CLI session.

Cheers, Jim

PS.

This the code to originally load/display the dialog.

Sub Dialog1Show
BasicLibraries.LoadLibrary("Tools")
oDialog1 = LoadDialog("Standard", "cmd")
oDialog1.Execute()
End Sub

Try dividing the script into two procedures. The first is the actual launch of the dialog window - the same as you showed in the last comment. And the second is processing the event of the TextField1 field (for example, When losing focus):
image

Sub onTextField_lostFocus(oEvent As Variant)
	cmd  = oEvent.Source.Text
    rslt = oDialog1.GetControl("ListBox1")
    If instr(cmd,"\") > 0 Then 
' ... all your operations with AddItem...`
End Sub

Don’t forget to add a description of the public variable at the beginning of the module, before the first procedure
Dim oDialog1 As Variant

I’m already doing that(on key pressed), my problem is that the ListBox
isn’t showing the update.

PS.

I appreciate that I’m probably using ListBox in a way it’s not designed to be used, maybe it can’t be done.

WHY NOT?!! Please see this -
tstDlgAddItem.ods (13.0 KB)

Thks John, that works, it’s almost identical to mine, I’m currently tracking down the differences.

I found the problem, for some unknown reason(Bodhi Linux), the output of the CLI command
wasn’t redirected to my home directory(the default), but to my Downloads directory,
I have now explicitly coded the path.

Thks all.