locked
Is it possible to lose data through a program (load function)

    Question

  • Hey there - i recent recieve help from derek on my program but through a few tests of my program - i thought we fix the program- but it turns out i have the same problem as before.

    one thought i had was that maybe i was losing data at some point in my program - is that possible?

    I have two forms that loads all of the hockey player skills to two datagrids (form 2 and Form3) then form 4 extracts all of the player skills from the grid and stores the values in varoius variables.  These variables are used throughout the program. 

    There are 6 of the following faceofftypes;

    1    Home_Def_Zone_Faceoff2
    2    Home_Def_Zone_Faceoff
    3    Away_Def_Zone_Faceoff2
    4    Away_Def_Zone_Faceoff
    5    Opening Faceoff
    6    GoalLine1

    I plan on adding a few more of these faceoffs -

    atm it loads 1 through 4 but it doesn't load certain parts - i.e. there are 3 possiblities LD Shot (away or home) , RD Shot (away or home) and LD (opposite of home or away) on any particular faceoff - just 1 through 4.

    the defense shooting functions work good - it just the left defense functions that don't load.

    the other faceoffs work pretty good.

    is there suppose to be an order in which the decision tree is executed?

    I have a problem loading one of my functions - i simplified my decision tree to the following:

    Case FaceoffTypes.Home_Def_Zone_Faceoff2

        Select Case Def_Faceoff_Home_Line2()

            Case FaceoffResultsLine2.Home_LD2_H

                Select Case LD2_H()

                    Case Playresults2.center2a_shot_H

                        Select Case centerH2a_Shot()

                            Case Playresults2.Write_Text_H2a

                                Select Case Text_Write_H2a()

                                End Select

                        End Select

                    Case Playresults2.rwer2a_shot_H

                        Select Case RwerH2a_Shot()

                            Case Playresults2.Write_Text_H2a

                                Select Case Text_Write_H2a()

                                End Select

                        End Select

                   Case Playresults2.lwer2a_shot_H

                        Select Case lwerH2a_Shot()

                            Case Playresults2.Write_Text_H2a

                                Select Case Text_Write_H2a()

                                End Select

                        End Select

                    Case Playresults2.center2a_shot_A

                        Select Case centerA2a_Shot()

                            Case Playresults2.Write_Text_A2a

                                Select Case Text_Write_A2a()

                                End Select

                        End Select

                    Case Playresults2.rwer2a_shot_A

                        Select Case RwerA2a_Shot()

                            Case Playresults2.Write_Text_A2a

                                Select Case Text_Write_A2a()

                                End Select

                        End Select

                    Case Playresults2.lwer2a_shot_A

                        Select Case LwerA2a_Shot()

                            Case Playresults2.Write_Text_A2a

                                Select Case Text_Write_A2a()

                                End Select

                        End Select

            End Select

            Case FaceoffResultsLine2.Home_LD2_A

                Select Case LD2A_Shot()

                    Case Playresults2.Write_Text_A2a

                        Select Case Text_Write_A2a()

                        End Select

                End Select

            Case FaceoffResultsLine2.Home_RD2_A

                Select Case RD2A_Shot()

                    Case Playresults2.Write_Text_A2a

                        Select Case Text_Write_A2a()

                        End Select

                End Select

    End Select

    Each faceoff is pretty much simular to the above.

    The only other thing i can try is to embed the shooting functions into the main program but i think the same problem will arise after i do so.

    Is there a more reliable decision tree i can use or can anyone see what is wrong?

    if there is any other info u need let me know - i could also send a copy of the program to someone to try in visual basic express.

    thanks

    Nick

    Monday, December 29, 2008 2:39 AM

