( Within A String Variable

 
#1

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


Code:


$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.

#2

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

#3

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.

#4

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.

#5

@rz90208,

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

check the threads:
https://www.ez-robot.com/Community/Forum/Thread?threadId=8278

https://www.ez-robot.com/Community/Forum/Thread?threadId=8172

https://www.ez-robot.com/Community/Forum/Thread?threadId=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?

#6

@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.

#7

@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.

#8

@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.

#9

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. Smile

#10

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. Smile

ScrubFiles.zip