Source language: Translate to:

Potential BUG - "StrParse" function & external file writing

Questions or information that don't quite fit anywhere else

Moderator: Neosoft Support

Potential BUG - "StrParse" function & external file writing

Postby netmediasurfer » Sun Aug 24, 2014 6:45 am

There appears to be a bug with the "StrParse" function & external file writing



Example


Suppose I have a .txt file with a single data string.


A text file contains the following on line 1 ...


book1.pdfbook2.pdfbook3.pdfbook4.pdf.book5.pdf



Now the objective is to split the data string by using the extension .pdf as the delimiter and write it back into the the LIST.txt neatly ( One per line, instead of a single string )




CODE


FileToVar "![PubDir]\BOOKLIST\LIST.txt" "[RAW_DATA]"

StrParse "[RAW_DATA]" ".pdf" "[list_array]" "[parsed_count]"

FileWrite "![PubDir]\BOOKLIST\LIST.txt" "1" "[list_array]"


It yields a list as intended but the first entry is not included in the generated list within "LIST.txt".


Instead of ..

BOOK1.PDF
BOOK2.PDF
BOOK3.PDF
BOOK4.PDF
BOOK5.PDF

It yields this instead ....

BOOK2.PDF
BOOK3.PDF
BOOK4.PDF
BOOK5.PDF


The workaround for me was to use the following code to ensure all the data that was split into arrays is written to the "LIST.txt" file


WORKS

FileWrite "![PubDir]\BOOKLIST\LIST.txt" "1" "[list_array1].pls"



NOT FULLY FUNCTIONAL


Isn't it suppose to include all the data that was split into arrays with the following code ?


THIS WORKS BUT FAILES TO WRITE THE FIRST ARRAY DATA CONTENT TO "LIST.TXT"


FileWrite "![PubDir]\BOOKLIST\LIST.txt" "1" "[list_array]" ( POTENTIAL BUG )


or


THIS ONE ONLY YIELDS THE FIRST ARRAY DATA WHICH IS STRANGE SINCE IT'S USING "ALL"AS PART OF THE PARAMETER


FileWrite "![PubDir]\BOOKLIST\LIST.txt" "All" "[list_array]" ( POTENTIAL BUG )



THIS WOULD NOT WORK EITHER USING MY WORKAROUND WITH THE "ALL" PARAMETER.


FileWrite "![PubDir]\BOOKLIST\LIST.txt" "All" "[list_array1].pls" ( POTENTIAL BUG )




Thanks
netmediasurfer
 
Posts: 18
Joined: Thu Aug 21, 2014 4:21 am

Re: Potential BUG - "StrParse" function & external file writ

Postby Gaev » Sun Aug 24, 2014 7:54 am

netmediasurfer:

A text file contains the following on line 1 ...
book1.pdfbook2.pdfbook3.pdfbook4.pdf.book5.pdf

1) if you use
Code: Select all
FileToVar "![PubDir]\BOOKLIST\LIST.txt" "[RAW_DATA]"

... make sure that LIST.txt ONLY CONTAINS 1 line ... otherwise use FielRead with a specified Line Number to be read.

2) Your understanding of the behaviour of StrParse is wrong ... from the Help file ...
StrParse "[Files]" ";" "[Names]" "[Count]"

When executed, an array based on the [Names] variable ([Names1], [Names2], etc.) will be created.

... so, with the command ...
Code: Select all
StrParse "[RAW_DATA]" ".pdf" "[list_array]" "[parsed_count]"

... you end up with a number of variables like ...
Code: Select all
[list_array1] = "book1"
[list_array2] = "book2"
[list_array3] = "book3"
[list_array4] = "book4"
[list_array5] = "book5"

... after the first 3 commands are serviced, view the variables (and their values) in your Debugger.

3) So, when you follow it up with ...
Code: Select all
FileWrite "![PubDir]\BOOKLIST\LIST.txt" "1" "[list_array]"

... what you write is the value associated with the (simple) variable called [list_array] ... NOT each of the (simple) variables whose names begin with list_array.


If you want to end up with a list like ...

BOOK1.PDF
BOOK2.PDF
BOOK3.PDF
BOOK4.PDF
BOOK5.PDF

