MACkie Posted December 31, 2009 at 01:37 PM Report Share #303424 Posted December 31, 2009 at 01:37 PM Boas pessoal! Eu sei que é passagem de ano, mas... Espero que alguém em ajude antes que eu mande tudo para o caixote do lixo e comece outra vez! Estou a fazer uma pequena aplicação em C# para gerar dados para, posteriormente, inserir numa base de dados. E o gerador está "configurado" para dar os dados tal e qual como são para serem inseridos. Até aqui tudo bem. O problema reside em que o ciclo que usa o gerador tira uma linha A e o resto B, ou seja, uma diferente e o resto tudo igual. Às vezes vem tudo igual, outras vêm 3 de um tipo e 7 de outro... Deixo aqui o código para se alguém me conseguir ajudar! Cumps, MACkie private void button1_Click(object sender, EventArgs e) { StreamWriter str = new StreamWriter("C:\\TEST.TXT"); string[] student = new string[18]; for (int i = 0; i < 10; i++) { generateData gen = new generateData(); student = gen.generateStudentEntry(); string line = ""; for (int a = 0; a < student.Length; a++) { student[0] = (i + 1000).ToString(); student[1] = "filepictures\\fileuser" + student[0].ToString(); line += student[a].ToString() + ", "; if (a.Equals(student.Length - 1)) { line += "/r/n"; } } str.WriteLine(line); } str.Close(); } private void doNotDisturb(string motive)if(motive.compareTo(somethingReallyImportant) == 0)pay attention;else//do nothing Link to comment Share on other sites More sharing options...
M6 Posted January 11, 2010 at 10:12 AM Report Share #305398 Posted January 11, 2010 at 10:12 AM Pelo que percebi, o teu problema está no método generateStudentEntry() que está a retornar demasiadas linhas iguais. 10 REM Generation 48K! 20 INPUT "URL:", A$ 30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50 40 PRINT "404 Not Found" 50 PRINT "./M6 @ Portugal a Programar." Link to comment Share on other sites More sharing options...
MACkie Posted January 11, 2010 at 10:45 AM Author Report Share #305407 Posted January 11, 2010 at 10:45 AM Não não... O problema prende-se com a optimização da biblioteca Random... Se colocar o objecto Random como static e fora de qualquer método - ou seja, variável global - ele já funciona devidamente. Tudo o resto estava operacional. private void doNotDisturb(string motive)if(motive.compareTo(somethingReallyImportant) == 0)pay attention;else//do nothing Link to comment Share on other sites More sharing options...
M6 Posted January 11, 2010 at 11:31 AM Report Share #305411 Posted January 11, 2010 at 11:31 AM Pronto, tens ai a explicação, necessitas de manter o estado ao longo das várias execuções. 10 REM Generation 48K! 20 INPUT "URL:", A$ 30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50 40 PRINT "404 Not Found" 50 PRINT "./M6 @ Portugal a Programar." 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