TheSwamp

Code Red => Visual DCL Programming => AutoLISP (Vanilla / Visual) => OpenDCL => Topic started by: Tharwat on November 26, 2015, 07:07:58 AM

Title: Can't add string to ListBox
Post by: Tharwat on November 26, 2015, 07:07:58 AM
Hello guys,

I have searched about the way to add strings to a ListBox with no luck , so I tried it as following but it doesn't work.

Any one can correct it for me please?

Code: [Select]
(command "OPENDCL")
(defun c:test ()
  (dcl_project_load "FirstExample" t)
  (dcl_form_show firstexample_form1)
  (princ)
)

(defun c:firstexample/form1/textbutton2_onclicked (/)
  (dcl_form_close firstexample_form1)
)

(defun c:firstexample_form1_oninitialize (/)

  (foreach x '("layer1" "layer2" "layer3")
    (dcl_listbox_addstring firstexample_form1_listbox1 x)
  )
)
Title: Re: Can't add string to ListBox
Post by: Kerry on November 26, 2015, 07:39:10 AM
How old is the reference you are learning from ?

The functions are separated by hyphens, not underscores.
The control names are separated by  a slash, not an underscore.

The old way may still work .. I'm not sure.

That looks like it should work, but I'm not going to make an .odcl to test it.
Please post your .odcl file.

Which version are you using ?

Title: Re: Can't add string to ListBox
Post by: Tharwat on November 26, 2015, 07:51:10 AM
Thank you Kerry .

I am using the OpenDCL Studio 8.0 3.0

I am also was confused about the separating symbols Hyphen , Underscore and  Hash tags .

Actually the program is working without any errors ( without the ListBox) , as you may know that I am just learning the OpenDCL and wanted to start using the tools one by one to become familiar with their codes and abilities .

Here I am attaching the OpenDCL file.

Thank you
Title: Re: Can't add string to ListBox
Post by: Kerry on November 26, 2015, 07:57:16 AM
The first thing I see is that you don't have the Events toggled on foe Initialize etc.

I'll have a look. Need coffee first though.

Title: Re: Can't add string to ListBox
Post by: Kerry on November 26, 2015, 08:04:05 AM
In the IDE, select (click) the ListBox1 either on the form itself of in the Control List on the Lower Left ( I prefer this)
Right Click the ControlName
Select Control Browser.
Select AddList from the Methods.
You'll see the Syntax to use.

Alternatively Select AddString for doing the adding one at a time

Title: Re: Can't add string to ListBox
Post by: Tharwat on November 26, 2015, 08:16:14 AM
Thanks Kerry , that did solve the problem.

Yeah , I search the help for the add_list method but honestly the document is very poor of enough descriptions for each function ( method ).

Life seems easy with OpenDCL to me for now , although I wanted to learn this tool from a quite two or three years ago , but it was complicated to me in that time and I don't know why.

Anyway , I do appreciate your time and inputs Kerry.

Regards.
Title: Re: Can't add string to ListBox
Post by: Kerry on November 26, 2015, 08:31:17 AM

Good, pleased I could help. It's been a while since I've used OpenDCL :)


Have a play with this as a template

Code - Auto/Visual Lisp: [Select]
  1. (command "OPENDCL")
  2. ;;; (dcl-project-load "FirstExample" t)
  3. ;;; use this for testing, while changing odcl
  4.  
  5. (defun c:test (/ returnResult itemSelected)
  6.   (dcl-project-load "FirstExample")
  7.   (setq returnResult (dcl-form-show firstexample/form1))
  8.   (cond ((= returnResult 100) (alert (itoa itemSelected)))
  9.         ((= returnResult 2) (alert "User Cancelled"))
  10.   )
  11.   (princ)
  12. )
  13.  
  14. (defun c:firstexample/form1/textbutton2#onclicked (/)
  15.   (setq
  16.     itemSelected (dcl-ListBox-GetCurSel FirstExample/Form1/ListBox1)
  17.   )
  18.   (dcl_form_close firstexample/form1 100)
  19. )
  20.  
  21. (defun c:firstexample/form1#oninitialize (/)
  22.   (dcl-ListBox-Clear FirstExample/Form1/ListBox1)
  23.   (dcl-ListBox-AddList FirstExample/Form1/ListBox1
  24.                        (list "Alpha" "Bravo" "Charlie")
  25.   )
  26. )
  27.  
  28.  
  29.  
  30.  
Title: Re: Can't add string to ListBox
Post by: Tharwat on November 26, 2015, 11:26:04 AM
Nice extra functions for the ListBox tile to know.  8-)

Thank you.
Title: Re: Can't add string to ListBox
Post by: owenwengerd on November 27, 2015, 10:32:06 AM
Or something like this to avoid the non-local itemSelected value:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ returnResult)
  2.   (dcl-project-load "FirstExample")
  3.   (setq returnResult (dcl-form-show firstexample/form1))
  4.   (cond
  5.     ((= returnResult 2) (alert "User Cancelled"))
  6.     ((> returnResult 2) (alert (itoa (- returnResult 3))))
  7.     )
  8.   (princ)
  9. )
  10.  
  11. (defun c:firstexample/form1/textbutton2#onclicked (/ itemSelected)
  12.   (setq
  13.     itemSelected (dcl-ListBox-GetCurSel FirstExample/Form1/ListBox1)
  14.   )
  15.   ;lowest possible value for itemSelected is -1, so add 3 to avoid value clash
  16.   (dcl_form_close firstexample/form1 (+ 3 itemSelected))
  17. )
  18.  
Title: Re: Can't add string to ListBox
Post by: Kerry on November 27, 2015, 11:08:12 AM
Hi Owen.,
Sorry, I don't understand your concern with the itemSelected variable.

I have it declared local in c:test()
It will not pollute or be polluted by a variable of the same name in global scope.

Regards,
Title: Re: Can't add string to ListBox
Post by: owenwengerd on November 27, 2015, 11:32:44 PM
I have it declared local in c:test()
It will not pollute or be polluted by a variable of the same name in global scope.

No, but in your version it will pollute the (c:test) scope.