jbennett Posted October 23, 2008 Share Posted October 23, 2008 Hi, I have a quick question... I have an .ini file that has a piece of data that I would look to read but it doesn't seem to be working. I have a feeling that it's due to the delimiters in the data, is there any way of reading this data into the code. [TEST] days=1,2,3,4 I know how to read ini files, just not with delimiters. Thanks Link to comment Share on other sites More sharing options...
dbzfanatic Posted October 23, 2008 Share Posted October 23, 2008 What exactly does it return? IniRead() should return a string so afaik delimiters shouldn't be a problem but if you show some example output as well as the sample ini it might help. Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote] Link to comment Share on other sites More sharing options...
Aceguy Posted October 23, 2008 Share Posted October 23, 2008 1st you $data=iniread(your.ini,"test","days","")oÝ÷ ÚØ^*.jëh×6$split=stringsplit($data,",") for $i = 1 to $split[0] msgbox(0,"","Element "&$i&" is "&$split[$i],2) next [u]My Projects.[/u]Launcher - not just for games & Apps (Mp3's & Network Files)Mp3 File RenamerMy File Backup UtilityFFXI - Realtime to Vana time Clock Link to comment Share on other sites More sharing options...
jbennett Posted October 23, 2008 Author Share Posted October 23, 2008 Hi, Thanks for that. The only problem I have is that it works in a msgbox but not in this code Do you have any ideas why? Note - I have only pasted a little piece of the code here... $scheduled_backup_days = IniRead(@scriptdir & "\Configuration.ini", "SCHEDULE_CONFIG", "scheduled_backup_days","") $read_scheduled_backup_days=stringsplit($scheduled_backup_days,",") for $i = 1 to $read_scheduled_backup_days[0] next Switch @WDAY case $read_scheduled_backup_days Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 23, 2008 Share Posted October 23, 2008 $scheduled_backup_days = IniRead(@scriptdir & "\Configuration.ini", "SCHEDULE_CONFIG", "scheduled_backup_days","") $read_scheduled_backup_days=stringsplit($scheduled_backup_days,",") for $i = 1 to $read_scheduled_backup_days[0] next Switch @WDAY case $read_scheduled_backup_days Why is 'Next' before the content of the loop? Your reference to the array requires an index, like: case $read_scheduled_backup_days[$i] The string split and loop are not required anyway. Just do: If StringInStr($scheduled_backup_days, @WDAY) Then ; ...do something EndIf 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 Link to comment Share on other sites More sharing options...
jbennett Posted October 23, 2008 Author Share Posted October 23, 2008 (edited) hmm now i'm confused. Normally I would have.. Switch @WDAY case 3 which then continues to run some code if it's Tuesday. But I want to be able to define the day(s) in an .ini file. Ofcourse if there is more than 1 day then it doesn't read the .ini as the .ini would then display 2,3 for example. thanks EDIT === The code below works but I can only have one number in the .ini e.g [sCHEDULE_CONFIG] scheduled_backup_days=2 $scheduled_backup_days = IniRead(@scriptdir & "\Configuration.ini", "SCHEDULE_CONFIG", "scheduled_backup_days","") Switch @WDAY case $scheduled_backup_days Edited October 23, 2008 by jbennett Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 23, 2008 Share Posted October 23, 2008 (edited) hmm now i'm confused. Normally I would have.. Switch @WDAY case 3 which then continues to run some code if it's Tuesday. But I want to be able to define the day(s) in an .ini file. Ofcourse if there is more than 1 day then it doesn't read the .ini as the .ini would then display 2,3 for example. thanks I'm not sure where you are getting lost? The following reads the INI: $scheduled_backup_days = IniRead(@scriptdir & "\Configuration.ini", "SCHEDULE_CONFIG", "scheduled_backup_days","") So $scheduled_backup_days now = "1,2,3,4". Then you check if @WDAY is in that list: If StringInStr($scheduled_backup_days, @WDAY) Then ; ...do something EndIf Switch/Case is not required, as far as I can tell. Edited October 23, 2008 by PsaltyDS 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 Link to comment Share on other sites More sharing options...
jbennett Posted October 23, 2008 Author Share Posted October 23, 2008 (edited) I need to keep the switch/case. All i'm struggling with is case 'something' where 'something' is read from the .ini, whether thats 2,3 or just 2 etc thanks EDIT --- the code does work, but only with 1 number in the .ini. (Refer to post #6) Edited October 23, 2008 by jbennett Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 23, 2008 Share Posted October 23, 2008 (edited) I need to keep the switch/case. All i'm struggling with is case 'something' where 'something' is read from the .ini, whether thats 2,3 or just 2 etc thanks EDIT --- the code does work, but only with 1 number in the .ini. (Refer to post #6) Then you can change it from Switch/Case to Select/Case, and use it like this: $scheduled_backup_days = IniRead(@scriptdir & "\Configuration.ini", "SCHEDULE_CONFIG", "scheduled_backup_days","") If StringInStr($scheduled_backup_days, @WDAY) Then Select Case StringInStr($scheduled_backup_days, "1") ; Do something if Sunday is in the list Case StringInStr($scheduled_backup_days, "2") ; Do something if Monday is in the list Case StringInStr($scheduled_backup_days, "3") ; Do something if Tuesday is in the list EndSelect EndIf Note that with either Switch/Case or Select/Case, it will siop processing when it gets a match and not check the rest of the Cases. Is that really what you wanted? Edit: Added check for @WDAY first. Edited October 23, 2008 by PsaltyDS 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 Link to comment Share on other sites More sharing options...
jbennett Posted October 23, 2008 Author Share Posted October 23, 2008 (edited) Note that with either Switch/Case or Select/Case, it will siop processing when it gets a match and not check the rest of the Cases. Is that really what you wanted? Yep I want it to stop processing. The only problem I have is that ideally I wanted to keep the numbers within 1 case. For instance with my code at the moment if I put "Case 1,2,3" then if it's one of these days it will run the code. I didn't want to split up the days Main reason is because I don't want to define the numbers in the code. thanks EDIT ----- Maybe I could try something like Case StringInStr($scheduled_backup_days, "1","2","3","4","5","6","7") run CODE A Case StringInStr($other_days, "1","2","3","4","5","6","7") run CODE B Edited October 23, 2008 by jbennett Link to comment Share on other sites More sharing options...
jbennett Posted October 23, 2008 Author Share Posted October 23, 2008 (edited) I've got a better idea, which is.... $scheduled_backup_days = IniRead(@scriptdir & "\Configuration.ini", _ "SCHEDULE_CONFIG", "scheduled_backup_days","") Switch @WDAY case $scheduled_backup_days RUN CODE A case Else RUN CODE B EndSwitch Then in my .ini I can put in the necessary date any any other dates will just use "case Else" Just a shame I can't put more days in "case $scheduled_backup_days" Edited October 23, 2008 by jbennett Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 23, 2008 Share Posted October 23, 2008 I've got a better idea, which is.... $scheduled_backup_days = IniRead(@scriptdir & "\Configuration.ini", _ "SCHEDULE_CONFIG", "scheduled_backup_days","") Switch @WDAY case $scheduled_backup_days RUN CODE A case Else RUN CODE B EndSwitch Then in my .ini I can put in the necessary date any any other dates will just use "case Else" Just a shame I can't put more days in "case $scheduled_backup_days" Now you are confusing me. I don't think that will work because @WDAY is a single digit and will not compare correctly to "1,2,3,4". Also, I don't see how that, if it did work, would be different from this: $scheduled_backup_days = IniRead(@scriptdir & "\Configuration.ini", _ "SCHEDULE_CONFIG", "scheduled_backup_days","") If StringInStr($scheduled_backup_days, @WDAY) Then RUN CODE A Else RUN CODE B EndIf 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 Link to comment Share on other sites More sharing options...
jbennett Posted October 23, 2008 Author Share Posted October 23, 2008 (edited) It's the same idea as you just posted. Mine works :-) But I can only have 1 day in the .ini file It's not really a requirement to have more than 1 day set as a schedule but just for my personal knowledge it would have been useful to know how to add this to the code so I can specify more than 1 day to run CODE A Basically CODE A is a scheduled backup that the user will specify the day in the .ini file. and CODE B will run the backup on the other days if it has not been run in CODE A (and if reminders are set to YES in the .ini but I don't want to confuse you). It all works perfectly well, just the fact that I can only set 1 day as a schedule day. Not that it really matters but was just interested to know how. thanks EDIT ----- A very easy way of adding more days would be to just put it in the .ini file [sCHEDULE] Schedule1=2 Schedule2=3 Schedule3=4 and then just put case $scheduled1, $schedule2,$schedule3 If I created a GUI for the .ini then it wouldn't be a big deal to me. Just an idea. Edited October 23, 2008 by jbennett Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now