I have been coding a series of functions to open a text file, check for the existence of a whole line (each line has a parameter name and value separated by an = sign eg. GMT_StartTime=00:05). Then show the current value to the user (it reads the file in line by line to find a match of the whole line and parses out the value) and then asks if they want to modify it.
Then it basically allows them to choose the parameter name and asks what to modify the value to.
Then currently the code reads in the text file complete and does a replace of the existing whole line with the new line.
I am updating 32 files currently with the same value. I.e it looks for a whole line that is common to all files and replaces the whole line in all files.
My difficulty is that if the files have different values for the same line in different files it only finds the exact matches. This will be more common when we increment a value in each file.
So question is. Is there a simple way of finding just the parameter name and then updating the value?
I assume that the current way of using replace function would not be easy to modify. Would I need to read in the lines one at a time and somehow “select” the line to operate on and then do a replace on the value.
When I first looked at this I could not see how to “select” a line (say using instr) and read it into a variable for manipulation.
Sample data
BanStopLoss=false
SetStopLossForHedgedTrades=false
CloseAllTradesOnNetProfitTrigger=false
NetProfitTrigger=500.0
AccountHistoryLookBackDays=3
GMT_StartTime=08:00
GMT_EndTime=15:00
LotSize=0.05
Any ideas anyone? Am I making a simple task difficult?
Regards
Neil
Bookmarks