Answers

  •  

    Hi Again .

    I'm not sure what your code should ( do, make ) with too many ( Select Case ) .
    I was trying to tell you that you can use an enumerator like a calculator .

    ( #Region "SomeName", #End Region ) Doesn't make any difference, as what 'Stuck On Code' said :_
    " Group a section of your code so that you can collapse and expand it in the editor "

    Here's another Example :
    Start up a new project ( Windows Application ) and paste the following into Form1.vb

    Public Class Form1

    Private DTab As String = (Chr(9) & Chr(9))
    Private _Header As String = "Player ID" & DTab & _
    "Golden Goals" & Chr(9) & "Silver Goals" & Chr(9) & _
    "Bronze Goals" & Chr(9) & "Red Card" & DTab & "Yellow Cards" & _
    Chr(9) & "Total"
    Private _Players As New List(Of Player)
    Private _MyTextBox As New TextBox
    Private WithEvents HScrollBar1 As New HScrollBar

    Private Sub Form1_Load(ByVal Sender As System.Object _
    ,
    ByVal E As System.EventArgs) Handles MyBase.Load
    Dim _MyRandom As New Random
    For I As Integer = 1 To 10
    Dim NewPlayer As New Player
    NewPlayer.PlayerID = I
    NewPlayer.SilverGoals(1) = _MyRandom.Next(0, 5)
    NewPlayer.GoldenGoals(1) = _MyRandom.Next(0, 5)
    NewPlayer.BronzeGoals(1) = _MyRandom.Next(0, 5)
    NewPlayer.RedCard(1) = _MyRandom.Next(0, 4)
    NewPlayer.YellowCards(1) = _MyRandom.Next(0, 3)
    _Players.Add(NewPlayer)
    Next
    _MyTextBox.Multiline = True
    _MyTextBox.Dock = DockStyle.Fill
    HScrollBar1.LargeChange = 1
    HScrollBar1.Maximum = 10
    HScrollBar1.Minimum = 1
    HScrollBar1.Dock = DockStyle.Bottom
    Controls.Add(_MyTextBox)
    Controls.Add(HScrollBar1)
    Size = New Size(624, 105)
    End Sub

    Private Sub HScrollBar1_Scroll(ByVal Sender As Object _
    , ByVal E As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll
    _MyTextBox.Text = _Header & (Chr(13) & Chr(10))
    _MyTextBox.Text &= GetInfo(HScrollBar1.Value, 1) & (Chr(13) & Chr(10))
    _MyTextBox.Text &= GetInfo(HScrollBar1.Value, 0) & (Chr(13) & Chr(10))
    End Sub

    Private Function GetInfo(ByVal PlayerID As Integer, ByVal TheCount As Boolean) As String
    For Each Player As Player In _Players
    If Player.PlayerID = PlayerID Then
    Dim Information As String = String.Empty
    Information = Player.PlayerID & DTab & Player.GoldenGoals(TheCount) _
    & DTab & Player.SilverGoals(TheCount) & DTab _
    & Player.BronzeGoals(TheCount) & DTab
    If TheCount Then
    Information &= Convert.ToBoolean(Player.RedCard(TheCount)).ToString()
    Else
    Information &= Player.RedCard(TheCount)
    End If
    Information &= DTab & Player.YellowCards(TheCount)
    If Not TheCount Then
    Information &= DTab & Player.Total
    End If
    Return Information
    End If
    Next
    End Function

    #Region "GameProperties"

    Public Enum Goals
    Golden = 100
    Silver = 50
    Bronze = 25
    End Enum

    Public Enum Cards
    Red = -100
    Yellow = -50
    End Enum

    Public Class Player
    Public PlayerID As Integer = 0
    Private _GoldenGoals As Integer = 0
    Private _SilverGoals As Integer = 0
    Private _BronzeGoals As Integer = 0
    Private _RedCard As Integer = 0
    Private _YellowCards As Integer = 0

    Public Property GoldenGoals(ByVal TheCount As Boolean) As Integer
    Get
    If TheCount Then
    Return _GoldenGoals
    Else
    Return CInt(_GoldenGoals * Goals.Golden)
    End If
    End Get
    Set(ByVal Value As Integer)
    _GoldenGoals = Value
    End Set
    End Property

    Public Property SilverGoals(ByVal TheCount As Boolean) As Integer
    Get
    If TheCount Then
    Return _SilverGoals
    Else
    Return CInt(_SilverGoals * Goals.Silver)
    End If
    End Get
    Set(ByVal Value As Integer)
    _SilverGoals = Value
    End Set
    End Property

    Public Property BronzeGoals(ByVal TheCount As Boolean) As Integer
    Get
    If TheCount Then
    Return _BronzeGoals
    Else
    Return CInt(_BronzeGoals * Goals.Bronze)
    End If
    End Get
    Set(ByVal Value As Integer)
    _BronzeGoals = Value
    End Set
    End Property

    Public Property RedCard(ByVal TheCount As Boolean) As Integer
    Get
    If TheCount Then
    Return CInt(_RedCard)
    Else
    Return CInt(_RedCard * Cards.Red)
    End If
    End Get
    Set(ByVal Value As Integer)
    _RedCard = Math.Max(Math.Min(Value, 1), 0)
    End Set
    End Property

    Public Property YellowCards(ByVal TheCount As Boolean) As Integer
    Get
    If TheCount Then
    Return _YellowCards
    Else
    Return (CInt(_YellowCards * Cards.Yellow))
    End If
    End Get
    Set(ByVal Value As Integer)
    _YellowCards = Value
    End Set
    End Property

    Public ReadOnly Property Total() As Integer
    Get
    Return CInt(GoldenGoals(0) + SilverGoals(0) + BronzeGoals(0) _
    + RedCard(0) + YellowCards(0))
    End Get
    End Property

    End Class

    #End Region

    End Class

    Hope this one going to give some idea .
    If you can put what's after each Case, I think we'll know the reason(s) for using those ( Select Case )(s)

    _____________

    Best Regards,

    BVS.


    BVS, Cos(), Sin() Can Make The Miracles
    Monday, December 29, 2008 10:49 AM

All replies

  • any ideas?
    Monday, December 29, 2008 4:34 AM
  • Hi Visual_Star .

    I think you must find a way to sort your Enumerations .

    the Following example is just to show how you can use that to calculate some values :

    Public Class Form1

    ' No overlap
    #Region "Enumerators"
    Public Enum Pack0
    P01 = 1
    P02 = 2
    P03 = 3
    P04 = 4
    P05 = 5
    P06 = 6
    P07 = 7
    P08 = 8
    P09 = 9
    End Enum

    Public Enum Pack1
    P11 = 10
    P12 = 20
    P13 = 30
    P14 = 40
    P15 = 50
    P16 = 60
    P17 = 70
    P18 = 80
    P19 = 90
    End Enum

    Public Enum Pack2
    P21 = 100
    P22 = 200
    P23 = 300
    P24 = 400
    P25 = 500
    P26 = 600
    P27 = 700
    P28 = 800
    P29 = 900
    End Enum
    #End Region

    #Region "Variables"
    Private _MyPack0 As Pack0 = Pack0.P01
    Private _MyPack1 As Pack1 = Pack1.P11
    Private _MyPack2 As Pack2 = Pack2.P21
    #End Region

    #Region "Events"
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim _MyRandom As New Random
    _MyPack0 = _MyRandom.Next(1, 9)
    _MyPack1 = (10 * _MyRandom.Next(1, 9))
    _MyPack2 = (100 * _MyRandom.Next(1, 9))
    MsgBox((_MyPack0 + _MyPack1 + _MyPack2))
    End Sub
    #End Region

    End Class

    For otherwise, Please read this Article for your reference.


    BVS, Cos(), Sin() Can Make The Miracles
    Monday, December 29, 2008 5:16 AM
  • So in #Region "Variables" - do i list the varoius possiblities that can occur?

    And i was wondering where to put the #Region "Events" - since i have alot of funtctions that return results too.
    Monday, December 29, 2008 6:12 AM
  • the #Region "", and #End Region  does absolutely NOTHING other than group a section of your code so that you can collapse and expand it in the editor.  You could remove the #region/#end region compiler directives and it will NOT effect the execution of your code at all.

    So to answer your question, put the functions for your class inside the scope of the class, just like your subs....... it doesn't matter....... the "Variables" he declared, are GLOBAL to the class, and HIDDEN from outside the class.  You can access those variables ANYWHERE inside your class, you CAN NOT access those variables OUTSIDE the class.  Now if you declared them instead of Private, but as Public, then those variables would be visible OUTSIDE the class.  However, in that case it would be better to declare them as Public Property, with appropriate "Get" and "Set" logic.

    I didn't explain that too well, but if you don't understand, respond, and maybe someone else can make it more clear.

    Go here http://msdn.microsoft.com/en-us/beginner/bb308752.aspx to help you understand classes.  Watch both videos, and it may give you a "clear" moment in which you understand the basic concept of how .net and OOP development works.  That is if you don't already know.
    Monday, December 29, 2008 6:29 AM
  •  

    Hi Again .

    I'm not sure what your code should ( do, make ) with too many ( Select Case ) .
    I was trying to tell you that you can use an enumerator like a calculator .

    ( #Region "SomeName", #End Region ) Doesn't make any difference, as what 'Stuck On Code' said :_
    " Group a section of your code so that you can collapse and expand it in the editor "

    Here's another Example :
    Start up a new project ( Windows Application ) and paste the following into Form1.vb

    Public Class Form1

    Private DTab As String = (Chr(9) & Chr(9))
    Private _Header As String = "Player ID" & DTab & _
    "Golden Goals" & Chr(9) & "Silver Goals" & Chr(9) & _
    "Bronze Goals" & Chr(9) & "Red Card" & DTab & "Yellow Cards" & _
    Chr(9) & "Total"
    Private _Players As New List(Of Player)
    Private _MyTextBox As New TextBox
    Private WithEvents HScrollBar1 As New HScrollBar

    Private Sub Form1_Load(ByVal Sender As System.Object _
    ,
    ByVal E As System.EventArgs) Handles MyBase.Load
    Dim _MyRandom As New Random
    For I As Integer = 1 To 10
    Dim NewPlayer As New Player
    NewPlayer.PlayerID = I
    NewPlayer.SilverGoals(1) = _MyRandom.Next(0, 5)
    NewPlayer.GoldenGoals(1) = _MyRandom.Next(0, 5)
    NewPlayer.BronzeGoals(1) = _MyRandom.Next(0, 5)
    NewPlayer.RedCard(1) = _MyRandom.Next(0, 4)
    NewPlayer.YellowCards(1) = _MyRandom.Next(0, 3)
    _Players.Add(NewPlayer)
    Next
    _MyTextBox.Multiline = True
    _MyTextBox.Dock = DockStyle.Fill
    HScrollBar1.LargeChange = 1
    HScrollBar1.Maximum = 10
    HScrollBar1.Minimum = 1
    HScrollBar1.Dock = DockStyle.Bottom
    Controls.Add(_MyTextBox)
    Controls.Add(HScrollBar1)
    Size = New Size(624, 105)
    End Sub

    Private Sub HScrollBar1_Scroll(ByVal Sender As Object _
    , ByVal E As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll
    _MyTextBox.Text = _Header & (Chr(13) & Chr(10))
    _MyTextBox.Text &= GetInfo(HScrollBar1.Value, 1) & (Chr(13) & Chr(10))
    _MyTextBox.Text &= GetInfo(HScrollBar1.Value, 0) & (Chr(13) & Chr(10))
    End Sub

    Private Function GetInfo(ByVal PlayerID As Integer, ByVal TheCount As Boolean) As String
    For Each Player As Player In _Players
    If Player.PlayerID = PlayerID Then
    Dim Information As String = String.Empty
    Information = Player.PlayerID & DTab & Player.GoldenGoals(TheCount) _
    & DTab & Player.SilverGoals(TheCount) & DTab _
    & Player.BronzeGoals(TheCount) & DTab
    If TheCount Then
    Information &= Convert.ToBoolean(Player.RedCard(TheCount)).ToString()
    Else
    Information &= Player.RedCard(TheCount)
    End If
    Information &= DTab & Player.YellowCards(TheCount)
    If Not TheCount Then
    Information &= DTab & Player.Total
    End If
    Return Information
    End If
    Next
    End Function

    #Region "GameProperties"

    Public Enum Goals
    Golden = 100
    Silver = 50
    Bronze = 25
    End Enum

    Public Enum Cards
    Red = -100
    Yellow = -50
    End Enum

    Public Class Player
    Public PlayerID As Integer = 0
    Private _GoldenGoals As Integer = 0
    Private _SilverGoals As Integer = 0
    Private _BronzeGoals As Integer = 0
    Private _RedCard As Integer = 0
    Private _YellowCards As Integer = 0

    Public Property GoldenGoals(ByVal TheCount As Boolean) As Integer
    Get
    If TheCount Then
    Return _GoldenGoals
    Else
    Return CInt(_GoldenGoals * Goals.Golden)
    End If
    End Get
    Set(ByVal Value As Integer)
    _GoldenGoals = Value
    End Set
    End Property

    Public Property SilverGoals(ByVal TheCount As Boolean) As Integer
    Get
    If TheCount Then
    Return _SilverGoals
    Else
    Return CInt(_SilverGoals * Goals.Silver)
    End If
    End Get
    Set(ByVal Value As Integer)
    _SilverGoals = Value
    End Set
    End Property

    Public Property BronzeGoals(ByVal TheCount As Boolean) As Integer
    Get
    If TheCount Then
    Return _BronzeGoals
    Else
    Return CInt(_BronzeGoals * Goals.Bronze)
    End If
    End Get
    Set(ByVal Value As Integer)
    _BronzeGoals = Value
    End Set
    End Property

    Public Property RedCard(ByVal TheCount As Boolean) As Integer
    Get
    If TheCount Then
    Return CInt(_RedCard)
    Else
    Return CInt(_RedCard * Cards.Red)
    End If
    End Get
    Set(ByVal Value As Integer)
    _RedCard = Math.Max(Math.Min(Value, 1), 0)
    End Set
    End Property

    Public Property YellowCards(ByVal TheCount As Boolean) As Integer
    Get
    If TheCount Then
    Return _YellowCards
    Else
    Return (CInt(_YellowCards * Cards.Yellow))
    End If
    End Get
    Set(ByVal Value As Integer)
    _YellowCards = Value
    End Set
    End Property

    Public ReadOnly Property Total() As Integer
    Get
    Return CInt(GoldenGoals(0) + SilverGoals(0) + BronzeGoals(0) _
    + RedCard(0) + YellowCards(0))
    End Get
    End Property

    End Class

    #End Region

    End Class

    Hope this one going to give some idea .
    If you can put what's after each Case, I think we'll know the reason(s) for using those ( Select Case )(s)

    _____________

    Best Regards,

    BVS.


    BVS, Cos(), Sin() Can Make The Miracles
    Monday, December 29, 2008 10:49 AM