Sign in to follow this  
Followers 0
myspacee

Insert value in csv file

7 posts in this topic

#1 ·  Posted (edited)

hello,

I've a script that return a value for every day of month.

want to insert this value in right place using csv file:

[chose this format for further import steps]

,uno,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,sun,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,meat,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,fruit,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,flower,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,lion,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

Every ,0, rapresent a day of month, and i want to replace it with new value day by day.

Any idea to do so?

Thank you for suggest me a solution,

m.

Edited by myspacee

Share this post


Link to post
Share on other sites



hello,

I've a script that return a value for every day of month.

want to insert this value in right place using csv file:

,uno,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,sun,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,meat,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,fruit,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,flower,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,lion,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

Every ,0, rapresent a day of month, and i want to replace it with new value day by day.

Any idea to do so?

Thank you for suggest me a solution,

m.

_FileReadToArray() ; Get the contents into an array

_ArraySearch() ; Find the line you want, or just For/Next through all lines in the array

StringSplit() ; split line into a comma delimited array

; Edit the correct element of the split array

_ArrayToString() ; convert split array back into single string

; write new string to file read array

_FileWriteFromArray() ; Write contents back to file

Look each function up in the help file. If you get stuck, post a more specific question.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Thank you for hints, stop in

; Edit the correct element of the split array

can you help me to do next step ?

[replace value]

#include <file.au3>
#Include <Array.au3>

;___________________________________________ _FileReadToArray(); Get the contents into an array
Dim $aRecords
If Not _FileReadToArray("data.csv",$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf


;___________________________________________ _ArraySearch(); Find the line you want, or just For/Next through all lines in the array
$sSearch = InputBox("_ArraySearch() demo", "String to find?", "flower")
If @error Then Exit

$iIndex = _ArraySearch($aRecords, $sSearch, 0, 0, 0, 1)
If @error Then
    MsgBox(0, "Not Found", '"' & $sSearch & '" was not found in the array.')
Else
    MsgBox(0, "Found", '"' & $sSearch & '" was found in the array at position ' & $iIndex & ".")
EndIf

msgbox(0,"Return right record:",$aRecords[$iIndex]);find right value in 2d array



;___________________________________________ StringSplit(); split line into a comma delimited array
$single_value = StringSplit($aRecords[$iIndex], ",")
msgbox(0,"Value in this day", $single_value[@MDAY+2]);skip first 2 values this is 'today' position

thank you all,

m.

Share this post


Link to post
Share on other sites

done by myself ! :)

#include <file.au3>
#Include <Array.au3>

;___________________________________________ _FileReadToArray(); Get the contents into an array
Dim $aRecords
If Not _FileReadToArray("data.csv",$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf


;___________________________________________ _ArraySearch(); Find the line you want, or just For/Next through all lines in the array
$sSearch = InputBox("_ArraySearch() demo", "String to find?", "flower")
If @error Then Exit

$iIndex = _ArraySearch($aRecords, $sSearch, 0, 0, 0, 1)
If @error Then
    MsgBox(0, "Not Found", '"' & $sSearch & '" was not found in the array.')
Else
    MsgBox(0, "Found", '"' & $sSearch & '" was found in the array at position ' & $iIndex & ".")
EndIf

msgbox(0,"Return right record:",$aRecords[$iIndex]);find right value in 2d array



;___________________________________________ StringSplit(); split line into a comma delimited array
$single_value = StringSplit($aRecords[$iIndex], ",")
msgbox(0,"Value in this day", $single_value[@MDAY+2]);skip first 2 values this is 'today' position


;___________________________________________; Edit the correct element of the split array
_ArrayDisplay($single_value, "$avArray BEFORE _ArrayInsert()")
_ArrayDelete($single_value, @MDAY+2);delete
_ArrayInsert($single_value, @MDAY+2, "cassoooooooooooooooooo");add
_ArrayDisplay($single_value, "$avArray AFTER _ArrayInsert()")


;___________________________________________ _FileWriteFromArray(); Write contents back to file
msgbox(0,"", _ArrayToString($single_value, ",",1))
_FileWriteToLine("data.csv", $iIndex, _ArrayToString($single_value, ",",1), 1)

PsaltyDS thank you for kick in my lazy ass !

m.

Share this post


Link to post
Share on other sites

done by myself ! :party:

PsaltyDS thank you for kick in my lazy ass !

Think nothing of it, I learn as much as anyone from this forum. It does give my boots a peculiar shine on the toe...

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

sorry for another question.

I speak about txt file. Now my script can't open file if in 'unicode' any way to convert all txt file in a directory in ANSI,

or open file in a different way if file is in unicode format ?

Thank you,

m.

Share this post


Link to post
Share on other sites

sorry for another question.

I speak about txt file. Now my script can't open file if in 'unicode' any way to convert all txt file in a directory in ANSI,

or open file in a different way if file is in unicode format ?

Thank you,

m.

Use FileOpen() to get a handle to the file with the desired mode. Use the handle in all your file operations (like _FileReadToArray()) instead of the string path.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0