Hst2txt

Hi I need to extract evry day the trend history in a csv file with a different name so i wrote this function:

Dim name
name = $Date&$Time&".csv"
$hst2txt($date, "00:00:00", 24, 1, name)

the problem is that this function does not work. But if i give name = "blablabla.csv" it works.

Oviously i use a scheduler function to call this script every day.

Sorry for my english. Saimir
  • Hi Saimir.

    The Indusoft Time tag contains the time formatted as HH:MM:SS.
    It is likely that the Date tag also contains the / character.
    I expect the hst2txt() function is failing as Windows file names can not contain any of:
    \ / : * ? " < > |

    If you want the file to be named with date and time you will need to build a suitable string.
    I would recommend something like ...

    name = $Year&$Month&$Day&$Hour&$Minute&$Second&".csv"

    Regards,
    Greg Shearer
  • Thank you for your answer Greg. This morning i tried to do

    name = CStr($Day)&CStr($Month)&CStr(Day)&".csv"

    and it worked fine. I did this becouse I thinked about the problem with special caracter on a file name and I used the $Cstr() function becouse
    the $Day, $Month and $Year system tags sre integer so I think than we have to convert them to string types before.
    Again thank you Greg. Solved

    Best regards
    Saimir Gjika
  • Hi again Saimir.

    To ensure the file name format remains consistent regardless of day and month, you will also need to format the Month and Day strings to be two characters.
    To do this you can use the Format function:

    name = $Format("%04d",$Year)&$Format("%02d",$Month)&$Format("%02d",$Day)&".csv"
    or
    name = CStr($Year)&$Format("%02d",$Month)&$Format("%02d",$Day)&".csv"

    should work.
  • I see that this is an older thread but am having a similar issue.

    I want to send/extract the trend data to a csv every 10 minutes instead of every day. Would that be possible using this same type of function?
  • Hi Philip,

    The function would be the same, but the execution would be in Scheduler for 10 mins instead of a day.

    Use trigger as Clock and under Time column enter 00:10:00 . Under tag column, enter a tag and set it to 1 under expression. Use,above expression for HST2TXT in a script and use Execution trigger as the tag which you just used in the Scheduler. It should generate the .csv every 10 minutes.