... try this ...
Code: Select all
FileRead "![PubDir]\BOOKLIST\LIST.txt" "1" "[RAW_DATA]"
StrReplace "[RAW_DATA]" ".pdf" ".pdf[#13][#10]" "[New_Data]" ""
FileWrite "![PubDir]\BOOKLIST\LIST.txt" "1" "![New_Data]"
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Potential BUG - "StrParse" function & external file writ

Postby netmediasurfer » Sun Aug 24, 2014 8:59 am

I understand StrParse just fine. : )

The array is created without problem within NeoBook. That is not my issue, the problem is when attempting to file write all the array data to "LIST.txt" it skips over the first array value & leaves that space blank within the "LIST.txt" file.

This is why I said it was a potential bug not a confirmed bug. I'm assuming the issue is caused by the resulting array not being processed properly by the File Write function when attempting to export the data to "LIST.txt"


Yes, I get ... ( I'm working with playlists .. this is just an example )

[list_array1] = "book1"
[list_array2] = "book2"
[list_array3] = "book3"
[list_array4] = "book4"
[list_array5] = "book5"


Problem ....


Exporting all data within the arrays to the "LIST.txt" file starting from [list_array_1]



The code you provided is the same code I had and it doesn't work properly. It skips exporting the data held within [list_array_1] but exports all the other array data without a problem.



FileWrite "![PubDir]\BOOKLIST\LIST.txt" "1" "[list_array]"



Yields

[list_array2] = "book2"
[list_array3] = "book3"
[list_array4] = "book4"
[list_array5] = "book5"



Instead of


[list_array1] = "book1"
[list_array2] = "book2"
[list_array3] = "book3"
[list_array4] = "book4"
[list_array5] = "book5"



I can only get it to work like this ...


FileWrite "![PubDir]\BOOKLIST\LIST.txt" "1" "[list_array1].pdf"


--


"Make sure that LIST.txt ONLY CONTAINS 1 line ... otherwise use FielRead with a specified Line

Number to be read."



Yes, it's all in one line. I import into NeoBook using StrParse function to generate the arrays. The array creation works fine, exporting to the "LIST.txt" is the issue as stated above.



I'll look into the last code provided when I get a chance.


Thanks!
netmediasurfer
 
Posts: 18
Joined: Thu Aug 21, 2014 4:21 am

Re: Potential BUG - "StrParse" function & external file writ

Postby Gaev » Sun Aug 24, 2014 9:47 am

netmediasurfer:

I understand StrParse just fine. : )
... with all due respect, you don't ... if you did, you would not expect any values in the (simple) variable called [list_array] ... and hence you would not expect ...
Code: Select all
FileWrite "![PubDir]\BOOKLIST\LIST.txt" "1" "[list_array]"
... to write out the contents of ...

[list_array1]
[list_array2]
[list_array3]
[list_array4]
[list_array5]

... to the file.

When you specify [list_array] in the (third parameter of the) StrParse command, think of it as a "mask/template" to be used to create other variables ... whose names begin with [list_array ... and have suffixes of 1], 2], 3], 4] etc.

The code you provided is the same code I had and it doesn't work properly. It skips exporting the data held within [list_array_1] but exports all the other array data without a problem.

... no it is not ... the code I provided DOES NOT USE StrParse at all ... bacause what you need to do DOES NOT REQUIRE the use of this command.
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Potential BUG - "StrParse" function & external file writ

Postby netmediasurfer » Sun Aug 24, 2014 7:08 pm

Hi, first I want to thank you for taking the time to help me out. I know you are highly experienced and are much more familiar with programming ect.. Greatly appreciate your guidance.

You stated that is wrong for me to expect [list_array] to output the values of simple variables but it does work for all arrays with the exception of the first.

Just for clarification, what allows ...

FileWrite "![PubDir]\BOOKLIST\LIST.txt" "1" "[list_array]"

to write out all array content to LIST.txt with the exception of the first array value ?


This is what is throwing me off & why I thought it was a bug.



I mis read your previous post, I thought the highlighted codes were codes you wanted me to try. I noticed you were just commenting on the codes I was using. Realized it's the last code you suggested.


I need some sleep. : )

I'll try out & see how it goes.



Thank you!
netmediasurfer
 
Posts: 18
Joined: Thu Aug 21, 2014 4:21 am

Re: Potential BUG - "StrParse" function & external file writ

