Author Topic: How do I set a variable to "Nothing"  (Read 11169 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How do I set a variable to "Nothing"
« Reply #15 on: April 17, 2006, 01:16:35 PM »
<1st question>
"Streamlining", well yes in my eyes. As you know "Beauty is in the eyes of the beholder"
Nothing wrong with the way you did it. I just changed it to expose you to an alternate method.
Nothing more than that.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Amsterdammed

  • Guest
Re: How do I set a variable to "Nothing"
« Reply #16 on: April 17, 2006, 01:17:50 PM »
Hi
If you want to set a string to nothing (that is how I understand your problem) why not set it to an empty string:
Code: [Select]
""

Bernd

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: How do I set a variable to "Nothing"
« Reply #17 on: April 17, 2006, 01:19:59 PM »
Tried that, was getting the Quotes ("") in my string.

Hi
If you want to set a string to nothing (that is how I understand your problem) why not set it to an empty string:
Code: [Select]
""

Bernd
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: How do I set a variable to "Nothing"
« Reply #18 on: April 17, 2006, 01:25:50 PM »
In simplistic terms, OR produces a result by examining the items in the comparison individually, thus (or toggle1 (setq toggle1 "0")) will evaluate toggle1 and if it has a value (i.e. not nil) then it will not evaluate the second expression (setq toggle1 "0") ... you could theoretically string together many multiples of true/false statements and evaluate them until one evaluates true in this fashion. It would evaluate much like a conditional statement, evaluating each until a true is found. Once a single true statement is found, the code will exit from that line of code because what you are saying is essentially "if any one of the following statements are true" ... you don't need to evaluate the setq because it will always return a T unless you set it to nil.

I hope that explains it a little better ...

<edited for spelling>
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: How do I set a variable to "Nothing"
« Reply #19 on: April 17, 2006, 01:27:24 PM »
<1st question>
"Streamlining", well yes in my eyes. As you know "Beauty is in the eyes of the beholder"
Nothing wrong with the way you did it. I just changed it to expose you to an alternate method.
Nothing more than that.

:-D  Yes I know my code is ugly when compared to yours and the other grand masters of the swamp.  My first thought was my code is like the old WW1 tanks; slow and clunky nest to todays Abrams tanks.   :-D

That is why i asked all the questions.

Off to my morning 10:00 meeting in the afternoon.
Be back in a little.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How do I set a variable to "Nothing"
« Reply #20 on: April 17, 2006, 01:51:22 PM »
If you are using ok_cancel; or similar for exit buttons the (done_dialog) passes a 0 or 1
to the (start_dialog) and that is returned. So you can test the exit condition.

From the help file:

Quote
The start_dialog function returns the optional status passed to done_dialog. The
default value is 1 if the user presses OK, 0 if the user presses Cancel, or -1
if all dialog boxes are terminated with term_dialog. If done_dialog is passed an
integer status greater than 1, start_dialog returns this value, whose meaning is
determined by the application.

You do not need an action_tile as the (done_dialog) is called by default & a 0 or 1 is
passed to the (start_dialog) for a return value.

All I did was to change the return value 0 or 1 to a nill or true representation of the result.

Did that answer your question?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: How do I set a variable to "Nothing"
« Reply #21 on: April 18, 2006, 06:33:41 AM »

All I did was to change the return value 0 or 1 to a Nil or true representation of the result......So you can test the exit condition.


Okay I see it now.  By seeing if the start dialog is equal to one it would return a true and you used that to set the userclick variable.    It took along time to for me to see how it was setting the variable.  I was expecting a complicated test but in reality you made it very simple.  OOhhh you're good.

Did that answer your question?
It did but just brings more questions.  :-)
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How do I set a variable to "Nothing"
« Reply #22 on: April 18, 2006, 08:47:47 AM »
It did but just brings more questions.  :-)


I'll try.. :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: How do I set a variable to "Nothing"
« Reply #23 on: April 18, 2006, 09:34:03 AM »
OK, use this:
Code: [Select]
(if userclick
  (vl-remove nil
             (setq connames
                    (list
                      (if (= toggle1 "1") "name1")
                      (if (= toggle2 "1") "name2")
                    ;;;  (if (= toggle3 "1") "name3")
                    ;;;  (if (= toggle4 "1") "name4")
                    )
             )
  )
)

Gives you this:
Code: [Select]
("name1" "name2" "name4")

Okay, I plunk the this into the code and commented out only the lines for toggles 3 & 4.  I have not set those toggles yet.  I am not getting the return as predicted.  See the Variable Watch below.
Code: [Select]
LOG Watch
CONNAMES = nil
DCL_ID = 1
NAME1 = nil
NAME2 = nil
TOGGLE1 = "1"
TOGGLE2 = "1"
USERCLICK = nil
WHICH_ACTION = 1

Correct me where I go astray in my thinking what this code is attempting to do.
Step one it looks at (= toggle1 "1") and if this is true it returns "name1" to the list that is Setq to the variable connames.  If (= toggle1 "0") then returns a nil which eventually is removed from the list by the (vl-remove nil) function.  This I understand and follow. 

What is the (if userclick) doing? What is it being compared to with IF function?

Oh yeah, why am I getting the results that I am getting?
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How do I set a variable to "Nothing"
« Reply #24 on: April 18, 2006, 10:07:36 AM »
Post the code you are now using.
Looks like you are exiting the dialog box via cancel.
USERCLICK should = true if you exit with OK.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Binky

  • Guest
