Get extract value from fact - prolog

Im pretty new to prolog, and got stuck.
I need to store a variable with some string during calculations, I decided to do this by adding a "single fact" to the class I'm working with. Everything works well, the string is being stored, but when I try to add the code to access it later on, compiler returns an error "The expression has type 'dataBL::dataBL#objectDB', which is incompatible with the type '::symbol'".
I dont think it is the valid way to store a variable, so, can anyone help me with that? I tried searching online for the answers, and found nothing.
I'm trying to access the fact like this:
getString(U) :-
U = stringStorage(_).

If I get you right you need to store a value associated with some variable ID (key) as a fact. The (abstract) solution for your task canas the storing your values as a facts:
bind( Key, Value ).
Example of implementation (SWI Prolog)
Storing
recordz('var1', "String value1"),
recordz('var2', "String value2")
Querying value of var2
current_key(-Key),
Key = 'var2'
recorded(Key, Value)

Related

DMQL2 Query Syntax for PHRets v2 Seach() to include filter arguments?

(It's been a while since I've been here.)
I've been using the first version of PHRets v1 for years, and understood it well enough to get by, but now I'm trying to understand the advantages of v2.6.2. I've got it all installed and the basics are working fine. My issues are pretty much with comprehending fine points of query syntax that goes into the rets=>Search() statement. (I'm much more familiar with SQL statements). Specifically, I'd like to have a query return a list of properties, EXCLUDING those which already have the status of "Sold".
Here's where I am stuck: If I start with this
`$results = $rets->Search('Property', 'A','*',['Select' => 'LIST_8,LIST_105,LIST_15,LIST_19,listing_office_shortid']);`
That works well enough. BUT I'd like to fit in a filter like:
"LIST_15 != Sold", or "NOT LIST_15=Sold"...something like that. I don't get how to fit/type that into a PHRets Search().
I like PHRets but it is so hard to find well-organized/complete documentation about specific things like this. Thanks in advance.
As in my comment above I've figured out that the filter goes in the third argument position ('*', as in the original question). The tricky thing was having to find a specific "sold" code for each class of properties and placing it in that position like so: '(LIST_15=~B4ZIT1Y75TZ)', (notice the =~ combination of characters that means "does not equal" in this context). I've found the code strings for each of the property types (not clear WHY they would need to be unique for each type of property: "Sold" is Sold for any type, after all) but the correct code for a single-family residential property (type 'A' ...at least for the MLS in which I have to search is:
$results = $rets->Search('Property', 'A','(LIST_15=~B4ZIT1Y75TZ)',['Select' => 'LIST_8,LIST_105,LIST_15,LIST_19,listing_office_shortid']);
(again, the code to go with LIST_15 will be different for the different types of properties.) I think there is a better answer that involves more naturalistic language, but this works and I guess I will have to be satisfied with it for now. I hope this is of some use to anyone else struggling with this stuff.

UiPath: Collection.contains("string") doesn't appear to be returning Boolean as expected

First I use a "Get processes" activity which assigns its result to a variable called currentProcessesCollection which is of type Collection
Next I want to check this condition in and If activity currentProcessesCollection.Contains("OUTLOOK")
I'm getting 'string' cannot be converted to type System.Diagnostics.Process'
I'm kind of flummoxed by this and wondering if anyone knows some other way to do this. I was kind of hoping that writing out the problem would help, it didn't. Thanks for any help in advance. I need to find out if outlook is running.
As you correctly said, currentProcessCollection contains a collection of Process objects. As such, Contains requires another Process object in order to compare them, when you provided the string object "OUTLOOK.EXE".
If you want to search whether at least one process by name exists, just assign the following to a boolean variable (just replace Scan with any process name):
processCollection.Where(Function(x) x.ProcessName = "Scan").Count > 0

Type mismatch error while reading lotus notes document in vb6

Am trying to read the lotus notes document using VB6.I can able to read the values of the but suddenly type mismatch error is throwed.When i reintialise the vb6 variable it works but stops after certain point.
ex; address field in lotus notes
lsaddress=ImsField(doc.address)
private function ImsField(pValue)
ImsField=pValue(0)
end function
Like this I am reading the remaining fields but at certain point the runtime error "13" type mismatch error throwed.
I have to manually reintialize by
set doc=view.getdocumentbykey(doclist)
The type mismatch error occurs for a certain field. The issue should be a data type incompatibility. Try to figure out which field causes the error.
Use GetItemValue() instead of short notation for accessing fields and don't use ImsField():
lsaddress=doc.GetItemValue("address")(0)
The type mismatch is occurring because you are encountering a case where pValue is not an array. That will occur when you attempt to reference a NotesItem that does not exist. I.e., doc.MissingItem.
You should not use the shorthand notation doc.itemName. It is convenient, but it leads to sloppy coding. You should use getItemValue as everyone else is suggesting, and also you should check to see if the NotesItem exists. I.e.,
if doc.hasItem("myItem") then
lsaddress=doc.getItemValue("myItem")(0)
end if
Notes and Domino are schema-less. There are no data integrity checks other than what you write yourself. You may think that the item always has to be there, but the truth is that there is nothing that will ever guarantee that, so it is always up to you to write your code so that it doesn't assume anything.
BTW: There are other checks that you might want to perform besides just whether or not the field exists. You might want to check the field's type as well, but to do that requires going one more level up the object chain and using getFirstItem instead of getItemValue, which I'm not going to get into here. And the reason, once again, is that Notes and Domino are schema-less. You might think that a given item must always be a text list, but all it takes is someone writing sloppy code in an one-time fix-it agent and you could end up having a document in which that item is numeric!
Checking your fields is actually a good reason (sometimes) to encapsulate your field access in a function, much like the way you have attempted to do. The reason I added "sometimes" above is that your code's behavior for a missing field isn't necessarily always going to be the same, but for cases where you just want to return a default value when the field doesn't exist you can use something like this:
lsaddress ImsField("address","")
private function ImsField(fieldName,defaultValue)
if doc.hasItem(fieldName) then
lsaddress=doc.getItemValue(fieldName)(0)
else
lsaddress=defaultValue
end if
end function
Type mismatch comes,
When you try to set values from one kind of datatype variable to different datatype of another variable.
Eg:-
dim x as String
Dim z as variant
z= Split("Test:XXX",":")
x=z
The above will through the error what you mentioned.
So check the below code...
lsaddress = ImsField(doc.address)
What is the datatype of lsaddress?
What is the return type of ImsField(doc.address)?
If the above function parameter is a string, then you should pass the parameter like (doc.address(0))

How can I retrieve object keys from a sequence in freemarker?

I have a list of objects that are returned as a sequence, I would like to retrieve the keys of each object so as to be able to display the object correctly. At the moment I try data?first?keys which seems to get something like the queries that return the objects (Not sure how to explain that last sentence either but img below shows what I'm trying to explain).
The objects amount of objects returned are correct (7) but displaying the keys for each object is my aim. The macro that attempts this is here (from the apache ofbiz development book chapter 8).
Seems like it my sequence is a list of hashes and as explained by Daniel Dekany this post:
The original problem is that, someHash[key] expects a
string as key. Because, the hash type of FTL, by definition, maps
string keys to arbitrary values. It's not the same as Java's Map.
(Note that to further complicate the matters, in FTL
someSequenceOrString[index] expects an integer index. So, the [] thing
is used for that too.) Now someBeanWrappedMap(key) has technically
nothing to do with all the []-s, it's just a method call, so it
accepts all kind of keys. If you have a Map with non-string keys, you
must use that.
Thanks D Dekany if you're on stack, this ended my half day frustration with the ftl template.

Reference Variable as a value - VB6

Is it possible to use a variable value as a name for a reference variable? For example:
Dim PersonName As String
PersonName = recordset("PersonName")
Instead of the value of PersonName being a person name e.g. JoeBloggs; the reference variable itself would be JoeBloggs i.e. joebloggs = whatever.
I have looked around for the answer as I thought it would be a common question; but I was unable to find one.
#w0051977 dont worry, your need (if i understand it correctly) does make sense, ive wanted to do this once as well. If you understand it, you want to be able to define your variables name using a string? Like, if you have a "JohnDoe" in your database then you want to set the name of your variable as a string named JohnDoe, am i right? if that is right, you can't directly do this in VB6, however, in vb.net we have reflection so there is some way you can read the name of the variable and have it returned as a string (though i understand you want to do the opposite). So, best way to do this in vb6 is the following...
Dim c As Collection ' where c is our collection to make it short-hand/less typing.
Set c = New Collection ' you could have done As New Collection instead but this is better, trust me.
c.Add "MyValue1", "JohnDoe" ' sets a variable named JohnDoe with value "MyValue1"
c.Add "MyValue2", "JessKay" ' remember, these are stored as Variants, but can use as string.
Now to call it...
MsgBox c("JohnDoe") ' this simple.
so c("JohnDoe") will return whatever is in the value you've set for this variable name.
same story for the chick, say you wanna set another variable with the girls value in it...
Dim abc As String
abc = c("JessKay") ' thats all :) abc will equal "MyValue2"
Also, remember anything stored in a VB6 collection will always be stored as a Variant, so takes more memory than a String. However, you can still use it as a string or a number or anything else you want.
Cool?
Let me know if your needs were actually different and i've misunderstood your question. thanks.

Resources