|
hi guys. beginner here!
following code throws up an formatexception error. unsure how fix the problem
reading from a text file with the data:
Rovers
6
1
1
12500
120000
United
4
2
2
20200
400000
City
1
0
7
8000
85000
Public Class Form1
Private Sub btnOutput_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOutput.Click
Dim sr As IO.StreamReader = IO.File.OpenText("C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\Assessment2\football.txt")
Dim fmtStr As String = "{0, -15}{1, 10:N0}{2, 8:N1}{3, 8:N2}{4, 8:N3}{5, 8:N4}{6, 20:N5}(7, 20:C}{8, 8:P0}"
Dim team As String
Dim played, won, drawn, lost, points, aveA, aveI, perc As Integer
lstbox.Items.Add(String.Format(fmtStr, "Team", "Played", "Won", "Drawn", "Lost", "Points", "AveAttendance", "AveIncome", "%Won"))
team = sr.ReadLine
won = sr.ReadLine
drawn = sr.ReadLine
lost = sr.ReadLine
played = won + lost + drawn
points = (won * 3) + (drawn * 1)
aveA = sr.ReadLine
aveI = sr.ReadLine
lstbox.Items.Add(String.Format(fmtStr, team, won, drawn, lost, points, aveA, aveI, perc))
team = sr.ReadLine
won = sr.ReadLine
drawn = sr.ReadLine
lost = sr.ReadLine
played = won + lost + drawn
points = (won * 3) + (drawn * 1)
aveA = sr.ReadLine
aveI = sr.ReadLine
lstbox.Items.Add(String.Format(fmtStr, team, won, drawn, lost, points, aveA, aveI, perc))
team = sr.ReadLine
won = sr.ReadLine
drawn = sr.ReadLine
lost = sr.ReadLine
played = won + lost + drawn
points = (won * 3) + (drawn * 1)
aveA = sr.ReadLine
aveI = sr.ReadLine
lstbox.Items.Add(String.Format(fmtStr, team, won, drawn, lost, points, aveA, aveI, perc))
sr.Close()
End Sub
End Class
|
|
|
|
|
bjk88 wrote: following code throws up an formatexception error. unsure how fix the problem
reading from a text file with the data:
What is the message of the exception and where did it happen?
|
|
|
|
|
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
Input string was not in a correct format.
it occurs in the line:
lstbox.Items.Add(String.Format(fmtStr, "Team", "Played", "Won", "Drawn", "Lost", "Points", "AveAttendance", "AveIncome", "%Won"))
|
|
|
|
|
bjk88 wrote: Dim fmtStr As String = "{0, -15}{1, 10:N0}{2, 8:N1}{3, 8:N2}{4, 8:N3}{5, 8:N4}{6, 20:N5}(7, 20:C}{8, 8:P0}"
Dim team As String
Dim played, won, drawn, lost, points, aveA, aveI, perc As Integer
lstbox.Items.Add(String.Format(fmtStr, "Team", "Played", "Won", "Drawn", "Lost", "Points", "AveAttendance", "AveIncome", "%Won"))
If I'm interpreting the format strings correctly, then it is expecting that some of the arguments being passed to the Format method to be numeric. All the arguments are strings. Did you mean to pass strings? Or did you mean to pass the variables with similar (capitalisation differences) names?
|
|
|
|
|
i meant to pass variables with similar names.
the aim is to print out a sort of table such as
team played won drawn lost etc.....
rovers 8 6 1 19
united 8 4 2 2
|
|
|
|
|
bjk88 wrote: i meant to pass variables with similar names.
You mean you meant to pass the strings on this line because if you passed the variables then you would not get the output you have indicated.
Your format string dictates that the input on certain columns will be numeric. You have passed a string. You need to use a formatting string that does not require numeric data for that line.
Also (once you fix this problem), the ReadLine statements will be your next problem, as you are not converting them to numeric data. (Well, at least those that need converting)
|
|
|
|
|
Oh yeah, sorry, the first line added to the lstbox the strings should be passed. After that the variable data read from the text file should be passed.
|
|
|
|
|
bjk88 wrote: lstbox.Items.Add(String.Format(fmtStr, "Team", "Played", "Won", "Drawn", "Lost", "Points", "AveAttendance", "AveIncome", "%Won"))
You can't use string values with a format that expects numeric values.
bjk88 wrote: won = sr.ReadLine
This is an implicit conversion equivalent to:
won = Convert.ToInt32(Double.Parse(sr.ReadLine))
This might not be exactly what you want. You might rather want to use Option Explicit On (to avoid unintended conversions), and do the conversions youself, so that you see what actually happens.
bjk88 wrote: lstbox.Items.Add(String.Format(fmtStr, team, won, drawn, lost, points, aveA, aveI, perc))
You haven't assigned any value to the perc variable.
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
Guffa wrote: You can't use string values with a format that expects numeric values.
How would i go about changing it so it would accept the values?
|
|
|
|
|
bjk88 wrote: How would i go about changing it so it would accept the values?
"{0, -15}{1, 10}{2, 8}{3, 8}{4, 8}{5, 8}{6, 20}(7, 20}{8, 8}"
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
Guffa wrote: "{0, -15}{1, 10}{2, 8}{3, 8}{4, 8}{5, 8}{6, 20}(7, 20}{8, 8}"
I changed to that, but still get the same error.
|
|
|
|
|
Change (7, 20} to {7, 20} .
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
That has worked. Thanks a lot!
Now getting an error at the next lstbox.Items.Add line.
"Index (zero based) must be greater than or equal to zero and less than the size of the argument list."
|
|
|
|
|
Check the arguments in the call, and add the one that is missing.
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
Ive added the one that is missing.
|
|
|
|
|
The code now looks like this:
Public Class Form1
Private Sub btnOutput_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOutput.Click
'Declare variables
Dim team As String
Dim played, won, drawn, lost, points, aveA, aveI, perc As Integer
'Create "zones" for data
Dim fmtStr As String = "{0, -15}{1, 10:N0}{2, 8:N1}{3, 8:N2}{4, 8:N3}{5, 8:N4}{6, 20:N5}{7, 20:C}{8, 8:P0}"
'Read data from football.txt
Dim sr As IO.StreamReader = IO.File.OpenText("C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\Assessment2\football.txt")
'Add headers to the table
lstbox.Items.Add(String.Format(fmtStr, "Team", "Played", "Won", "Drawn", "Lost", "Points", "AveAttendance", "AveIncome", "%Won"))
team = sr.ReadLine
won = CInt(sr.ReadLine)
drawn = CInt(sr.ReadLine)
lost = CInt(sr.ReadLine)
played = won + lost + drawn
points = (won * 3) + (drawn * 1)
aveA = CInt(sr.ReadLine)
aveI = CInt(sr.ReadLine)
perc = (won / played) * 100
lstbox.Items.Add(String.Format(fmtStr, team, won, drawn, lost, points, aveA, aveI, perc))
sr.Close()
End Sub
End Class
With the error appearing in the highlighted line.
|
|
|
|
|
See my previous post.
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
hi all
i have download one project in vb6 and i have also convert in to vb.net but there is one problem Me.Line
this is the code in vb6
Sub AngleLineXY(ByRef X As Single, ByRef Y As Single, ByRef LineLength As Single, ByRef Angle As Single, ByRef LineID As Short, Optional ByRef Color As Short = 0)<br />
Dim X1 As Single<br />
Dim Y1 As Single<br />
Dim X2 As Single<br />
Dim Y2 As Single<br />
<br />
X1 = CenterX + X<br />
Y1 = CenterY + Y<br />
X2 = CSng(X1 + (System.Math.Cos(Angle - Radians(90)) * LineLength))<br />
Y2 = CSng(Y1 + (System.Math.Sin(Angle - Radians(90)) * LineLength))<br />
<br />
'UPGRADE_ISSUE: Form method Main.Line was not upgraded. Click for more: 'ms-help:
Me.Line (X1,Y1)-(X2,Y2)<br />
Me.Line (X1,Y1)-(X3,Y3)<br />
<br />
AL(LineID).X1 = X1 - CenterX<br />
AL(LineID).Y1 = Y1 - CenterY<br />
AL(LineID).X2 = X2 - CenterX<br />
AL(LineID).Y2 = Y2 - CenterY<br />
<br />
CurLineID = CShort(CurLineID + 1)<br />
End Sub
so how can i change this
this project is for rotate 3d qube i am new in vb.net and i just want to create 3d qube with rotation
any help
please
|
|
|
|
|
Have you checked what the help article that the code references has to say?
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
you need to handle your forms paint event and then use the graphics object passed in there to draw lines
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I hope I'm posting this on the right board;
Using VB6 & Win 98, I spent many days trying to make an old (cash register) program I wrote many years ago talk. ie; "two at three dollars and twenty-five cents each", "Total due is" , "Your change is", etc. I had little or no success. One member suggested I up-grade my OS & up-grade from VB6 to VB.NET. I did up-grade to Win XP Pro & will try to learn VB.NET later.
Still trying to accomplish my goal, I purchase several third-party APIs (Alive Text to Speech, TextSound, & TextAloud) at a cost of $25 to $29 each. They all had problems and wouldn't work for me. I sent numerous e-mails to their support address for help. I got zero response from "Alive Text to Speech" & "TextSound". I did get immediate response from "TextSound". "TextSound" was NOT able to help me with my problem which turned out (according to their forum) to be shared by other users of their application. Additionally, "TextSound" wanted an additional $250 for a developers license if I wanted to use their command line feature for more than 30 days. Since it wouldn't work for me anyway, this discussion became mute.
About to give up, I decided to download the free SDK5.1 (Speech Development Kit) from Microsoft. Only having dial-up this took 4 hours. Boy, was it worth it!
Not only did the download come with several complete sample speech projects, they all compiled & ran on VB6. Even better yet, they all had complete, well commented source code. After getting this download, I had my old program running & talking perfect in about 45 minutes.
I hope this might be helpful to someone.
Robert, still trying
|
|
|
|
|
Robert from Florida wrote: this discussion became mute.
you mean moot ?
Robert from Florida wrote: About to give up, I decided to download the free SDK5.1 (Speech Development Kit) from Microsoft. Only having dial-up this took 4 hours. Boy, was it worth it!
Yeah, as I was reading, I wondered why no search you did brought this up.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Actually I want to display the Amount of Available Memory and CPU Usage and also its history on Screen just like one on Task Manager. So far I am able to display the Available Memory on Screen by using a Performance Counter under Memory Category "Available KBytes". But how can i display the CPU Usage and its History. I am using the "% Processor Time" Performance counter but can't see anything happening on screen. What should i use for this purpose. Thanks for your cooperation !
AliAmjad(MCP)
|
|
|
|
|
Would you care to show the code that you are using for the PerformanceCounter class? It sounds like it ought to be working. I've done this numerous times in the past and it works.
"Find it your bloody self - immediately!" - Dave Kreskowiak
|
|
|
|
|
I am using the RawValue Property of "Available KBytes" Performance Counter and also used the same one for "% Processor Time" under a Timer which updates the Text of the Label after every Second But I Get always a '0' for "% Processor Time" is there any other way of using this counter and also what about the real time graph how can i display it on screen.
AliAmjad (MCP)
|
|
|
|
|