Re: How do I set a variable to "Nothing"
« Reply #25 on: April 18, 2006, 10:17:27 AM »
Being somewhat new I often get results that I did not quite intend or in the manner I wished for reasons that will become clear to me as I learn more.  In the meantime I find I can keep the train on the tracks by 'fixing' the results I got until enlightment shines upon my soul.  I would attack the returned string (being thrilled that I got anything back).  If the problem is '0's in the string I would remove the '0's.

(setq abc "one0two00three")
(repeat 5 (setq abc (vl-string-subst "" "0" abc)))
returned "onetwothree"

However vl-string-subst only replace 1 instance so I wrapped it in a repeat.
elegant-probably not, more like using a rusty scalpel. but hey it worked

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: How do I set a variable to "Nothing"
« Reply #26 on: April 18, 2006, 10:27:37 AM »
:oops: Me redfaced overhere.    :whistle:
I commented out your Accept/Cancel code to compare the results with my original code.  I forget to Un-Comment your code so as the userclick would work.  The routine works great.

That Apply function is a sweet little function.  One of the function that Autodesk explained nicely. Thanks for letting me know about that one.  I would have never thought to go down that road of thinking.

Now I am going to organize (pretty it up  :-D) this piece of the pie and dump back in to the main routine.  Hopefully everything everything will play nice with each other.

Thanks for your help.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: How do I set a variable to "Nothing"
« Reply #27 on: April 18, 2006, 10:29:06 AM »
Thanks for your help.

This reminds me.
Thanks to all that have help and/or made suggestions. 
 :-)
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: How do I set a variable to "Nothing"
« Reply #28 on: April 19, 2006, 08:38:21 AM »
I knew it was going too easy. :x

Does anyone know why the vl-remove function would stop working.  I was cleaning up and organizing the portion of code that been posted above.   All this morning, the vl-remove function was working great when I ran it numerous times giving me the expected returns.  When I copied this portion into the main routine it stop working right at the vl-remove function. Both lisp files have stop working at exactly the same spot.

Below is the portion of code with vl-remove function.
Code: [Select]
  ;; ;;PreSets Dialog Box Variables with Defaults~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(setq which_action 1)
(or toggle1 (setq toggle1 "0"))
(or toggle2 (setq toggle2 "0"))
(or toggle3 (setq toggle3 "0"))
(or toggle4 (setq toggle4 "0"))
(or toggle9 (setq toggle9 "0"))
(or toggle10 (setq toggle10 "0"))

  ;; ;;Starts Dialog Box Session~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(setq dcl_id (load_dialog "samp4.dcl")) ;load dialog

(if (not (new_dialog "samp4" dcl_id) ;test for dialog
    ) ;not
  (exit) ;exit if no dialog
) ;if

;;;  Radio Button Row~~~~~~~~~~~~~~~~~~~~~~
  (setq which_action 1)
  (action_tile "rb1" "(setq which_action 1)")
;New version 2004 file with date Prefix
  (action_tile "rb2" "(setq which_action 2)")
;New version 2000 file with date Prefix

 
;;; Toggle Alley~~~~~~~~~~~~~~~~~~~~~~
  (set_tile "tog1" toggle1)  ;set toggle
  (set_tile "tog2" toggle2)  ;set toggle
  (set_tile "tog3" toggle3)  ;set toggle
  (set_tile "tog4" toggle4)  ;set toggle
  (set_tile "tog9" toggle9)  ;set toggle
  (set_tile "tog10" toggle10)  ;set toggle

  (action_tile "tog1" "(setq toggle1 $value)");if toggle 1 selected - get the value
  (action_tile "tog2" "(setq toggle2 $value)");if toggle 2 selected - get the value
  (action_tile "tog3" "(setq toggle3 $value)");if toggle 3 selected - get the value
  (action_tile "tog4" "(setq toggle4 $value)");if toggle 4 selected - get the value
  (action_tile "tog9" "(setq toggle9 $value)");if toggle 9 selected - get the value
  (action_tile "tog10" "(setq toggle10 $value)");if toggle 10 selected - get the value


;;; Accepting & Canceling Buttons~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(setq userclick (= (start_dialog) 1))
(unload_dialog dcl_id) ;unload
(princ)
 
;;;Evaulating Toggles selected~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(if userclick
  (vl-remove nil
             (setq ConList
                    (list
                      (if (= toggle1 "1") "BSE")
                      (if (= toggle2 "1") "BEI")
                      (if (= toggle3 "1") "MnA")
                      (if (= toggle4 "1") "LnL")
      (if (= toggle9 "1") "Clnt")
      (if (= toggle10 "1") "OTH")
                    )
             )
  )
)

  (setq ConNames (strcat (apply 'strcat ConList) "_")) ;to be stored for the StrPath function

;;;;;; Main Application ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Posted from the Variable watch.
Code: [Select]
LOG Watch
...............
CONLIST = ("BSE" "BEI" nil nil nil nil)
CONNAMES = nil
DCL_ID = 3
NEWFILE = nil
OLDFILE = nil
TOGGLE1 = "1"
TOGGLE10 = "0"
TOGGLE2 = "1"
TOGGLE3 = "0"
TOGGLE4 = "0"
TOGGLE9 = "0"
USERCLICK = T
WHICH_ACTION = 1

 :realmad:
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How do I set a variable to "Nothing"
« Reply #29 on: April 19, 2006, 09:02:04 AM »
Because it's in the wrong place. :-)
Code: [Select]
(if userclick
  (setq ConList
             (vl-remove nil
                    (list
                      (if (= toggle1 "1") "BSE")
                      (if (= toggle2 "1") "BEI")
                      (if (= toggle3 "1") "MnA")
                      (if (= toggle4 "1") "LnL")
      (if (= toggle9 "1") "Clnt")
      (if (= toggle10 "1") "OTH")
                    )
             )
  )
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.