Tutorial, what have I missed ?

  • Thread starter Thread starter Keith(Southend)
  • Start date Start date
K

Keith(Southend)

http://msdn.microsoft.com/en-us/library/3akccs5d.aspx

To create a collection of objects...

I've added the code to Form1.vb PlayerTest but I get 5 Errors all as follws:
Name 'team' is not declared.
I was thinking I need to add 'team' as a declaration at the top, but
this didn't seem to work. I'm sure I've followed the whole tutorial
correctly.
Team.add (x4) & SelectedPlayer = team(Trim(ComboBox1.SelectedItem)).

<snip>
Public Class Form1
Dim player1 As New Persons.Players
Dim player2 As New Persons.Players
Dim player3 As New Persons.Players
Dim player4 As New Persons.Players


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

With player1
.FirstName = "Andrew"
.LastName = "Davis"
.Number = 43
.Position = "Shortstop"
End With
With player2
.FirstName = "Robert"
.LastName = "Brown"
.Number = 11
.Position = "Catcher"
End With
With player3
.FirstName = "Jeff"
.LastName = "Smith"
.Number = 52
.Position = "First Base"
End With

With player4
.FirstName = "Chris"
.LastName = "Mayo"
.Number = 22
.Position = "Pitcher"
End With

Team.Add(player1, player1.Position)
team.Add(player2, player2.Position)
team.Add(player3, player3.Position)
team.Add(player4, player4.Position)

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
MsgBox(player1.Position & " " & player1.FullName & _
" is now at bat.")

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
MsgBox(player2.Position & " " & player2.FullName & _
" is on deck.")


End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ComboBox1.SelectedIndexChanged
Dim SelectedPlayer As Persons.Players
' The Trim function deletes spaces at the beginning and
' at the of the string.
SelectedPlayer = team(Trim(ComboBox1.SelectedItem))
MsgBox("Playing " & ComboBox1.SelectedItem & " is " & _
SelectedPlayer.FullName & "!")

End Sub
End Class
<snip>

I'm sure this is basic, but it's got my stuck at this minute :-(

Many thanks
 
Keith(Southend) said:
http://msdn.microsoft.com/en-us/library/3akccs5d.aspx

To create a collection of objects...

I've added the code to Form1.vb PlayerTest but I get 5 Errors all as
follws:
Name 'team' is not declared.
I was thinking I need to add 'team' as a declaration at the top, but
this didn't seem to work. I'm sure I've followed the whole tutorial
correctly.
Team.add (x4) & SelectedPlayer = team(Trim(ComboBox1.SelectedItem)).

<snip>
Public Class Form1
Dim player1 As New Persons.Players
Dim player2 As New Persons.Players
Dim player3 As New Persons.Players
Dim player4 As New Persons.Players


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

With player1
.FirstName = "Andrew"
.LastName = "Davis"
.Number = 43
.Position = "Shortstop"
End With
With player2
.FirstName = "Robert"
.LastName = "Brown"
.Number = 11
.Position = "Catcher"
End With
With player3
.FirstName = "Jeff"
.LastName = "Smith"
.Number = 52
.Position = "First Base"
End With

With player4
.FirstName = "Chris"
.LastName = "Mayo"
.Number = 22
.Position = "Pitcher"
End With

Team.Add(player1, player1.Position)
team.Add(player2, player2.Position)
team.Add(player3, player3.Position)
team.Add(player4, player4.Position)

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
MsgBox(player1.Position & " " & player1.FullName & _
" is now at bat.")

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
MsgBox(player2.Position & " " & player2.FullName & _
" is on deck.")


End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ComboBox1.SelectedIndexChanged
Dim SelectedPlayer As Persons.Players
' The Trim function deletes spaces at the beginning and
' at the of the string.
SelectedPlayer = team(Trim(ComboBox1.SelectedItem))
MsgBox("Playing " & ComboBox1.SelectedItem & " is " & _
SelectedPlayer.FullName & "!")

End Sub
End Class
<snip>

I'm sure this is basic, but it's got my stuck at this minute :-(

Many thanks

In step three they showed you needing to declare:

Dim team As New Collection

I believe you want that right after your declaration for player4.
 
In step three they showed you needing to declare:

Dim team As New Collection

I believe you want that right after your declaration for player4.

Thanks Mike, I'd missed that step. I spotted the problem almost as
soon as I posted, I'd copied the "Dim baseballTeam As New Collection"
just had to remove 'baseball' then all fell into place.

I did post on my ISP's newserver, "Demon" but it didn't send. It will
probably appear soon, hopefully, as I added a little about myself and
what I'm trying to achieve.

Hopefully I won't make to much of a nuisance of myself in the coming
weeks, but I know there will be some grey areas not covered in the
tutorials.

But this looks fun all the same :-)

Thanks once again.

Keith (Southend, UK)
 
On Jul 12, 9:51 pm, Family Tree Mike <[email protected]>
wrote:

No, Demon news is dead for now, this is what I posted....

$$$$$$$$$$

AH, no soon I posted I found the error:

***
Visual Basic

Dim baseballTeam As New Collection
***

I added the declaration as above which was giving me the error, but
when I removed 'baseball' and just left 'Team' the errors cleared.

:-)

