Jump to content

record-format criteria with variables


Recommended Posts

Joshua Benghiat already told me, that record-format-criteria with variables can be finicky. However, I now wanted to switch my script to python.

 

Can anyone tell me why "ZANZAHL = vs.Count("('Wohnung'.'Haus-Nr'=Variable)");" doesn't work, or beter, what can I do for make it working?

Sure, the whole Syntax inbetween the quotation marks is a string, so, the variable gets lost.

Maybe I really have to concatenate the criteria to make them working, do I really have to? Sounds quite strange to me. Looking for record format criteria with variables sounds to me quite normal.

Link to comment
  • 2 weeks later...

finally have been able to resume my work on python, never thought it would be that different between vectorscript and python. The code from above doesn't return me any syntax errors, however, it doesn't still work

 

I actually try to calculcate the area of all objects with the same criteria, (like I already have been able to do in Vectorscript)

 

I tried it your way, then I tried it the other way you suggested me last time in vectorscript. 

Concatenating strings works fine in python, with + signs and with vs.Concat. However the area-function doesn't return me the area of all objects with the wanted criteria.

 

So I integrated the AlrtDialog in the end of the script, just to see what really is happening inside the script, and, every concatenation looks really good. However, the area is always empty. I also wrote # in front of the area function, just to see, if there was another problem. From that moment the HAREA variable was always = 1234. (because I set it = 1234 in the 5th line)

 

Somehow I want to port my script to python, too

1) because I am learning both, python and vectorscript

2) because i think that python in long terms is the better choice...

 

thanks for your great help to my last questions!

 

(unfortunately tabs don't work as I want them to work in the forum-quote)

Quote

BR = vs.Chr(10);
kQC = vs.Chr(39);
HNR=1
WHNR=1
HAREA=1234
for HNR in range (10):

    HNRS = (vs.Concat(HNR))
#    HNRS = vs.Num2Str(HNR, 0)    
    HQUERY = (vs.Concat('(',kQC,'datenbank', kQC,'.', kQC,'Haus', kQC,'=',HNRS,')'))
#    critSTRING = vs.Concat('((', kQC,'Wohnung', kQC,'.', kQC,'Haus-Nr', kQC,'=', kQC, HNR, kQC,') & (', kQC,'Wohnung', kQC,'.', kQC,'Whg-Nr', kQC,'=', kQC, WHGNR, kQC,'))');
        

    HAREA = vs.Area(HQUERY)
#    ZANZAHL = vs.Count("('datenbank'.'Haus'='"+HNR+"')")
    vs.AlrtDialog(vs.Concat('Haus-Nr ',HNRS,' hat ', HAREA,' m²',BR,'Abfrage: ', HQUERY))

 

 

python_criteria_test.vwx

Link to comment

First, one advantage to python is that it excepts both single and double quotes as string identifiers. That means that if you formulate your criteria string with double quotes, you don’t need to concatenate in all those quote characters, making your code more human-readable and thus easier to spot errors. 
 

I would also use the criteria builder in the script editor as a starting place. The criteria builder will tell you how many objects match your search, functioning as a quick unit test. Then, take the resulting string, select the variable and type: "++" (or ", , " for vs.Concat), and insert your variable name. 
 

There may be a simple error here, for example if the house number is stored as an integer, you would not enquote the search value. 
 

Also try AreaN() instead. 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...