Source language: Translate to:

Control Method - Detection & String Insertion

Questions or information that don't quite fit anywhere else

Moderator: Neosoft Support

Control Method - Detection & String Insertion

Postby netmediasurfer » Tue Sep 02, 2014 5:20 pm

Hi, need some help with a control method.


OBJECTIVE

To input a pre define string into an external file if a specific set of characters are detected immediately after each other. Need it to loop through the entire file.

In this case I want ....

"http://" to trigger an alert if the line immediately after contains "http://" also instead of a radio station title and input a predefined string where the missing data is suppose to be.


This way I can avoid problems exporting odd or even number lines with the wrong data. By inserting a custom string where the missing data is suppose to be I can keep the code for exporting odd and even number lines with the correct data consistent. If not, I would have an exported file containing a mix of station titles and url's when I need each to be placed within their own external file.

Below it starts with a radio station title so every odd number exported should be a radio station title. However, if the station title or url is missing it throws off the entire purpose of exporting odd and even lines to capture the targeted data.


Odd number lines should be reserved for titles only.

Even number lines should be reserved for url's only.


EXAMPLE


Metro Oslo
http://89.105.32.27:80/trondheim128.mp3
Metro Trondheim
http://212.7.199.201:8012/stream
NRG95
http://listen.radionomy.com/PortofinoNetwork
http://94.176.168.66:8048 <---- Throws off the export code. - There should be a radio station title on this line but it's missing.
Radio Cafe Romania <-- Due to missing data this becomes part of the even number line when it's suppose to remain part of the odd number line.
http://176.31.125.205:8010
Radio Vanessa FM
http://37.48.83.45:8050



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

Re: Control Method - Detection & String Insertion

Postby Gaev » Tue Sep 02, 2014 6:48 pm

netmediasurfer:

Try this ...
Code: Select all
SetVar "[myFile]" "![PubDir]RadioStations.txt"

FileLen "[myFile]" "[Lines]"

SetVar "[thisRadioStation]" ""
SetVar "[thisHttp]" ""

Loop "1" "[Lines]" "[thisLineNumber]"

   FileRead "[myFile]" "[thisLineNumber]" "[thisLineText]"
   SearchStr "http://" "[thisLineText]" "[FoundPosition]" ""

   If "[FoundPosition]" "=" "0"
      ... not http; save content
      SetVar "[thisRadioStation]" "[thisLineText]"
   Else
      ... has http
      SetVar "[thisHttp]" "[thisLineText]"
      If "[thisRadioStation]" "=" ""
         ... oops; no radio station line before http
         ... {your actions for this condition go here}
         AlertBox "Error" "Missing Radio Station for [thisHttp]"
      Else
         ... ok; do your thing with [thisRadioStation] and [thisHttp]
         ... {your actions for this condition go here}
         AlertBox "OK" "[thisRadioStation][#13][#10][thisHttp]"
         ... then clear out [thisRadioStation]
         SetVar "[thisRadioStation]" ""
      EndIf
   EndIf
EndLoop
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Control Method - Detection & String Insertion

Postby netmediasurfer » Sat Sep 06, 2014 7:01 pm

Hi, yields "Error 206"


I got it working in reverse order as intended for the most part. Thanks!

By reverse I mean .. URL's come first followed by station titles. Now it's detecting it and associating it correctly.



FileRead "[PubDir]\STATIONS_8.txt" "All" "[MYFILE]"

FileLen "[PubDir]\STATIONS_8.txt" "[NUM_OF_LINES]"

SetVar "[TITLE]" ""

SetVar "[URL]" ""

Loop "1" "[NUM_OF_LINES]" "[LOOP_POSITION]"

FileRead "[PubDir]\STATIONS_8.txt" "[LOOP_POSITION]" "[STATIONS_8_DATA]"


SearchStr "http://" "[STATIONS_8_DATA]" "[DETECTED_POS]" ""



If "[DETECTED_POS]" "=" "1"

... not title; save content

SetVar "[URL]" "[STATIONS_8_DATA]"


Else

... has title

SetVar "[TITLE]" "[STATIONS_8_DATA]"



If "[URL]" "=" ""

... oops; no url line before station title
... {your actions for this condition go here}

AlertBox "Error" "Missing URL for [TITLE]"


Else


... ok; do your thing with [URL] and [TITLE]
... {your actions for this condition go here}

AlertBox "OK" "[URL][#13][#10][TITLE]"

... then clear out [URL]

SetVar "[URL]" ""


EndIf

EndIf

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