I'm new to programming and have been advised that for what I require
Visual Basic 2008 Express will do what I want to do.

*****
Basically, my interest is Meteorology (weather) and in particular
decoding synop code:
eg
SMUK43 EGRR 121800
AAXX 12184
03305 16680 /2420 10143 20115 39813 40068 52007 69922 91750 333 10159
81/40 86/50 90710 91130=
03313 16969 /2409 10171 20110 39970 40061 51005 60002 91750 333 10192
81/58=
etc.....
I'm looking at eliminating much of the 'number crunching' I do
compiling the full hourly data lists of synops (text files).
Two pressing steps I have to sort out.
1. Write a programme that can select a number of Countries/times from
the following website:
http://www.ogimet.com/synopsc.phtml.en
38 Countries I grab, which can take me quite sometime each day.
2. Sort the data into individual hourly text files, cleaning up some
of the letters and numbers. Basically AAXX 12184 is today 18:00 hour,
I may have 12194, 12204 etc, 19:00, 20:00 etc.

This is quite a step for me so I am running through ALL the tutorials
and bought a book by Patrice Pelland "Build a Programm NOW!" Visual
Basics 2008 Express Edition. I'm sure if I can crack this the world we
be my oyster.

Many thanks
 
Keith said:
AH, no soon I posted I found the error:

***
Visual Basic

Dim baseballTeam As New Collection
***

I added the declaration as above which was giving me the error, but
when I removed 'baseball' and just left 'Team' the errors cleared.

:-)


Without knowing what the error message said, it would be hard to guess
why that might be happening.

I'm new to programming and have been advised that for what I require
Visual Basic 2008 Express will do what I want to do.

*****
Basically, my interest is Meteorology (weather) and in particular
decoding synop code:
eg
SMUK43 EGRR 121800
AAXX 12184
03305 16680 /2420 10143 20115 39813 40068 52007 69922 91750 333 10159
81/40 86/50 90710 91130=
03313 16969 /2409 10171 20110 39970 40061 51005 60002 91750 333 10192
81/58=
etc.....
I'm looking at eliminating much of the 'number crunching' I do
compiling the full hourly data lists of synops (text files).
Two pressing steps I have to sort out.
1. Write a programme that can select a number of Countries/times from
the following website:
http://www.ogimet.com/synopsc.phtml.en
38 Countries I grab, which can take me quite sometime each day.
2. Sort the data into individual hourly text files, cleaning up some
of the letters and numbers. Basically AAXX 12184 is today 18:00 hour,
I may have 12194, 12204 etc, 19:00, 20:00 etc.


Are you then familiar with the METAR data format? We do something
similar with that data. We grab data from
http://weather.noaa.gov/pub/data/observations/metar/cycles/HHZ.txt,
where HH is the hour of the day, on a regular schedule. We get the data
(your step 1) on a timer event with a webclient object. We parse the
data into a METAR object which is stored into a dictionary for the
particular hour. This dictionary is then stored into a database.

