If function won't recognize nil value string variable

If function won't recognize nil value string variable

Gorra
Advocate Advocate
1,119 Views
8 Replies
Message 1 of 9

If function won't recognize nil value string variable

Gorra
Advocate
Advocate

Hello,

I have a lisp that extracts values from a csv, writes them to variables and updates existing blocks, which it is thankfully doing. The problem is that it is supposed to skip sub-functions when it encounters blank entries in the csv, but it won't recognize the nil-value variables. I've had it pause and princ the value and type of the variable, which is set to a nil string.

 

I've tried

(if (eq RES_1_ADDRv nil)

(if (not (eq RES_1_ADDRv nil))

(if (/= RES_1_ADDRv nil)

(if (null RES_1_ADDRv)

(if (not (null RES_1_ADDRv)),

 

flipping the order of the subsequent then/else as appropriate. Is there an = or /= equivalent function specific to strings that I should be using?

 

(RES_1_ADDRv is global variable)

 

Thanks,

Gorra

0 Likes
Accepted solutions (1)
1,120 Views
8 Replies
Replies (8)
Message 2 of 9

ronjonp
Mentor
Mentor
Accepted solution

@Gorra Are you sure that the "nil" values aren't actually empty strings "" ?

(= RES_1_ADDRv "")

 

FWIW:

;; This
(if (eq res_1_addrv nil))
;; is the same as this
(if (null res_1_addrv))
;; as the same as this
(if (not res_1_addrv))
;; can be simplified to this
(if res_1_addrv)
0 Likes
Message 3 of 9

Gorra
Advocate
Advocate

@ronjonp 

I think I started out using "", but I'll try the assorted permutations with "" to make sure.

...

Not recognizing as "" either. 

 

Thanks,

Gorra

0 Likes
Message 4 of 9

ronjonp
Mentor
Mentor

If you're using the VLIDE, debug using a watch and break point on the variable to see what value it holds.

ronjonp_0-1711407280599.png

 

0 Likes
Message 5 of 9

Gorra
Advocate
Advocate

I will try it simplified and see if that works

0 Likes
Message 6 of 9

Gorra
Advocate
Advocate

@ronjonp 

If it can give me that information, I will get VLIDE directly and check. Or is that the one embedded in AutoCad?

 

 

Gorra

0 Likes
Message 7 of 9

ronjonp
Mentor
Mentor

@Gorra wrote:

@ronjonp 

If it can give me that information, I will get VLIDE directly and check. Or is that the one embedded in AutoCad?

 

 

Gorra


The VLIDE/VSCODE is included with the full version of AutoCAD. What are you using to debug now?

0 Likes
Message 8 of 9

Gorra
Advocate
Advocate

@ronjonp 

If I'm making significant changes the the code I use notepad++, with alerts and princs embedded in relevant places. I open the LISP editor in CAD about a quarter of the time. I didn't realize it could track your variable values, I'll have to start using it more.

 

It's looking like the simplified if statements are going to work. Having "if [variable]" and nothing after it returning nil isn't what I thought it would do, but I guess it makes sense.

 

Gorra

0 Likes
Message 9 of 9

Sea-Haven
Mentor
Mentor

If you use say getstring and press Enter you will get "" a string with nothing in it, a getreal press enter will return nil. 

 

Not sure if that helps.

0 Likes