Page 1 of 1
[Solved] I can't add data into ListBox in runtime
Posted: Thu Mar 30, 2017 9:16 pm
by zenira
Hi friends
I want to add data into ListBox from TextBox in a dialog box but I can not
Code: Select all
Sub Main
DialogLibraries.LoadLibrary("Standard")
oDlg = CreateUnoDialog(DialogLibraries.Standard.Dialog1 )
oDlg.execute()
End Sub
Sub AddButton
dim textbox,listbox as object
textbox=oDlg.getControl(TextField1)
listbox=oDlg.getControl(ListBox1)
listbox.additem(textbox.Text, 0) REM this does not work
End Sub
when i add this controls on document they are work but they dont work on dialog box
thanks for your help
Re: I can't add data into ListBox in runtime
Posted: Thu Mar 30, 2017 9:48 pm
by JeJe
textbox.model.text
Re: I can't add data into ListBox in runtime
Posted: Fri Mar 31, 2017 8:00 am
by zenira
it does not work
Re: I can't add data into ListBox in runtime
Posted: Fri Mar 31, 2017 10:40 am
by JeJe
You also need to put quotes round the name of the controls
Code: Select all
dim textbox,listbox as object
textbox=oDlg.getControl("TextField1")
listbox=oDlg.getControl("ListBox1")
listbox.additem(textbox.model.Text, 0)
Re: I can't add data into ListBox in runtime
Posted: Fri Mar 31, 2017 11:53 am
by zenira
I did. But it does not work
Re: I can't add data into ListBox in runtime
Posted: Fri Mar 31, 2017 12:14 pm
by Villeroy
Works for me.
Re: I can't add data into ListBox in runtime
Posted: Fri Mar 31, 2017 12:29 pm
by JeJe
Works for me as well. I've attached a writer document with it.
Re: I can't add data into ListBox in runtime
Posted: Fri Mar 31, 2017 12:57 pm
by Villeroy
A combo box is a combo box becase it combines a text box with a list box.
Re: I can't add data into ListBox in runtime
Posted: Fri Mar 31, 2017 5:42 pm
by RoryOF
Re: I can't add data into ListBox in runtime
Posted: Sat Apr 01, 2017 10:22 am
by zenira
ok. I will try your advices. Thank your help
zenira wrote:Hi friends
I want to add data into ListBox from TextBox in a dialog box but I can not
Code: Select all
Sub Main
DialogLibraries.LoadLibrary("Standard")
oDlg = CreateUnoDialog(DialogLibraries.Standard.Dialog1 )
oDlg.execute()
End Sub
Sub AddButton
dim textbox,listbox as object
textbox=oDlg.getControl(TextField1)
listbox=oDlg.getControl(ListBox1)
listbox.additem(textbox.Text, 0) REM this does not work
End Sub
when i add this controls on document they are work but they dont work on dialog box
thanks for your help
when i click Add button, i get this message "BASIC runtime error.Object variable not set"
The Code can't recognize "oDlg" object when I click Add Button
so i change code like this
Code: Select all
dim oDlg as object
Sub Main
DialogLibraries.LoadLibrary("Standard")
oDlg = CreateUnoDialog(DialogLibraries.Standard.Dialog1 )
oDlg.execute()
End Sub
Sub AddButton
dim textbox,listbox as object
oDlg = CreateUnoDialog(DialogLibraries.Standard.Dialog1 )
textbox=oDlg.getControl("TextField1")
listbox=oDlg.getControl("ListBox1")
listbox.additem(textbox.Text, 0) REM this does not work
End Sub
in this code, I don't get any error but again it does not work
Re: I can't add data into ListBox in runtime
Posted: Sat Apr 01, 2017 10:24 am
by Villeroy
You can not do this without minimal programming skills. You've got to understand the error messages and the code.
Re: I can't add data into ListBox in runtime
Posted: Sat Apr 01, 2017 10:53 am
by JeJe
Did you download the document I posted with it in? Did it work? If yes... and I bet it did... you got the solution...
dim oDlg as object
Sub Main
DialogLibraries.LoadLibrary("Standard")
oDlg = CreateUnoDialog(DialogLibraries.Standard.Dialog1 )
oDlg.execute()
End Sub
Sub AddButton
dim textbox,listbox as object
oDlg = CreateUnoDialog(DialogLibraries.Standard.Dialog1 )
textbox=oDlg.getControl("TextField1")
listbox=oDlg.getControl("ListBox1")
listbox.additem(textbox.Text, 0) REM this does not work
End Sub
You still haven't changed textbox.Text to textbox.Model.Text
It also won't work because in your AddButton function you create a new dialog oDlg which you don't show.
Start putting
at the top of your modules so every variable has to be declared.
Re: I can't add data into ListBox in runtime
Posted: Sat Apr 01, 2017 10:15 pm
by zenira
Thank you guys for your help. I did everything, I spend hours about this issue
. I changed my code. Simply I want to get textbox's text but I get "Object variable not set".
I realize that the code works on calc document but it does not work writer document. Same code.
Code: Select all
Option Explicit
dim oDlg,textbox,listbox as object
Sub Main
DialogLibraries.LoadLibrary("Standard")
oDlg = CreateUnoDialog(DialogLibraries.Standard.Dialog1 )
textbox=oDlg.getControl("TextField1")
listbox=oDlg.getControl("ListBox1")
oDlg.execute()
End Sub
Sub AddButton
Dim stext as string
sText = textbox.Model.getText() Error: Object variable not set
listbox.additem(sText, 0)
End Sub
I think that after oDlg.execute(), all of variables relases in memory and code does not know textbox in AddButton sub despite I define in public
Re: I can't add data into ListBox in runtime
Posted: Sat Apr 01, 2017 10:20 pm
by RoryOF
You need to read up on "Scope and Life Span of Variables" in the OpenOffice BASIC Guide.
Re: I can't add data into ListBox in runtime
Posted: Sat Apr 01, 2017 10:34 pm
by JeJe
Your last code works fine here in OpenOffice if you change it to textbox.Model.Text.
Re: I can't add data into ListBox in runtime
Posted: Sat Apr 01, 2017 10:38 pm
by zenira
RoryOF wrote:You need to read up on "Scope and Life Span of Variables" in the OpenOffice BASIC Guide.
Yes I did.
Re: I can't add data into ListBox in runtime
Posted: Sat Apr 01, 2017 10:41 pm
by zenira
JeJe wrote:Your last code works fine here in OpenOffice if you change it to textbox.Model.Text.
I run it in LibreOffice 4.2.1.1
it works in calc document but does not work in writer document.
Re: I can't add data into ListBox in runtime
Posted: Sat Apr 01, 2017 10:54 pm
by UnklDonald418
Your declaration isn't correct. Replace
Code: Select all
dim oDlg,textbox,listbox as object
with
then
Code: Select all
textbox=oDlg.getControl("TextField1")
listbox=oDlg.getControl("ListBox1")
oDlg.execute()
should return the values you entered
Re: I can't add data into ListBox in runtime
Posted: Sat Apr 01, 2017 10:59 pm
by JeJe
Try changing the names of all your variables and controls and subs.
Try a non-modal dialog
viewtopic.php?f=20&t=5815
Try posting it for people to look at
Re: I can't add data into ListBox in runtime
Posted: Sat Apr 01, 2017 11:07 pm
by zenira
UnklDonald418 wrote:Your declaration isn't correct. Replace
Code: Select all
dim oDlg,textbox,listbox as object
with
then
Code: Select all
oDlg.execute()
textbox=oDlg.getControl("TextField1")
listbox=oDlg.getControl("ListBox1")
should return the values you entered
Here is fresh code
Code: Select all
Option Explicit
Public oDlg,textbox,listbox as object
Sub Main
DialogLibraries.LoadLibrary("Standard")
oDlg = CreateUnoDialog(DialogLibraries.Standard.Dialog1 )
oDlg.execute()
textbox=oDlg.getControl("TextField1")
listbox=oDlg.getControl("ListBox1")
End Sub
Sub AddButton
Dim stext as string
sText = CStr(textbox.Model.getText()) 'Error: Object variable not set
listbox.additem(sText, 0)
End Sub
It does not work
Re: I can't add data into ListBox in runtime
Posted: Sat Apr 01, 2017 11:12 pm
by JeJe
Code: Select all
Sub Main
DialogLibraries.LoadLibrary("Standard")
oDlg = CreateUnoDialog(DialogLibraries.Standard.Dialog1 )
oDlg.execute()
textbox=oDlg.getControl("TextField1")
listbox=oDlg.getControl("ListBox1")
End Sub
Sub AddButton
Dim stext as string
sText = CStr(textbox.Model.getText()) 'Error: Object variable not set
listbox.additem(sText, 0)
End Sub
That isn't going to work because the Sub Main doesn't run any of the code following the oDlg.execute line until the dialog is closed.
Re: I can't add data into ListBox in runtime
Posted: Sat Apr 01, 2017 11:34 pm
by zenira
JeJe wrote:Try changing the names of all your variables and controls and subs.
Try a non-modal dialog
viewtopic.php?f=20&t=5815
Try posting it for people to look at
I changed names of variables ,controls and subs ..here is fresh code
Code: Select all
Option Explicit
Public Window as object
Public EnterBox,SaveBox as object
Sub Main
End Sub
Sub Run
DialogLibraries.LoadLibrary("Standard")
Window = CreateUnoDialog(DialogLibraries.Standard.Dg1
EnterBox=Window.getControl("EnterBoxControl")
SaveBox=Window.getControl("SaveBoxControl")
Window.execute()
End Sub
Sub AddingButton
Dim textarea as string
textarea = EnterBox.Model.getText() 'Error: Object variable not set
SaveBox.additem(textarea, 0)
End Sub
it does not again
ok I will try non-modal dialog . thank you
Re: I can't add data into ListBox in runtime
Posted: Sat Apr 01, 2017 11:53 pm
by zenira
I tried non-modal dialog code
Code: Select all
Option Explicit
Global g_Dlg as object
Global g_Stop as Boolean
Global TextBox,ListBox as object
Sub Main
DialogLibraries.LoadLibrary("Standard")
g_Dlg = CreateUnoDialog(DialogLibraries.Standard.Dg2
TextBox=g_Dlg.getControl("TextField1")
ListBox=g_Dlg.getControl("ListBox1")
g_Dlg.setVisible(True)
do until g_Stop
wait 1000
loop
g_Dlg.setVisible(False)
end sub
Sub someEvent()
g_Stop = True
End Sub
Sub AddingButton
Dim textarea as string
textarea = TextBox.Model.getText() 'Error: Object variable not set
ListBox.additem(textarea, 0)
End Sub
It does not work
Re: I can't add data into ListBox in runtime
Posted: Sun Apr 02, 2017 12:19 am
by JeJe
Why do you keep changing it to TextBox.Model.getText?
Its TextBox.Model.text or TextBox.getText
Re: I can't add data into ListBox in runtime
Posted: Sun Apr 02, 2017 12:41 am
by zenira
JeJe wrote:Why do you keep changing it to TextBox.Model.getText?
Its TextBox.Model.text or TextBox.getText
I tried both. it does not work
Re: I can't add data into ListBox in runtime
Posted: Sun Apr 02, 2017 3:27 pm
by UnklDonald418
This morning using the IDE I set a break point on the offending line in the
AddingButton and a watch on
EnterBox. The watch revealed that
EnterBox was returning a Null value despite being declared Public. It then occurred to me that of course it's Null because the assignment was made before the Dialog was executed. So …
Code: Select all
Sub AddingButton
Dim textarea as string
EnterBox=oDlg.getControl("TextField1")
SaveBox=oDlg.getControl("ListBox1")
textarea = EnterBox.Text
SaveBox.additem(textarea, SaveBox.getItemCount)
EnterBox.Text = ""
End Sub
I added a couple of things.
additem(textarea,0) inserts the new entry at the top of the list,
additem(textarea, SaveBox.getItemCount) adds it to the bottom of the list.
Also the last line clears the Text Box, ready for a new entry.
Re: I can't add data into ListBox in runtime
Posted: Sun Apr 02, 2017 6:48 pm
by zenira
Lastest code but it is not work
Re: I can't add data into ListBox in runtime
Posted: Sun Apr 02, 2017 7:49 pm
by UnklDonald418
I downloaded your example.
When I run the dialog and type something into the text box and press the Add button that string appears in the list box.
What doesn't work?
[Solved]I can't add data into ListBox in runtime
Posted: Sun Apr 02, 2017 8:16 pm
by zenira
Finally it work...
I notice where is fault. When i run it on IDE clicking "Run Basic", it does not run.I get this message
But I add a Run button on page and assign it Sub Main(), it works
it works now
Thank you guys, specially UnklDonald418,JeJe,RoryOF,Villeroy. thank you advices.
Re: [Solved]I can't add data into ListBox in runtime
Posted: Sun Apr 02, 2017 10:46 pm
by Villeroy
GlobalScope.DialogLibraries.loadLibrary("Standard") [global library]
DialogLibraries.loadLibrary("Standard") [embedded library]