I'm trying to use stream reader to read a text file in visual basic, but it wont work... The code i'm using is :
Dim sr As IO.StreamReader = _
IO.File.OpenText("GROWTH.TXT")
Dim Occupation As String = ""
Dim YearOne As Integer = 0
Dim YearTwo As Integer = 0
Dim Increase As Integer = 0
Dim fmtStr As String = "{0,-20}{1,-20}{2,-20}{3,-20}"
lstResults.Items.Add(String.Format(fmtStr, "Occupation", "YearOne", "YearTwo", "Increase"))
Do While sr.Peek <> -1
Occupation = sr.ReadLine
YearOne = CDbl(sr.ReadLine)
YearTwo = CDbl(sr.ReadLine)
Is there something wrong here?![]()
+ Reply to Thread
Results 1 to 8 of 8
-
-
Well my knowledge of vb ended before OO programming became the forte but it does appear that you are not providing for 'Increase'.
And how would you run the loop since it does not have any end pointers ? -
I have loop and sr.close at the end, I don't know what to write for increase?
-
Surely if 'increase' is the same type as the other variables, your code becomes
.......
Increase = CDbl(sr.ReadLine)
Loop
etc. -
Your questions would probably be better addressed at a dedicated forum.
But I can well remember when I was dabbling with vb that it often took minutes to write the code and hours to debug it. Often the fault did not lay where you thought it was.
There could even be fault in the text file. Without seeing that and the whole code we can but guess. Like I said, you would best be served at a dedicated forum. -
Sorry, can't help, all I can say is that you brought back a lot of memories from my VB days.
Good luck -
First glance there appears to be a lot of information missing. You dim YearOne as Integer and then later try to make it equal a line that's converted to a CDBL (CDbl function converts an expression to type Double). It is possible that you don't get at least one error from Converting a LINE to a DOUBLE to an INTEGER but without the specifics of the file you are reading its hard to say.
What exactly are you trying to accomplish from what data?
Similar Threads
-
Visual Basic help
By collegegurl in forum ComputerReplies: 3Last Post: 10th Oct 2013, 10:00 -
Calling MediaInfo from Visual Basic to et video info
By SearchQuality in forum ProgrammingReplies: 18Last Post: 2nd Nov 2011, 06:36 -
MPEG-4 Visual
By nirbhayn in forum Video ConversionReplies: 9Last Post: 4th Jul 2010, 14:43 -
visual basic code
By kudoshinichi in forum ProgrammingReplies: 1Last Post: 21st Jan 2009, 08:30