How to save an info from external text to a parameter?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-15
10:49 AM
- last edited on
2021-09-14
08:59 AM
by
Noemi Balogh
I was trying to save text (numbers in text files are string type) to parameter. I've created parameter "x" - text array. Didn't change it, so x[1] = ""
Master script
dim x[5][5] for i=1 to 5 for j=1 to 5 x="" next j next i ch=OPEN("text",”voda.txt”,"separator='\t', mode=ro, Library") iLine=1 nr=INPUT(ch, iLine, 1, v1, v2, v3, v4, v5) WHILE nr>-1 DO !just to limit, original text filex has >50 rows if nr then x[iLine][1] = v1 x[iLine][2] = v2 x[iLine][3] = v3 x[iLine][4] = v4 x[iLine][5] = v5 else add2 0, -1 !empty row endif iLine=iLine+1 nr=INPUT(ch, iLine, 1, v1, v2, v3, v4, v5) ENDWHILE CLOSE ch for iLine=1 to 5 for j=1 to 5 text2 5*(j-1),1-iLine,x[iLine] next j next iLine x[1][1]="a b c" !without it X_array stays empty; with it x[1][1] is overwritten and first column and row stays empty, BUT rest values are correct. why ?!! parameters x=xbut idk why "parameters x=x" has no effect. I mean when I check "x" parameter it remains empty (if comment x[1][1]='abc'). Because after closing reading the file text2 cycles show proper values in 2D view (without it I'd think that code is wrong and it even didn't read the file). So array should have correct values, I guess.
----->”voda.txt”<--------- 0 4 6 8 10 1 0,22 0,28 0,33 0,39 2 0,23 0,29 0,34 0,40 3 0,25 0,30 0,36 0,42 4 0,26 0,32 0,38 0,44
Solved! Go to Solution.
- Labels:
-
Library (GDL)
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-16 12:32 PM
Please try the following: replace all fields with strings, e.g. #1 insted of 1.
After the import you can split #1 to 1 again.
For some reason the TEXT Addon cannot handle mixed Vartypes.
GDL object creation: b-prisma.de

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-15 09:30 PM
I faced to that problem several years ago (this why I don't remember all details of it). Was something like if I save 0 into txt - this value was skipped and in total I received less fields and couldn't read from txt these values back. The solution was to detect zero and record instead 'null'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-16 08:42 AM
For simplisity I've reduced size of text file to share here. The original one has [54][21]. And turns out if the text file has "0", array saves it indeed as empty string. If it has "0,00" array will has "0,00" also. In this case it's not a problem that array has some cells with empty strings, but that I can't save 1st column and 1st row. Of course, I can add redundant column and row to text file and I'll get data I want, but that's bad solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-16 09:24 AM
If they are numbers, they must be "0.22", "0.28", etc.
GDL object creation: b-prisma.de
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-16 09:46 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-16 10:01 AM


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-16 10:41 AM
Is it your first try of using txt Add-On?
I wrote some tools based on txt database - and it actually worked. Several years on different platforms, computers and versions.
Another question - what you shared here it's all you have got or just fragment of bigger object / system - anything you are developing? Maybe, if you are saving in txt only numbers, try to read them as numbers? Just set your x array as numbers. This is also annihilating the problem with zero, I mentioned before, because this problem exist only with string variables. In case of integer zero will be zero.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-16 12:32 PM
Please try the following: replace all fields with strings, e.g. #1 insted of 1.
After the import you can split #1 to 1 again.
For some reason the TEXT Addon cannot handle mixed Vartypes.
GDL object creation: b-prisma.de
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-16 01:20 PM
Podolsky wrote:It's my first try of text Add-On. So, unfortunately, it could be anything... here is 7z archieve
Strange that it's not working properly.
Is it your first try of using txt Add-On?
I wrote some tools based on txt database - and it actually worked. Several years on different platforms, computers and versions.
Another question - what you shared here it's all you have got or just fragment of bigger object / system - anything you are developing? Maybe, if you are saving in txt only numbers, try to read them as numbers? Just set your x array as numbers. This is also annihilating the problem with zero, I mentioned before, because this problem exist only with string variables. In case of integer zero will be zero.
Now I made 2 text files - one is original (with commas instead of dots) and another with dots. And I've created 2 different arrays: one has string values, other real numbers. And for some reason "trick" with overwritting first cell of array effecting only text array, not with numbers. Plus if you look at 2D view all numbers are zero - left side, big one, is string array (with different values) and right side is number array with zeroed values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2021-07-23 10:46 AM
Win 10 AC23 7000 AUT
Win 10 AC22 6021 AUT
However I had also some problems with getting the input right: the add-on actually interprets numbers as numbers directly, you don't have to convert them. In order for this to work correctly, you have to set the variable right though, so:
Text file: 123,1
A = "" nr=INPUT(ch, 1, 1, A)causes weird issues, while
A =0 nr=INPUT(ch, 1, 1, A)works.
You can convert strings to numbers with the split command.