Paradox Posted January 12, 2006 Share Posted January 12, 2006 Hey guys, it's been a while... Anyways, here's the issue: I need to read lines from two files into an array to do a file comparison. Here's a sample of my full code so far: expandcollapse popup#cs Database syncronization v0.1 1/12/06 #CE #include <file.au3> ; declaration of variables global $dbstart, $dbstop, $confirm, $file2compress, $simLocal, $simRemote, $aSim, $aSimRemote, $minidisk, $last, $minidiskRemote $dbstart="net start ""docubase service""" $dbstop="net stop ""docubase service""" $confirm="copydone.txt" $file2compress="filelist.txt" $simLocal="insuranc.sim" $simRemote="\\jfritzsche\DbBases\insuranc.sim" $last="last.txt" ; 1. Shut down services runwait($dbstop) ; 2. compare .SIM files dim $aSim dim $aSimRemote dim $minidisk dim $minidiskRemote for $x= 1 to $aSim[_fileCountLines($sim)] $minidisk[$x]=_filereadtoarray($sim, $aSim[$x]) next for $y= 1 to $aSimRemote[_fileCountLines($simRemote)] $minidiskRemote[$y]=_filereadtoarray($simRemote, $aSimRemote[$y]) next However, when I run it, I get an error dealing with the array saying that "Subscript used with non-array variable" pointing to the "for $x= 1 to $aSim[_fileCountLines($sim)]" line. To be quite honest with you, I'm reading the documentation as I'm working on writing this program, but am having a hard time understanding how to work with an array. If someone could help me out with this, I would greatly appreciate it! Thanks! Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 12, 2006 Moderators Share Posted January 12, 2006 You didn't declare $aSim for it to be know it was an array.. ie: $aSim[4] or whatever... I'm a bit confused though... because $aSim doesn't contain a value... could you break up your For loop on what you were expecting to happen? I'll see if I can give a hand after that. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Paradox Posted January 12, 2006 Author Share Posted January 12, 2006 You didn't declare $aSim for it to be know it was an array.. ie: $aSim[4] or whatever... I'm a bit confused though... because $aSim doesn't contain a value... could you break up your For loop on what you were expecting to happen? I'll see if I can give a hand after that. I was just going to clarify on what it is that's suppose to happen. sorry for the confustion. Basically: I need to compare the same file on 2 different computers. "insuranc.sim". What I'm trying to do is compare how many lines are in the two seperate files. I also need to read in all the lines, in BOTH of the files (which are just file paths to specific files), into two seperate arrays. I don't know how long each of these arrays are, so when I'm declaring it (which I still have NO IDEA how to do) I can't put any kind of an array limitation. My latest attempt looks something like this: $simLocal="insuranc.sim" $simRemote="\\jfritzsche\DbBases\insuranc.sim" $file1=_filecountlines($simLocal) $file2=_filecountlines($simRemote) dim $aSim(_filecountlines($simLocal)) dim $aSimRemote(_filecountlines($simRemote)) Make more sense now as far as what I'm trying to do? Link to comment Share on other sites More sharing options...
seandisanti Posted January 12, 2006 Share Posted January 12, 2006 You didn't declare $aSim for it to be know it was an array.. ie: $aSim[4] or whatever... I'm a bit confused though... because $aSim doesn't contain a value... could you break up your For loop on what you were expecting to happen? I'll see if I can give a hand after that.Come on man. you're better than that! maybe you should start sleeping at night... When you declare a variable that you want to be an array, if you don't know the expected number of elements, don't declare it as an array, he did that right. Here's are the issues... #cs Database syncronization v0.1 1/12/06 #CE #include <file.au3> ; declaration of variables global $dbstart, $dbstop, $confirm, $file2compress, $simLocal, $simRemote, $aSim, $aSimRemote, $minidisk, $last, $minidiskRemote $dbstart="net start ""docubase service""" $dbstop="net stop ""docubase service""" $confirm="copydone.txt" $file2compress="filelist.txt" $simLocal="insuranc.sim" $simRemote="\\jfritzsche\DbBases\insuranc.sim" $last="last.txt" ; 1. Shut down services runwait($dbstop) ; 2. compare .SIM files dim $aSim dim $aSimRemote dim $minidisk dim $minidiskRemote for $x= 1 to $aSim[_fileCountLines($sim)];this wasn't declared or assigned anywhere else $minidisk[$x]=_filereadtoarray($sim, $aSim[$x]);that one either next for $y= 1 to $aSimRemote[_fileCountLines($simRemote)];this one was declared, but never assigned any value, so no array to have a subscript... $minidiskRemote[$y]=_filereadtoarray($simRemote, $aSimRemote[$y]) next However, when I run it, I get an error dealing with the array saying that "Subscript used with non-array variable" pointing to the "for $x= 1 to $aSim[_fileCountLines($sim)]" line. To be quite honest with you, I'm reading the documentation as I'm working on writing this program, but am having a hard time understanding how to work with an array. If someone could help me out with this, I would greatly appreciate it! Thanks! Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 12, 2006 Moderators Share Posted January 12, 2006 (edited) Come on man. you're better than that! maybe you should start sleeping at night... When you declare a variable that you want to be an array, if you don't know the expected number of elements, don't declare it as an array, he did that right. Here's are the issues... Even when the variable doesn't have a value that you are calling to the array? errr... I'm tired but... Edit: I mean in essence what your saying if I understand the critique is that: Dim $value For $i = 1 To $value[10] MsgBox(0, "Test", $value[$i]) Next Would return a result?... that's the error I was pointing out. Edited January 12, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Paradox Posted January 12, 2006 Author Share Posted January 12, 2006 Come on man. you're better than that! maybe you should start sleeping at night... When you declare a variable that you want to be an array, if you don't know the expected number of elements, don't declare it as an array, he did that right. Here's are the issues...Okay, I'm still lost... Link to comment Share on other sites More sharing options...
seandisanti Posted January 12, 2006 Share Posted January 12, 2006 Even when the variable doesn't have a value that you are calling to the array? errr... I'm tired but... Edit: I mean in essence what your saying if I understand the critique is that: Dim $value For $i = 1 To $value[10] MsgBox(0, "Test", $value[$i]) Next Would return a result?... that's the error I was pointing out.no no no. that wouldn't work because like the OP, you're using the variable before giving it a value (or an array). I meant that your example of: You didn't declare $aSim for it to be know it was an array.. ie: $aSim[4]or whatever...was inaccurate, because he would be correct in doing something like this: dim $avar _FileReadToArray("C:\test.txt",$avar) but the real problem was that he's using variables that he's not yet assigned any value (or array) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 12, 2006 Moderators Share Posted January 12, 2006 See if you understand this a bit, and see if this is the direction you are wanting to go... As Sean says, I should just go to bed!!, but I'm going to take his advice and wait till this evening ; declaration of variables global $dbstart, $dbstop, $confirm, $file2compress, $simLocal, $simRemote, $aSim, $aSimRemote, $minidisk, $last, $minidiskRemote $dbstart="net start ""docubase service""" $dbstop="net stop ""docubase service""" $confirm="copydone.txt" $file2compress="filelist.txt" $simLocal="insuranc.sim" $simRemote="\\jfritzsche\DbBases\insuranc.sim" $last="last.txt" ; 1. Shut down services runwait($dbstop) ; 2. compare .SIM files dim $aSim dim $aSimRemote dim $minidisk dim $minidiskRemote _FileReadToArray($sim, $aSim) _FileReadToArray($simRemote, $aSimRemote) For $x = 1 To UBound($aSim) - 1 If 'Something From File 1 on this Line: ' $aSim[$x] = 'Something From File 2 on the Same Line' $aSimRemote[$x] Then ;Do Something EndIf Next Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
seandisanti Posted January 12, 2006 Share Posted January 12, 2006 As Sean says, I should just go to bed!!, but I'm going to take his advice and wait till this evening there we go. put it on me. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 12, 2006 Moderators Share Posted January 12, 2006 there we go. put it on me. LOL... I tried to explain the Dim $var[4] << needing to contain an array.. but forgot to say it that way... So... Before I show my true colors... I think I'll sit back and watch Jessica Simpson on the Dukes of Hazards. I'll check back in a bit to see if you had any questions or if something along those lines is what you were looking for Paradox. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
seandisanti Posted January 12, 2006 Share Posted January 12, 2006 I think I'll sit back and watch Jessica Simpson on the Dukes of Hazards.$first = "Jessica Simpson" $second= " on the " $third = "Dukes of Hazards" $correct = $first & StringReplace($second,"o","i") & StringLeft($third,StringLen($third)-1) [/jackassery] Link to comment Share on other sites More sharing options...
Paradox Posted January 13, 2006 Author Share Posted January 13, 2006 Okay, I've got the array working, but now here's the issue... What is the maximum amount of elements I can have in a array with 1 dimension? I ask because it's possible that I may have to go through a maximum of 4,096 files... Link to comment Share on other sites More sharing options...
Paradox Posted January 13, 2006 Author Share Posted January 13, 2006 Nevermind... just tried it doing something like dim $minidiskRemote[4096] and it works I am so smart! S M R T Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 13, 2006 Moderators Share Posted January 13, 2006 (edited) Nevermind... just tried it doing something like dim $minidiskRemote[4096] and it works I am so smart! S M R T Forgot your 'A' Edit: Here you go $A = StringSplit('SMART', '') For $I = 1 To UBound($A) - 1 ConsoleWrite($A[$I] & @LF) Next Edited January 13, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Paradox Posted January 13, 2006 Author Share Posted January 13, 2006 I know I did was quoting Homer Simpson Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 13, 2006 Moderators Share Posted January 13, 2006 I know I did was quoting Homer Simpson Doh!Hey... glad you got things working!! Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
seandisanti Posted January 16, 2006 Share Posted January 16, 2006 Nevermind... just tried it doing something like dim $minidiskRemote[4096] and it works I am so smart! S M R T so you know, that would work even if you took off the [4096] depending on how the array is being populated... 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