So, if you look into using a timer, with a dictionary collection and a
web client, you probably will get a long way toward where you are going.
The hard part dealing with met data is the parsing. Presumably if you
get the data you know how to parse it.
 
Public Class Form1
Dim player1 As New Persons.Players
With player1
.FirstName = "Andrew"
.LastName = "Davis"
.Number = 43
.Position = "Shortstop"
End With
<etc>

I suggest that rather than having a separate variable for each player you
should use a List(Of Player) to represent the team.

Just commenting, but to save typing you can define a method for a New
..Player such that you can add them with the new statement:

Public Class Form1
Friend Class player
Private _FirstName As String
Private _LastName As String
Private _Number As String
Private _Position As String
Public Property FirstName() As String
Get
Return _FirstName
End Get
Set(ByVal value As String)
_FirstName = value
End Set
End Property
Public Property LastName() As String
Get
Return _LastName
End Get
Set(ByVal value As String)
_LastName = value
End Set
End Property
Public Property Number() As String
Get
Return _Number
End Get
Set(ByVal value As String)
_Number = value
End Set
End Property
Public Property Position() As String
Get
Return _Position
End Get
Set(ByVal value As String)
_Position = value
End Set
End Property
Public ReadOnly Property FullName() As String
Get
Return (_FirstName & " " & _LastName)
End Get
End Property

Friend Sub New(ByVal FirstName As String, ByVal LastName As String,
ByVal Number As String, ByVal Position As String)
_FirstName = FirstName
_LastName = LastName
_Number = Number
_Position = Position
End Sub

End Class

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim Team As List(Of player)
Team.Add(New player("James", "Kirk", "1", "Captain"))
Team.Add(New player("Leonard", "McCoy", "2", "Doctor"))
' and so on
End Sub

End Class

(I did Position as a string because in reality it is a label, not a number,
c.f. rugby positions: some teams use a letter rather than a number.)

Then you could create a class called Team with properties such as position
in the league and have leagues as List(Of Team). From that you can expand
Team to include scores-per-game and so on.

(expansion of Private _Whatever variables into properties aided by CodeRush
Xpress from DevExpress.com)

Also, you could represent the positions with an Enum, which means your code
would show things like Position.Backstop rather than a "string", leading to
fewer potential errors. (Like Team.Add(New player("James", "Kirk", "1",
Position.Captain)).)

Andrew
 
Without knowing what the error message said, it would be hard to guess
why that might be happening.







Are you then familiar with the METAR data format?  We do something
similar with that data.  We grab data fromhttp://weather.noaa.gov/pub/data/observations/metar/cycles/HHZ.txt,
where HH is the hour of the day, on a regular schedule.  We get the data
(your step 1) on a timer event with a webclient object.  We parse the
data into a METAR object which is stored into a dictionary for the
particular hour.  This dictionary is then stored into a database.

So, if you look into using a timer, with a dictionary collection and a
web client, you probably will get a long way toward where you are going.
  The hard part dealing with met data is the parsing.  Presumably if you
get the data you know how to parse it.

Yes , I'm familiar with METAR data and regularily use the NOAA site,
they also have synop data:
http://weather.noaa.gov/pub/SL.us008001/DF.an/DC.sflnd/DS.synop/
ftp://tgftp.nws.noaa.gov/SL.us008001/DF.an/DC.sflnd/DS.synop
Another project that I have in mind ;-)

I'll make a note of what you do using Web Client, dictionary and
parsing, but at the moment it's a bit further down my learning curve.
I have some tools that do some parsing (I think you mean by this,
sorting the synop code into a useable format), these were written for
me over 7 years ago. It's only now I've got to the point where I want
to be able to take control of these things.

I haven't yet got to the point of downloading a file from a programme,
only been on the VB trail for two weeks.

Many thanks

Keith (Southend, UK)
 
Back
Top