List boxes filled only on 2nd recall of function

Started by tedicad, June 28, 2011, 05:04:49 AM

Previous topic - Next topic

tedicad

I have been working with opendcl for a few weeks now, and it is fun, thanks a lot to all of you.

Now, on my first "serious" piece of code I encounter a problem I could not solve: everything works fine, with one exception: my listboxes are just empty the first time I recall the function. Closing the box and recalling the function shows them just the way I want them. I tried to move code around, but once I had the listboxes properly filled, the OK-button did not work anymore. Here is the code:

; Ensure the appropriate OpenDCL ARX file is loaded
(command "OPENDCL")
(defun c:s203 ()


; Create the lists the user will choose a value from:
(setq s203Breite '("  624 (2 Schuppengläser)"
                   "  924 (3 Schuppengläser)"
                   "1224 (4 Schuppengläser)"
                   "1524 (5 Schuppengläser)"
                   "1824 (6 Schuppengläser)"
                   "2124 (7 Schuppengläser)"
                   "2424 (8 Schuppengläser)"
                   "2724 (9 Schuppengläser)"
                   "3024 (10 Schuppengläser)"
                   "3324 (11 Schuppengläser)"
                   "3724 (12 Schuppengläser)")
      s203Achsen '("0" "1" "2" "3")
      s203Glastyp '("VSG/ESG"
                    "Heat Mirror"
                    "ESG/ESG (nur CH!)")
      )

; call the method to load the s203.odcl file.
(dcl_Project_Load "s203" T)

; call the method to show the s:203 dialog box
(dcl_Form_Show s203_Form1)
 
(defun c:s203_Form1_OnInitialize (/)
  (dcl_ListBox_AddList s203_Form1_RIM-H s203Breite)
  (dcl_ListBox_AddList s203_Form1_AnzahlMittelAchsen s203Achsen)
  (dcl_ListBox_AddList s203_Form1_GlasTyp s203Glastyp)
)
 


(defun c:s203_Form1_OK_Button_OnClicked (/)
  (setq Val_RIM-B (atof (dcl_Control_GetText s203_Form1_RIM-B)))
  (setq Val_RIM-H (dcl_ListBox_GetSelectedItems s203_Form1_RIM-H))
  (setq Val_AnzahlMittelAchsen (dcl_ListBox_GetSelectedItems s203_Form1_AnzahlMittelAchsen))
  (setq Val_GlasTyp (dcl_ListBox_GetSelectedItems s203_Form1_GlasTyp))
  (if (or
       (< Val_RIM-B 400.)
       (> Val_RIM-B 5200.)
       (= Val_RIM-H NIL)
       (= Val_AnzahlMittelAchsen NIL)
       (= Val_GlasTyp NIL))
    (dcl_messagebox "Es muss in jedem Feld ein Wert angeklickt sein, ausserdem muss die Breite minimal 400 mm / maximal 5200 sein. Bitte korrigieren Sie Ihre Eingabe")
    (dcl_Form_Close s203_Form1)
    )
  )
)


I'll attach both the lsp and odcl files. The error will be stupid, I assume, but since I only am a "part time programer", more at home on the engineering side of life, I just can't identify the fault.

Thanks a lot in advance,

Holger

Fred Tomke

Hi, and welcome to the board.
Please define the events before dcl_form_show otherwise your form does not know what to do.

Regards, Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

tedicad

Thanks a lot! That was absolutely fast, you saved my day! It works. Got to improve my error routine now, and some more things...

Holger

owenwengerd

You should use OnInitialize to initialize your listbox, otherwise your initialization code will not execute until after the form is closed.
Owen Wengerd (Outside The Box) / ManuSoft

Fred Tomke

Quote from: tedicad on June 28, 2011, 07:14:07 AM
...and some more things...

Yes, that's right: either you use (dcl_Control_SetList Unbenannt_Dialog1_Listenfeld1 lstNewValue) instead of AddList or you call (dcl_ListBox_Clear Unbenannt_Dialog1_Listenfeld1) before AddList because the Listbox remains this list after reshowing the form (when you will remove the T argument after project_load in future).

Regards,
Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]