Source language: Translate to:

This code keeps looping on one value :-(

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

This code keeps looping on one value :-(

Postby nerdgerl » Wed Apr 06, 2011 7:44 pm

Sometimes, it will skip to a new value, but then loop forever.

So here's my problem. I have a list of people and their stats in a csv file. The program parses each record in the csv and then replaces existing text in a rtf file with parsed data. It works great!

But for some reason, it will parse what it already processed again and again!! What am I doing wrong? I'm working with a 49MB rtf. Is that the problem? Here's my code:

Code: Select all
FileOpenBox "Open Database" "Any File|Data.csv" "[PubDir]" "[Data.File]" ""
If "[Data.File]" ">" ""

     FileLen "[Data.File]" "[File.Length]"

     ...........................................................................

     FileRead "[Data.File]" "1" "[File.Data]"
     SearchStr "LAST NAME" "[File.Data]" "[File.Data.Contents]"
     If "[File.Data.Contents]" ">" "0"
        Setvar "[Counter.Start]" "2"
     Else
        Setvar "[Counter.Start]" "1"
     Endif

     Loop "[Counter.Start]" "[File.Length]" "[Current.Counter]"

       FileRead "[Data.File]" "[Current.Counter]" "[Current.File.Data]"
       StrParse "[Current.File.Data]" "," "[Current.File.Data.Items]" "[Current.File.Data.Item.Total]"
       Setvar "[status]" "Working on [Current.File.Data.Items3] [Current.File.Data.Items4]'s report..."
       ShowObject "Text2" "None" "0"
       ExtractFile "[Embedded]document.rtf" "[PubDir]document.rtf"
       FileRead "[PubDir]document.rtf" "All" "[Cover]"
       Setvar "[status]" "Adding current date to [Current.File.Data.Items3] [Current.File.Data.Items4]'s report..."
       StrReplace "[Cover]" "CurrentMonth" "[Month]" "[Cover1]"
       StrReplace "[Cover1]" "CurrentYear" "[Year]" "[Cover2]"
       Setvar "[status]" "Adding name to [Current.File.Data.Items3] [Current.File.Data.Items4]'s report..."
       StrReplace "[Cover2]" "CurrentName" "[Current.File.Data.Items3] [Current.File.Data.Items4]" "[Cover3]"
       Setvar "[status]" "Adding screen date to [Current.File.Data.Items3] [Current.File.Data.Items4]'s report..."
       DefineVar "[Screening.Date]" "Date" "m/d/yyyy" "Global" "[Current.File.Data.Items2]"
       StrReplace "[Cover3]" "Appointment" "[Screening.Date]" "[Cover4]"
       FileWrite "[PubDir][Current.File.Data.Items3] [Current.File.Data.Items4]'s Report.rtf" "All" "[Cover4]"

       Setvar "[Counter.Start]" "[Counter.Start]+1"
       FileErase "[PubDir]document.rtf"
       Setvar "[Cover]" ""
       Setvar "[Cover1]" ""
       Setvar "[Cover2]" ""
       Setvar "[Cover3]" ""
       Setvar "[Cover4]" ""
       
       Delay "5000"
     EndLoop
     
     HideObject "Group8" "None" "0"
Else
     .Do Nothing
Endif
...........................................................................

Exit "" ""
You know me. You may not know it yet. But you know me.
Think DOS. Think NeoBook. Think iGui.
User avatar
nerdgerl
 
Posts: 33
Joined: Sat Sep 06, 2008 3:13 pm
Location: USA

About the endless loop

Postby carlos torres » Wed Apr 06, 2011 8:06 pm

Dear Nerdgerl

What is the content of the variable "[File.Data]" on the forth line?

May be your problem star there.

regards

carlost
User avatar
carlos torres
 
Posts: 289
Joined: Mon May 02, 2005 8:14 am
Location: Pamplona, Colombia

Re: About the endless loop

Postby nerdgerl » Wed Apr 06, 2011 9:47 pm

carlos torres wrote:Dear Nerdgerl

What is the content of the variable "[File.Data]" on the forth line?

May be your problem star there.

regards

carlost


[File.Data] is the first line of the file opened by FileOpenBox [Data.File]. The program checks [File.Data] to see if it contains column headers or actual data.
You know me. You may not know it yet. But you know me.
Think DOS. Think NeoBook. Think iGui.
User avatar
nerdgerl
 
Posts: 33
Joined: Sat Sep 06, 2008 3:13 pm
Location: USA

Postby nerdgerl » Wed Apr 06, 2011 10:01 pm

I just found the problem. It's in the csv file. Fields are separated by commas, but one field contains commas inside quotes. How do I get Neobook to ignore the commas in the quoted field?
You know me. You may not know it yet. But you know me.
Think DOS. Think NeoBook. Think iGui.
User avatar
nerdgerl
 
Posts: 33
Joined: Sat Sep 06, 2008 3:13 pm
Location: USA

Postby nerdgerl » Wed Apr 06, 2011 10:17 pm

nerdgerl wrote:I just found the problem. It's in the csv file. Fields are separated by commas, but one field contains commas inside quotes. How do I get Neobook to ignore the commas in the quoted field?


Okay, that wasn't the problem. It's still looping. Seems like double per item in the csv. Like, it will loop twice for 1 item, 4 times for the next, 8 for the next and so on an so forth.

Help!! :(
You know me. You may not know it yet. But you know me.
Think DOS. Think NeoBook. Think iGui.
User avatar
nerdgerl
 
Posts: 33
Joined: Sat Sep 06, 2008 3:13 pm
Location: USA

Postby nerdgerl » Wed Apr 06, 2011 10:54 pm

Okay, sorry guys. The problem was the csv file after all. Apparently, there were some line breaks in some of the fields that sent the program all wacky. All is well now! :D
You know me. You may not know it yet. But you know me.
Think DOS. Think NeoBook. Think iGui.
User avatar
nerdgerl
 
Posts: 33
Joined: Sat Sep 06, 2008 3:13 pm
Location: USA

About the endless loop

Postby carlos torres » Fri Apr 08, 2011 7:55 am

Dear nerdgerl

Try to replace the separator symbol with a tab code [#9] instead of using comma [#44]

regards,
carlost
User avatar
carlos torres
 
Posts: 289
Joined: Mon May 02, 2005 8:14 am
Location: Pamplona, Colombia

Re: About the endless loop

Postby nerdgerl » Fri Apr 08, 2011 3:16 pm

carlos torres wrote:Dear nerdgerl

Try to replace the separator symbol with a tab code [#9] instead of using comma [#44]

regards,
carlost


Will do! Thank you :-)
You know me. You may not know it yet. But you know me.
Think DOS. Think NeoBook. Think iGui.
User avatar
nerdgerl
 
Posts: 33
Joined: Sat Sep 06, 2008 3:13 pm
Location: USA


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 2 guests

cron