Postby Gaev » Mon Aug 25, 2014 5:24 am

netmediasurfer:
You stated that is wrong for me to expect [list_array] to output the values of simple variables but it does work for all arrays with the exception of the first.

You are drawing the wrong conclusion from your observations ... try this code ...
Code: Select all
SetVar "[ArrayedItem]" "blah blah"
SetVar "[DelimitedText]" "a,b,c,d,e,f"
StrParse "[DelimitedText]" "," "[ArrayedItem]" "[ArrayedItemCount]"
AlertBox "ArrayedItem" "[ArrayedItem]"
FileWrite "![PubDir]temp.txt" "1" "[ArrayedItem]"
Run "![PubDir]temp.txt" "" "Normal" "" ""

You will observe that ...

a) [ArrayedItem] has a value of "blah blah" ... not "b,c,d,e,f"

b) if you remove the first line of code, [ArrayedItem] has a value of "" (null)

Just for clarification, what allows ...

FileWrite "![PubDir]\BOOKLIST\LIST.txt" "1" "[list_array]"

to write out all array content to LIST.txt with the exception of the first array value ?

I believe that the value in [list_array] is from some previous code that was serviced (before the StrParse command) ... do a ...
Code: Select all
SetVar "[list_array]" ""
... before the StrParse command ... and then see what the value of this variable is after the StrParse command.

I have not seen anything in the Help file that tells you what value to expect for the (simple) variable (mask/template) that you specify in the StrParse command.
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Potential BUG - "StrParse" function & external file writ

Postby dpayer » Mon Aug 25, 2014 11:47 am

netmediasurfer wrote:There appears to be a bug with the "StrParse" function & external file writing

StrParse "[RAW_DATA]" ".pdf" "[list_array]" "[parsed_count]"

FileWrite "![PubDir]\BOOKLIST\LIST.txt" "1" "[list_array]"



First I will tell you that I learned something new here.

I never knew that you could write out all the data in a variable array with one statement. I always though a longer (and bothersome) system was needed:
Code: Select all
SetVar {NewVar]" ""
Loop "1" "[parsed_count]" "WILL"
SetVar "[NewVar]" "[NewVar][list_array[WILL]]"
Endloop
FileWrite "![PubDir]\BOOKLIST\LIST.txt" "ALL" "[NewVar]"

Having said that, I believe this method would enumerate the missing variable for you.

David P.
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1380
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: Potential BUG - "StrParse" function & external file writ

Postby netmediasurfer » Tue Aug 26, 2014 7:08 am

Hi, got it working with ...

FileRead "![PubDir]\BOOKLIST\LIST.txt" "1" "[RAW_DATA]"
StrReplace "[RAW_DATA]" ".pdf" ".pdf[#13][#10]" "[EDITED_DATA]" ""
FileWrite "![PubDir]\BOOKLIST\LIST.txt" "All" "![EDITED_DATA]"


Now I just need to find the other post about capturing the titles & renaming files. :)

Thanks!
netmediasurfer
 
Posts: 18
Joined: Thu Aug 21, 2014 4:21 am

Re: Potential BUG - "StrParse" function & external file writ

Postby netmediasurfer » Thu Aug 28, 2014 2:20 pm

To export the array values in one line of code you actually need to be careful with the brackets because if you miss one it will just yield a blank document & no error alerts will occur. It works for exporting all array values with the exception of the first so you need to use the workaround stated in previous post.

I learned this via trial and error : )


Be careful with this line ...


INCORRECT

FileWrite "![PubDir]OUTPUT.txt" "Append" "[array[loop_position]" <-- Missing an extra bracket at the end.


CORRECT

FileWrite "![PubDir]OUTPUT.txt" "Append" "[array[loop_position]]"




Example Use

FileToVar "![PubDir]TEST.pdf" "[RAW_DATA]"

StrParse "[RAW_DATA]" "=" "[array]" "[count]"

Loop "1" "[count]" "[loop_position]"

FileWrite "![PubDir]OUTPUT.txt" "Append" "[array[loop_position]]"

EndLoop
netmediasurfer
 
Posts: 18
Joined: Thu Aug 21, 2014 4:21 am


Return to Misc. Questions and Information

Who is online

Users browsing this forum: No registered users and 1 guest

cron