BleepingComputer.com: For next loop involving items?

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

For next loop involving items?

#1 User is offline   Wolfy87 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 414
  • Joined: 25-July 08
  • Gender:Male
  • Location:England

Posted 29 March 2009 - 10:00 AM

i have 30 text boxes named N1 - N30, i have a streamwriter that writes all of theese to an individual line, i want a for next loop within that to write all of the textboxes text to the file, here is my code:

		FolderBrowserDialog1.ShowDialog()
		slocation = FolderBrowserDialog1.SelectedPath
		Dim sw As New StreamWriter((slocation + "/data.dat"))
		For i As Integer = 1 To 30
			selectedb = ("N" + i)
			sw.WriteLine(selectedb.Text)
		Next
		sw.Close()


Clearly this is not going to work but i dont know any other way =S

Thanks, Wolfy87.

#2 User is offline   Wolfy87 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 414
  • Joined: 25-July 08
  • Gender:Male
  • Location:England

Posted 29 March 2009 - 10:12 AM

Ok dont worry i just wrote it all out seperatly, i think i would of had to do that anyway but still, thanks.

Wolfy87.

#3 User is offline   Billy O'Neal 

  • Bleepin Engineer GRADUATE
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Malware Response Instructor
  • Posts: 10,403
  • Joined: 17-January 08
  • Gender:Male
  • Location:Cleveland, Ohio

Posted 29 March 2009 - 10:22 AM

Probably a good time to mention you should probably use a SaveFileDialog instead of a folder browser dialog here...

Billy3

#4 User is offline   groovicus 

  • Hail Groovicus!
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Moderator
  • Posts: 9,605
  • Joined: 05-June 04
  • Gender:Male
  • Location:Centerville, SD

Posted 29 March 2009 - 10:25 AM

Quote

Clearly this is not going to work but i dont know any other way =S


You are going to have to access each one of them individually, because as you discovered, you can not dynamically create a string representing a variable name (at least not without using a dynamic language. Javascript can do it). And before you complain about how long it is going to take to code all of that, think about your poor user that has to try and fill in those 30 pieces of information. Poor design.

Another problem with your scheme is that your variable names do not reflect the information that they are holding. While you may know now what d25 represents, in two months you will have forgotten. If D1 represents a user's name, it should have the name, 'name'. If it is the users age, then it should be named 'age'. Do yourself a favor and read the following PDF:
http://www.objectmentor.com/resources/articles/Naming.pdf
"Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way" - Christopher Hitchens

#5 User is offline   Wolfy87 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 414
  • Joined: 25-July 08
  • Gender:Male
  • Location:England

Posted 29 March 2009 - 10:30 AM

Thanks billy but it will save about 5 different files so i need it so you just choose a directory instead of five different saves, and groovicus i have it sorted now so im not complaining about the time it would take and naming them like this is fine by me because i know what they are and where they are, this way of naming them makes it easyer for me.

Thanks, Wolfy87.

#6 User is offline   groovicus 

  • Hail Groovicus!
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Moderator
  • Posts: 9,605
  • Joined: 05-June 04
  • Gender:Male
  • Location:Centerville, SD

Posted 29 March 2009 - 11:33 AM

Quote

this way of naming them makes it easyer for me.

Of course. Doing things the right way is sometime a bit harder initially. I understand that you know what they mean now, but in two or three months when you go back to refactor your code, you won't remember. Or you are going to have a problem with your code, and when you ask for help, you are going to have a bunch of code with meaningless names that nobody will want to help fix.

If you want to be employed as a programmer, then take the time to learn to do it right. There are enough crappy web pages and applications that look like they were designed by 15 year olds; the world certainly does not need more. That means taking the time to learn how to do things right.
"Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way" - Christopher Hitchens

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users