Load set of variables from text file - Page 2 - Forum

Forum Navigation
You need to log in to create posts and topics.

Load set of variables from text file

PreviousPage 2 of 3Next

@smartmedia

LATEST UPDATE - the CORS error is/was being reported in error !!

After a good night's sleep, I looked at the issue with some fresh eyes, and tried putting  a time delay after the FileToVar command; Voila, the CORS error message disappeared.

I am attaching the revised sample App; please review it and advise if it works for you.

I have a couple of other improvements in mind, but will not begin until you confirm that this is going to satisfy your requirements.

 

Uploaded files:
  • You need to login to have access to uploads.
luishp and farhad2008 have reacted to this post.
luishpfarhad2008

Hello, @gaev @luishp and @smartmedia instead of Wait it is better to use Watch

... load the contents of the txt file into a single variable
FileToVar "https://servicefinder.gr/en.txt" [allText]
Watch [allText] "setupVariables"
... All Done

Greetings

luishp, Darbdenral and susan have reacted to this post.
luishpDarbdenralsusan

Hi,

Very Good.

@gaev

I have test it your code and is working locally and on web putting a wait of 800m/s. I call the sub on start-up and i even change the language from greek to english and via versa. The only problem i have is that on some text they are HTML tags that are not rendered. So if i can't found a way to bypass that obstacle i will not add the multi-language future.

@smartmedia

1) I have test it your code and is working locally and on web putting a wait of 800m/s.

As mentioned by @emmanuel-fernandez , instead of using a Wait it is better to use Watch (because slower machines/internet-access-speeds may require a longer wait time).

If you chose to pursue this project, in the next version, I was hoping to implement his suggestion.

2) While I used prefixes of "sm" for variable names for testing purposes, note that the prefix string needs to be something that is not also part of the rest of the line e.g.

smPrism=blah blah blah
smBlahBlah=You have something to smile about

... will both fail because the variable returned from FileToVar is being split into lines using this string as the delimiter.

Something like xlate1 or smart2 would be better choices for prefixes.

3) If you do not want to be constrained by any prefix string, you could consider placing something like $$$ or ;; or {} at the END of each line.

This can be accommodated with a small change in the subroutine.

4) The only problem i have is that on some text they are HTML tags that are not rendered.

In general, text with HTML tags will only be rendered (by the Browser) when placed inside containers that are setup for rich text; otherwise the content (including tags) is treated as being plain text.

Can you give an example of ...

- a text file with such tags
- the type of Container you are planning to use to show such rich text

luishp, farhad2008 and 3 other users have reacted to this post.
luishpfarhad2008Darbdenralemosmartmedia

Hi @gaev,

because is a lot of task to translate everything with that method and facing the problem that HTML are not rendered i decided NOT to include that solution.

The translation of Google does a got job all though it cuts for some reason the spaces between glyphicons and text.(see the pictures) So i am thinking if there is any api that we can use so the page will be translated on the fly.

Again, you knowledge and you contribution is always touching for me, all those years you are helping people. A big thanks from my heart..

Uploaded files:
  • You need to login to have access to uploads.

@smartmedia regarding missing spaces, have you tried using   instead of a simple space?
Perhaps this simple change will do the trick.

Quote from luishp on May 16, 2023, 11:34 am

@smartmedia regarding missing spaces, have you tried using   instead of a simple space?
Perhaps this simple change will do the trick.

I use   i also change it to   but again the same result. It removes all spaces between glyphicons and text.

Also notice that vertical-align property is not working in Style Tab on Text objects. Can you verify that ?

@gaev

I found a way to overcome the problem about HTML tags inside the text. So instead of using setvar to load the text its better to use setobjectHTML that accepts all HTML tags and instead of using a variable i will use the object name. What do you think about that ?

@smartmedia

When you mentioned in an earlier post that ...

The only problem i have is that on some text they are HTML tags that are not rendered.

... that was exactly what I was trying to say (in a rather clumsy way) when I responsed that ...

In general, text with HTML tags will only be rendered (by the Browser) when placed inside containers that are setup for rich text; otherwise the content (including tags) is treated as being plain text.

So, if you update your text file with variable values that contain html tags, I will post v3 of the sample App

While you are at it, please use delimiters other than "sm" (something non-conflicting like xlate1 or qwrt); you can place them at the start or end of the line, and I will adjust the code likewise.

 

smartmedia has reacted to this post.
smartmedia

@gaev

I have changed the text on the file to check it out.

Headline1=In first part will be the object name and on second part will be the text$$
Headline2=I dont know if the equal sign (=) is the appropriate symbol to use as separator between elements$$
Paragraph1=I think its better to use the special character at the end of line$$
TextInput1=A possible special character could be the $$ dollar sign or a special character that is not used in HTML tags$$

 

@smartmedia

Thank you for the new text file.

