Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

For next loop involving items?


  • Please log in to reply
5 replies to this topic

#1 Wolfy87

Wolfy87

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:06:25 AM

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.

BC AdBot (Login to Remove)

 


#2 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:06:25 AM

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 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:11:25 PM

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
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#4 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:12:25 AM

Posted 29 March 2009 - 10:25 AM

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

#5 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:06:25 AM

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 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:12:25 AM

Posted 29 March 2009 - 11:33 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users