Asked — Edited

( Within A String Variable

I receive the error: Error on line 7: Missing ) in Expression


$HumanSaid = "How far is the earth from the moon"

$URL="http://api.brainshop.ai/get?bid=xxx&key=xxxxxxxxxx&uid=1&msg=" + $HumanSaid
$URL = $URL + "Hello There"
sleep(3000)
$Answer = HttpGet($URL)
$StringLength = length($Answer)
$MessageLength = $StringLength - 14
$APIResponse = SubString($Answer,11,$MessageLength)
Say($APIResponse)

The variable $Answer = "{"cnt":"The moon is 252,088 miles (405,696 km) from Earth."}" If $Answer does not contain the character ( , the code works fine.


ARC Pro

Upgrade to ARC Pro

Experience early access to the latest features and updates. You'll have everything that is needed to unleash your robot's potential.

PRO
USA
#1  

Typo the line $URL = $URL + "Hello There" should not be there, I used it for testing.

#2  

I'm not a coding expert and I haven't messed with ez code for a while so I'm rusty. But.. I know ez script is very sensitive about spaces. I see that in your first $URL statement there is no space on either side of the = .

Also I don't see how you could have two variables, $URL, in the same script with two different explanations and not confuse the script.

#3  

OK. That explains the extra line.

Try adding a space before the = in the $URL line.

I'll get that exception on some of my scripts sometimes. I haven't been able to stop them. I had thought it was a timing issue at one time. I was able to make the problem better by adding some sleep commands but I can't confirm that's what helpped.

PRO
USA
#4  

@rz90208,

It's a string limitation, some characters e.g. "(", new line characters aren't supported.

check the threads: https://synthiam.com/Community/Questions/8278

https://synthiam.com/Community/Questions/8172

https://synthiam.com/Community/Questions/9006

btw the response text can be more complicated...

try on your browser:

http://api.brainshop.ai/get?bid=nnn&key=xxxxx&uid=1&msg=what%20means%20handsome?

PRO
USA
#5  

@DJ Any chance we can get this patched?

I read in one of the posts that the 4.x/2 update in march would correct it.

I tried doing a search of the string using the contains($x,$y), in hope I can just delete the (

But get the same error.

#6  

@rz90208 That's the problem with the left paren error. It can sit there in a string and be just fine, but as soon as you try to do any operation on the variable that contains the string, it crops up. Even if that operation is trying to remove, or replace the left paren. That's the Catch-22. What would be nice would be to have a file operation which would filter out (or replace) that sort of thing as it loads the up variable. But we don't have such a thing, and I don't have the inclination to make one.

What I do have is an external program that do all that. I simply gave up on ever having this problem fixed by EZ-Robot. It's been over a year now, after all. It was originally done as a temporary work-around. But programmers can't ever leave well enough alone. In it's latest incarnation, it can be set to filter out or replace any character (or group of characters) in the text. Additionally it can be set to look for key phrases to give it a starting place where to begin gathering the text from the web page, and a length of text to gather. That can drastically reduce the amount of text you (and the program) have to deal with. Once you send out a command to it (via a text file) it does all that and produces a text file as a result. You then bring in that text file instead of directly using the HTTPGet control.

The bad news is that I also used that project as a test bed to try out a new method of scripting that works more like other languages, complete with Function calls and a form of parameter passing. So there would be a bit of a learning curve to using it. The good news is that it only takes a few statements in this new style to implement it in any script. You can use the new methods and the current scripting methods together in one script. However you have to load up several script managers worth of scripts to your project to make it all work. This can be done via the "Merge" process in EZ-Script. They can be placed in another virtual window to get them out of the way. They are just a means to an end.

So it will solve your problem but take a bit more to implement. I should make a version that doesn't need the Merge and all that I guess, but I don't have the time at the moment. If you can wait for a week or so, I can probably do it then. If you are interested let me know.

PRO
USA
#7  

@WBS Waiting is getting to be a habit. Waiting for the new EZB controller, the new EZB communications board, the new little EZB controller, waiting for EZ-AI. I'm not complaining well maybe a little. But ya, I'm interested. I will add you to my list.

Thank you for the response.

#8  

LOL, ya, I hate the waiting game. However I've learned that these things take time to develop and deploy. The only way around the flustration for the huddled masses is for the designers and manufacturers not to announce until the product is ready for sale. Where's the fun in that? We'd all lose interest and move on to whatever is available at the time. I remember waiting for the V4 and was one of the first to get one. It was more than worth the year + wait and frustrations with all the missed deadlines. I'm sure my wait on the new products coming out soon will be the same. :)

#9  

OK. I finally took some time and revised the Text Scrubber program I have for more basic operation.

I have uploaded a project called ScrubProgBasic.ezb. It contains the scripts needed to make the scrubbing of web site text possible. It also contains 2 Notepad controls with a description of how it all works and how to use it.

Additionally, I have attached a zip file to this post which contains the executable file needed to make it all work, as well as, an .rtf file with the same information as in the Notepad controls. The difference is that, being rtf formatted it has appropriate bolding and color added to help make the text easier to read and understand. Otherwise the information is the same. Of course, by having it free from the project it can be placed at hand on the screen for reference.

NOTE: This zip file has been updated as of 10/01/2016 at approx. 5:00 PM

This project has been checked, but not fully. Not every possibility has been run. But I'm putting it out now to get it into the hands of users. Consider it a Beta release. While I expect it operate as expected, one never knows where software is concerned.

The first thing to do is to decide where you want to place the executable file, ScrubText.exe and modify the variable, $UserDir in MainScript to that directory path. Place ScrubText.exe there and everything else will fall into place. You can put it anywhere you like, on any drive. The default directory path is: $UserDir ="C:\Users\Public\Documents\TextScrubber".

Once you have done that you can run the ScrubInit script (once) to set everything up, and then run MainScript to watch it work. You won't really see anything since the program will be invisible when it runs, though the screen may refresh. MainScript is initially set up to run the system in Line By Line mode. That means the scrubbed text will be displayed in the monitor window line by line as it is read from the result file. It will go by really fast, so you won't actually be able to read it. It's just to demonstrate the operation.

That is one of two modes in which it can gather the data from the web site. The other is the "All At Once" mode in which the scrubbed text can be read into a single variable all at once. Unfortunately these two modes are mutually exclusive. This is explained in the documentation. Generally, you will find the line by line mode better to use.

The ScrubText.exe program does not run in the background. It only runs when scrubbing the web site raw text. It has no associated .ini file, nor does it make any entries in the Registry. It does create a few files for it's own use that reside in the same directory as it does. This means that if you wish to place it somewhere else later, all you have to do is move the executable file there and change the $UserDir variable to reflect that change. You can also delete the old directory and it's contents.

Let me know if you have questions and concerns. :)