Something unexpected came up, and took away 2 hours of my time; so there will be a slight delay in uploading v3 of the sample App; hopefully tomorrow night.

Here is my plan for the new version ... you will be able to specify ...

a) the name of the file containing the variable name/value pairs
b) the name of the (single) variable where the contents of the file will be uploaded
c) the character string at the end of each line (e.g. "$$" or "zzz" etc.)
d) The "character string" that separates the names of the variables from their content (currently = sign; but can be something like "==" or "=>" etc.)

It is important to make sure that strings specified in (c) and (d) above are NOT something that will be present in any of the variable names or values, as these strings are used to split the various lines and variable parts.

I am hoping to provide a solution that allows users to invoke this facility from a single command (subroutine name or plug-in command) with parameters for (a) to (d).

I am also trying to see if I can replace the Wait with the suggestion put forward by@emmanuel-fernandez ; but since his suggestion requires a call to another subroutine, I have to find out how a call to a subroutine from another subroutine works.

smartmedia has reacted to this post.
smartmedia

@gaev , @smartmedia

Hello, why don't you use "\r\n" as an end-of-line delimiter?

I leave the example using this solution, see if it is valid for your specifications

 

Uploaded files:
  • You need to login to have access to uploads.

@emmanuel-fernandez

Hello, why don't you use "\r\n" as an end-of-line delimiter?

I think you misunderstand the issue.

By default, @smartmedia IS using this character combo in his text file; but when FileToVar loads all the lines into a single variable, it separates the lines via a single space (could be some other unprintable character).

So, the workaround is to place some printable characters (like "$$") that can then be used to split the content into its original lines.

BTW, as good as your previous suggestion for using Watch instead of Wait, I realized that it is not usable in this scenario because the specified subroutine can not take parameters; without parameters, the subsequent processing of the single variable becomes too complex or requires number of commands (smartmedia's requirement is to enable this functionality with just one line of code). But thanks for that useful suggestion.

@gaev  I use FileToVar "https://servicefinder.gr/en.txt" [allText] to get all the text

I use watch to call the subroutine that splits the contents and setup correctly the vars with their values

Maybe I'm also a senior who needs rest ;-) but the result seems correct to me with the text provided in the url

It can also be like you say I'm not understanding the problem well.

Uploaded files:
  • You need to login to have access to uploads.

Hi..

To clearly some issues. This function will be used to load different language text in the site. Will be loaded on every page because i notice that when i move from one page to another using the SetObjectHTML the changes all ready loaded are gone. I don't know why this is happening, perhaps because are NOT variables. So having that in mind, on startup on every page i will call a subroutine with the file name to be called as a parameter. From that point a FileToVar command will be used to load the text and then to parse the text in two elements. So using watch is useless. Then those two elements (1 element = objectname - 2 element = text) will run a loop according to the length of lines have been created by the string parse and in finally a SetObjectHTML command will load the text on objects.

@gaev

When you ready i be happy to test it..

@emmanuel-fernandez

It is not impossible, but gets very complicated to make it happen with just one command (function or plugin), and have its parameters passed from the function/plugin to the subroutine specified as part of the Watch command. Yes, it could be done with some hard-coding of the parameters but flexibility is also an important consideration.

Perhaps you can take a look at v3 of the sample app that I am hoping to deliver tonight; if you can use Watch and still maintain flexibility and one command, I will be happy to look at it.

@smartmedia

Yes, it is a good idea to have the variables for each page in a separate file; I once tried a similar scheme for a VisualNEOWin Application, and it was noticeably slow when all variables were in a single file.

After I deliver v3, we can look at how the individual variables can populate the different objects; I think that in many cases, you won't need SetObjectHTML if the "container" supports rich text.

After I deliver v3, I will ask you to setup different files in order to test different values for the delimiters.

 

smartmedia has reacted to this post.
smartmedia

@gaev , But have you seen my solution? Maybe I'm slowly becoming invisible... :-)

@emmanuel-fernandez

But have you seen my solution?

Generally, I don't let myself get distracted by alternatives while I am pursuing one myself; but I did look at your sample app.

a) When I ran it, the displayed variable content ignored the rich text tags in the text file.

b) it is a good solution were it not for the explicit requirement from smartmedia that it be invoked with a single command (though 2 commands would be acceptable to me).

c) you don't get the flexibility of specifying delimiters for new lines (again, using standard characters would be fine with me)

d) you don't get the flexibility of specifying the delimiter separating variable name from variable values (the standard = sign might conflict with variable values.

@gaev ,Thank you for responding and checking it out. For me it is a valid generic solution, which is a pity that it is not worth for smartmedia requirements, in any case it can be useful for someone. There can be no problems with the "=" and the content of the varible since it only looks for the first one and ignores any other.

Greetings and happy programming.

smartmedia has reacted to this post.
smartmedia
PreviousPage 2 of 3Next