Click here to Skip to main content
16,006,605 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: i need to show the result in COmmand prompt...but i am using Windows Application please help me Pin
Christian Graus12-Feb-07 23:49
protectorChristian Graus12-Feb-07 23:49 
QuestionWrit Text File Pin
nawalage12-Feb-07 18:35
nawalage12-Feb-07 18:35 
AnswerRe: Writ Text File Pin
Christian Graus12-Feb-07 18:57
protectorChristian Graus12-Feb-07 18:57 
GeneralRe: Writ Text File Pin
nawalage12-Feb-07 19:37
nawalage12-Feb-07 19:37 
GeneralRe: Writ Text File Pin
Christian Graus12-Feb-07 19:46
protectorChristian Graus12-Feb-07 19:46 
AnswerRe: Writ Text File Pin
M-Hall12-Feb-07 19:30
M-Hall12-Feb-07 19:30 
GeneralRe: Writ Text File Pin
nawalage12-Feb-07 19:59
nawalage12-Feb-07 19:59 
AnswerRe: Writ Text File Pin
Guffa12-Feb-07 21:14
Guffa12-Feb-07 21:14 
I don't think that you have really gotten into the object oriented way of thinking... Let's look at your code.

First you create a file:

IO.File.Create("C:\test.txt")

The Create method returns a FileStream object, but you don't take care of the return value, so you have a open file with no means of writing to it or closing it.

Then you try to open the same file again:

IO.File.OpenWrite("C:\test.txt")

This of course fails, as the file is already open. Even if it did not fail, the OpenWrite method also returns a FileStream object that you just throw away.

Then you try to write to the file:

For X = 1 To 20<br />
IO.File.AppendAllText("C:\test.txt", "myname")<br />
Next


Even if this would work if the file wasn't already open, this is a very inefficient way of writing to a file. Each iteration in the loop would open the file, write a string to it, then close it.

For writing a text file, you should rather use a StreamWriter than a FileStream.

Dim file As StreamWriter<br />
Dim x as Integer<br />
file = IO.File.CreateText("c:\test.txt")<br />
For x = 1 to 20<br />
   file.Write("myname")<br />
Next<br />
file.Close()



---
single minded; short sighted; long gone;

QuestionCreate table Pin
Socheat.Net12-Feb-07 17:48
Socheat.Net12-Feb-07 17:48 
AnswerRe: Create table Pin
Christian Graus12-Feb-07 19:01
protectorChristian Graus12-Feb-07 19:01 
AnswerRe: Create table Pin
ChandraRam12-Feb-07 20:50
ChandraRam12-Feb-07 20:50 
AnswerRe: Create table Pin
Hamid_RT13-Feb-07 8:14
Hamid_RT13-Feb-07 8:14 
QuestionHow to Display only Year in DateTimepicker or comboBox? Pin
priya_p23312-Feb-07 16:49
priya_p23312-Feb-07 16:49 
AnswerRe: How to Display only Year in DateTimepicker or comboBox? [modified] Pin
M-Hall12-Feb-07 18:02
M-Hall12-Feb-07 18:02 
QuestionRe: How to Display only Year in DateTimepicker or comboBox? Pin
priya_p23312-Feb-07 18:37
priya_p23312-Feb-07 18:37 
AnswerRe: How to Display only Year in DateTimepicker or comboBox? Pin
M-Hall12-Feb-07 19:15
M-Hall12-Feb-07 19:15 
AnswerRe: How to Display only Year in DateTimepicker or comboBox? Pin
ajay5888612-Feb-07 19:38
ajay5888612-Feb-07 19:38 
QuestionConversion from string &quot;System.Data.DataRowView&quot; to type 'Integer' is not valid ? Pin
cheeken2u12-Feb-07 16:32
cheeken2u12-Feb-07 16:32 
AnswerRe: Conversion from string &quot;System.Data.DataRowView&quot; to type 'Integer' is not valid ? Pin
M-Hall12-Feb-07 18:30
M-Hall12-Feb-07 18:30 
GeneralRe: Conversion from string &amp;quot;System.Data.DataRowView&amp;quot; to type 'Integer' is not valid ? Pin
cheeken2u12-Feb-07 19:38
cheeken2u12-Feb-07 19:38 
GeneralRe: Conversion from string &amp;quot;System.Data.DataRowView&amp;quot; to type 'Integer' is not valid ? Pin
M-Hall12-Feb-07 19:50
M-Hall12-Feb-07 19:50 
QuestionExcel Question Pin
ghettoneck12-Feb-07 16:07
ghettoneck12-Feb-07 16:07 
QuestionFile Association..pls help Pin
carl_sti12-Feb-07 14:59
carl_sti12-Feb-07 14:59 
AnswerRe: File Association..pls help Pin
TwoFaced12-Feb-07 15:53
TwoFaced12-Feb-07 15:53 
GeneralRe: File Association..pls help Pin
carl_sti12-Feb-07 16:26
carl_sti12-Feb-07 16:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.