ScrubFiles.zip

PRO
USA
#10  

Outstanding!, Thank you. I hope to find time to implement this this weekend. I will let you know how it goes. Thank you again

#11  

@rz90208 You're welcome. Glad to help. :)

One thing though. There are a couple of lines in the MainScript script which need to be removed. They are:


  #This gets the raw page text and puts it into a file without causing a crash.
FileWrite($RawDataPath,HTTPGet($WebPage))  

The script will still work even with it in, but it's redundant and the $GetRawData variable will have no effect as long as the second line is there. I'll be uploading a corrected project shortly.

#12  

Wow, this is a lot of technical anf detailed work. Thanks so much for going through all this trouble. This is very valuable stuff. Much appreciated!

#13  

@Dave_Schulpius

You're very welcome as well.

To ALL I went in to add a new section to the documentation in the Notepad controls and the rtf file and noticed some spelling errors. So I decided to run another spell check and found a number of other errors. Strange they weren't caught the first time. Anyway. as a result, I have re-uploaded the ScrubTextBasic.ezb file to reflect those changes.

Additionally, I revised the zip file in Post # 10. However, for convenience sake I have also zipped up just the rtf file with the added section as well as the corrections, attaching it to this post. Please download this revised rtf file version and kill the old one with fire. Thanks. ScrubTextBasic.zip

#14  

Revisions, Revisions, Revisions

I figured out a reasonably easy way to add case sensitivity selection to the ScrubText program and decided to implement it. The revised project has been uploaded to the cloud. Only the text in the Notepad control needed revision to reflect this new option so you don't need to download again if you don't want to.

However, you will need to download the new ScrubText executable. To do so, please go to post #10 and download the ScrubFiles.zip file which is attached to it.

While I was adding the case sensitivity option to the program, I discovered a potential bug in the software that can fill the ModData.txt file with incorrect data in some circumstances. Thus, you should download the zip file even if case sensitivity is not important to you (case sensitive = True is the current default). Once you have the new zip file, please replace the ScrubText.exe program with the new one and the ScrubText Basic.rtf you have now with the revised one.

The case sensitivity options are explained in the rtf file, but I'll list them here so you won't have to go through the entire text to find it.

Two of the parameters used in the scrub system are ::STT and ::ENT. The ::ENT parameter has been changed to ::ETT to better conform with the case sensitivity options. Two new parameters have been added. They are ::STF and ::ETF. These two parameters correspond directly to :STT and ::ETT. Each behaves exactly as their corresponding ones do except that they are not case sensitive.

STT stands for Start Text True and ETT stands for End Text True. The True part meaning Case Sensitive = True. Likewise, ::STF stands for Start Text False and ETF is End Text False. Meaning the search performed by them is Case Insensitive (Case Sensitive = False).

There is one more new Command; ::RCS. This stands for Replace Case Sensitive. This refers to character replacements (substitutions). The default in the ScrubText progran is Case Sensitive = True. To make the substitution search and replace case insensitive, you will need to send the command: ::RCS=False in the $ConStr variable.

Sorry about all that, but that's how it goes with new software.