|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On October 26 2011 03:08 fabiano wrote: so you need to break a 1x25 table into five 1x5 tables in which each one theres some label (such as "set2 of run 4")?
if thats what you need you should code a CSV parser that identifies if the table has 25 or 60 lines and break it into five 1x5 (for the 25 lines) or fifteen 1x4 (for the 60 lines). Should be very easy to do with java, no idea about VB though.
Im trying to automate teh whole process.. I hit something or open up both the csv and excel file... start it... it seperates it, copy pasta's it all and then I just save and close... I spend like over an hour a day copy and pasting that crap
|
On October 26 2011 03:12 B00ts wrote:Show nested quote +On October 26 2011 03:08 fabiano wrote: so you need to break a 1x25 table into five 1x5 tables in which each one theres some label (such as "set2 of run 4")?
if thats what you need you should code a CSV parser that identifies if the table has 25 or 60 lines and break it into five 1x5 (for the 25 lines) or fifteen 1x4 (for the 60 lines). Should be very easy to do with java, no idea about VB though. Im trying to automate teh whole process.. I hit something or open up both the csv and excel file... start it... it seperates it, copy pasta's it all and then I just save and close... I spend like over an hour a day copy and pasting that crap
Okay, I've made in java something to automate that. Command-line only.
Download
Usage:
on prompt type:
java CSVParser your_input_file.csv your_output_file.csv
notes: - Your prompt must be on the same directory as the CSVParser.class is - It only works on CSV files with only 1 column (heh, lame I know) - Do not use your input file as output file, I'vent tested if shit would happen if you did - Backup your original files before using it - Use at your own risk
REMEMBER TO TRY THIS ON SOME TEST FILES TO MAKE SURE IT IS IN FACT WHAT YOU WANT. ALSO, BACKUP YOUR FILES.
Heres the code, if you are interested: + Show Spoiler + import java.io.*;
public class CSVParser { public static void parse(String inFilename, String outFilename) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(inFilename)); FileWriter writer = new FileWriter(outFilename); int lines = getNumOfLines(inFilename); int iterations = 0; if(lines == 25) { while(reader.ready()) { if(iterations == 5) { iterations = 0; writer.write("\n"); } writer.write(reader.readLine() + "\n"); iterations++; } } else if(lines == 60) { while(reader.ready()) { if(iterations == 4) { iterations = 0; writer.write("\n"); } writer.write(reader.readLine() + "\n"); iterations++; } } writer.flush(); reader.close(); writer.close(); } public static int getNumOfLines(String filename) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(filename)); int lines = 0; while(reader.ready()) { reader.readLine(); lines++; } reader.close(); return lines; } public static void main(String args[]) { try { CSVParser.parse(args[0], args[1]); } catch(IOException e) { e.printStackTrace(); } } }
|
On October 26 2011 03:58 fabiano wrote:Show nested quote +On October 26 2011 03:12 B00ts wrote:On October 26 2011 03:08 fabiano wrote: so you need to break a 1x25 table into five 1x5 tables in which each one theres some label (such as "set2 of run 4")?
if thats what you need you should code a CSV parser that identifies if the table has 25 or 60 lines and break it into five 1x5 (for the 25 lines) or fifteen 1x4 (for the 60 lines). Should be very easy to do with java, no idea about VB though. Im trying to automate teh whole process.. I hit something or open up both the csv and excel file... start it... it seperates it, copy pasta's it all and then I just save and close... I spend like over an hour a day copy and pasting that crap Okay, I've made in java something to automate that. Command-line only. DownloadUsage: on prompt type: java CSVParser your_input_file.csv your_output_file.csv notes: - Your prompt must be on the same directory as the CSVParser.class is - It only works on CSV files with only 1 column (heh, lame I know) - Do not use your input file as output file, I'vent tested if shit would happen if you did - Backup your original files before using it - Use at your own risk REMEMBER TO TRY THIS ON SOME TEST FILES TO MAKE SURE IT IS IN FACT WHAT YOU WANT. ALSO, BACKUP YOUR FILES. Heres the code, if you are interested: + Show Spoiler + import java.io.*;
public class CSVParser { public static void parse(String inFilename, String outFilename) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(inFilename)); FileWriter writer = new FileWriter(outFilename); int lines = getNumOfLines(inFilename); int iterations = 0; if(lines == 25) { while(reader.ready()) { if(iterations == 5) { iterations = 0; writer.write("\n"); } writer.write(reader.readLine() + "\n"); iterations++; } } else if(lines == 60) { while(reader.ready()) { if(iterations == 4) { iterations = 0; writer.write("\n"); } writer.write(reader.readLine() + "\n"); iterations++; } } writer.flush(); reader.close(); writer.close(); } public static int getNumOfLines(String filename) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(filename)); int lines = 0; while(reader.ready()) { reader.readLine(); lines++; } reader.close(); return lines; } public static void main(String args[] { try { CSVParser.parse(args[0], args[1] ; } catch(IOException e) { e.printStackTrace(); } } }
Wow thanks for the work, wasn't expecting that!
The only thing is that the start point for where it will be pasted will vary... all teh pasted lines are in the same spot relative to the first pasted cell... however that pasted cell could be on line 34, 246, etc... and not always on the same column... so just using new line will mess up the rest of the excel...
Is there a way to access individual cells in an excel file and write to that cell... that way I could just edit that code and write to specific cells based off of a start cell number I can either hard code in or enter as an argument.
Does java have such a library?
|
ah.. sorry, I didnt think of that.
Dont know if java has such library. Don't know how to solve that for now, sorry
|
On October 26 2011 04:30 B00ts wrote:Show nested quote +On October 26 2011 03:58 fabiano wrote:On October 26 2011 03:12 B00ts wrote:On October 26 2011 03:08 fabiano wrote: so you need to break a 1x25 table into five 1x5 tables in which each one theres some label (such as "set2 of run 4")?
if thats what you need you should code a CSV parser that identifies if the table has 25 or 60 lines and break it into five 1x5 (for the 25 lines) or fifteen 1x4 (for the 60 lines). Should be very easy to do with java, no idea about VB though. Im trying to automate teh whole process.. I hit something or open up both the csv and excel file... start it... it seperates it, copy pasta's it all and then I just save and close... I spend like over an hour a day copy and pasting that crap Okay, I've made in java something to automate that. Command-line only. DownloadUsage: on prompt type: java CSVParser your_input_file.csv your_output_file.csv notes: - Your prompt must be on the same directory as the CSVParser.class is - It only works on CSV files with only 1 column (heh, lame I know) - Do not use your input file as output file, I'vent tested if shit would happen if you did - Backup your original files before using it - Use at your own risk REMEMBER TO TRY THIS ON SOME TEST FILES TO MAKE SURE IT IS IN FACT WHAT YOU WANT. ALSO, BACKUP YOUR FILES. Heres the code, if you are interested: + Show Spoiler + import java.io.*;
public class CSVParser { public static void parse(String inFilename, String outFilename) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(inFilename)); FileWriter writer = new FileWriter(outFilename); int lines = getNumOfLines(inFilename); int iterations = 0; if(lines == 25) { while(reader.ready()) { if(iterations == 5) { iterations = 0; writer.write("\n"); } writer.write(reader.readLine() + "\n"); iterations++; } } else if(lines == 60) { while(reader.ready()) { if(iterations == 4) { iterations = 0; writer.write("\n"); } writer.write(reader.readLine() + "\n"); iterations++; } } writer.flush(); reader.close(); writer.close(); } public static int getNumOfLines(String filename) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(filename)); int lines = 0; while(reader.ready()) { reader.readLine(); lines++; } reader.close(); return lines; } public static void main(String args[] { try { CSVParser.parse(args[0], args[1] ; } catch(IOException e) { e.printStackTrace(); } } }
Wow thanks for the work, wasn't expecting that! The only thing is that the start point for where it will be pasted will vary... all teh pasted lines are in the same spot relative to the first pasted cell... however that pasted cell could be on line 34, 246, etc... and not always on the same column... so just using new line will mess up the rest of the excel... Is there a way to access individual cells in an excel file and write to that cell... that way I could just edit that code and write to specific cells based off of a start cell number I can either hard code in or enter as an argument. Does java have such a library? like http://poi.apache.org/ for instance? (google java xls first hit :p )
|
I figured some of you might like this quote from my teacher today:
"Using static variables in functions that are called in a multi-threaded application is like playing Russian roulette with a fully loaded gun."
|
On October 26 2011 05:24 Phrost wrote: I figured some of you might like this quote from my teacher today:
"Using static variables in functions that are called in a multi-threaded application is like playing Russian roulette with a fully loaded gun."
Haha yes thats bound for disaster. Not that anyone would do it save novices though
|
the variables don't need to be static, static is only required if your object is used thread-exclusive. If your object is shared between multiple threads, static is totally unnecessary to play "russian roulette". So don't be fooled into thinking "i don't have static, i'm thread safe", because you are not.
|
On October 26 2011 01:37 ArcticVanguard wrote:Could someone help me break down this (small) code please, so I may understand it better? + Show Spoiler +quine = 'quine = %r\r\nprint quine %% quine' print quine % quine I know what the flags do, but I'm having trouble understanding how they relate to print quine % quine. What does the % operator do when performed on two identical strings like that? lol, that's pretty funny piece of code. It was made specifically to confuse beginners. But it's really simple. quine isn't just a string in this case. It's a formatted string. And for such strings % operator works as string formatting operator (link). Say, if you do >>> print "2x2=%i" % 4 You will have '2x2=4' as a result, cause %i was substituted with 4 ('i' stands for integer). In your example there's a %r format used that stands for object representation and is substituted with whatever objects built-in __repr__() function returns. For strings this function returns string itself surrounded by quotation marks and stuff like \n or \t intact. So when you do >>> print quine % quine The %r in quine is replaced with 'quine = %r\r\nprint quine %% quine' and the resulting string that is printed basically looks like quine = 'quine = %r\r\nprint quine %% quine'\r\nprint quine % quine except for the last \r\n combo that turns into new line. Also notice that once formatting is done '%%' is replaced with '%'.
|
Fun random tidbits I learned recently:
In Java (6),
String a = "foo"; String b = "foo" System.out.println(a==b); //prints "true"
Class A{ static void foo(){ System.out.println("foo");} } Class B extends A{ static void foo(){ System.out.println("bar");} } ... public static void main(String[] args){ A var = new B(); var.foo(); //prints "foo" }
Also, for a lot of languages you need to synchronize your threads to be thread safe.
|
On October 26 2011 20:41 BottleAbuser wrote:Fun random tidbits I learned recently: In Java (6), String a = "foo"; String b = "foo" System.out.println(a==b); //prints "true" Class A{ static void foo(){ System.out.println("foo");} } Class B extends A{ static void foo(){ System.out.println("bar");} } ... public static void main(String[] args){ A var = new B(); var.foo(); //prints "foo" } Also, for a lot of languages you need to synchronize your threads to be thread safe.
Yup. The first is because of string interning. In Java, dynamically generated strings (e.g., those created from user input or files) are not interned by default. The second is because static methods are associated with the class rather than objects of that class type. It's a convenience that you can say var.foo() because this sugars to A.foo() where A is the static type of var.
|
Don't call static methods by instance variable, ever. It can deceive you and others in numerous ways. If you want to shorten the call, just use static import.
|
On October 28 2011 03:31 Frigo wrote: Don't call static methods by instance variable, ever. It can deceive you and others in numerous ways. If you want to shorten the call, just use static import.
This is very good advice. I'm surprised Java even allows it, to be honest.
|
Does anyone else find it difficult to remember different frameworks and tool names and how they operate and compare to each other? Recently at work I've been coming across this problem. I'm finding it fairly difficult to keep all of them straight. The only solution I've found so far to remember them by is to try them all out for an extended period of time, but there are simply too many.
|
On October 30 2011 03:43 foom wrote: Does anyone else find it difficult to remember different frameworks and tool names and how they operate and compare to each other? Recently at work I've been coming across this problem. I'm finding it fairly difficult to keep all of them straight. The only solution I've found so far to remember them by is to try them all out for an extended period of time, but there are simply too many. Sort of; I've been having trouble keeping the API's of all the different languages and libraries I use for my coursework straight. It'd be nice if they were all as easily accessible as Java's API, but sadly, this is not the case.
|
hello im new in c++. i was using Convert.ToDouble(blabla) in c# but i dont know how to do this in c++. so how can i convert char '3' to double 3. i need to get values from a char array like "6-8*2+45".
|
On October 30 2011 04:16 Isualin wrote: hello im new in c++. i was using Convert.ToDouble(blabla) in c# but i dont know how to do this in c++. so how can i convert char '3' to double 3. i need to get values from a char array like "6-8*2+45". Well, I would first get the chars to be ints, by something like this: int a = 'a' - 97. Its 97 because that is the unicode representation of the letter 'a', so 'a' as an int should be 0, 'b' should be 1, and so on. Then its trivial to get doubles from those ints, you just cast them as doubles.
NOTE: My above method only works for systems using unicode encoding. If you want it to work on all encodings it should be something like:
int a = 'a' - 'a'; int b = 'b' - 'a';
And so on for however many characters you need. Also, this is only reasonable for single characters. I can't think of a good way to change strings to ints. For instance, the string "bb" might be 11, because 'b' = 1, but then again, 'L' is also 11. "bb" could instead be thought of as 1+1, but thats just 2, and 'c' is 2 as well, so as you can see there really isn't a good way to do this for more than a single character.
|
@Isualin: Simple type cast converts it. + Show Spoiler +char ch = 'A'; int i = ch; double = (double)i;
|
On October 30 2011 04:16 Isualin wrote: hello im new in c++. i was using Convert.ToDouble(blabla) in c# but i dont know how to do this in c++. so how can i convert char '3' to double 3. i need to get values from a char array like "6-8*2+45". use sscanf from stdio.h e: or atof from stdlib.h
On October 30 2011 04:22 LionKiNG wrote:EDIT: Sorry, this should work better: char ch = "A"; int i = ch; double = (double)i; this won't even compile
|
On October 30 2011 04:16 Isualin wrote: hello im new in c++. i was using Convert.ToDouble(blabla) in c# but i dont know how to do this in c++. so how can i convert char '3' to double 3. i need to get values from a char array like "6-8*2+45".
Do you need to sum that char array/string?
|
|
|
|