Pittpitu 0 Newbie Poster

Hi guys,

I am trying to make a small application for the company I work for.
The application has to be able to make a floor plan for a casino.
The casino has to create the map of where all the slot machines are located and if you double click on a certain machine pull some info for it.
So I put a picturebox and divide it in a lot of cells and create a class named CellValue and create and array of object Cell value.
The Cellvalue has some variables cellcolor, cellname, cellshape and cell Location x and y.

My issue now is that I need to save the array so I can re draw and save the map made. and tried several methods to save it using XML serialization but it doesn't do nothing :(
If I do get the array to save how can I access items in the array from outside the method? that doesn't seem to be working as well.

here is the code I have up to now

Imports System
Imports System.Collections
Imports System.Xml
Imports System.Array
Imports System.Data
Imports System.IO

Public Class Form1

    Dim SizeW As Integer = 30
    Dim SizeH As Integer = 30
    Dim Plan(SizeW - 1, SizeH - 1) As CellValue
    'array created of objects from class CellValue 
    Dim Command As Integer = -1
    'Set to -1 if none of the buttons are clicked, can give a function/sub code for this
    Dim RND As New Random
    'To randomize the colors if needed
    Public LocXY As String = ""
    Public mcid As String = ""


    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        Command = 0
        'This will execute command 0 code below
    End Sub

    Public Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Command = 1
        'This will execute command 1 below
    End Sub
    Private Sub btnstrdata_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnstrdata.Click
        Command = 2
        'This will execute command 2 code below
        'will be to serialize map to xml

    End Sub

    Public Function PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
        Dim CellW As Integer = PictureBox1.Width \ SizeW
        Dim CellH As Integer = PictureBox1.Height \ SizeH
        'Divides the picture box size into cells p.e size =200 and there is 20 array obj each cell is 10px
        Dim P As Point = PointToClient(MousePosition)
        Dim X As Integer = (P.X - PictureBox1.Left) \ CellW
        Dim Y As Integer = (P.Y - PictureBox1.Top) \ CellH
        'Determining which cell is clicked
        Label1.Text = X.ToString & " " & Y.ToString
        'Label5.Text = Plan(X, Y).CellName

        If Command <> -1 Then
            If Plan(X, Y) Is Nothing Then Plan(X, Y) = New CellValue
            Select Case Command
                Case 0 : Plan(X, Y).CellShape = 0
                    Label5.Text = Plan(X, Y).CellName
                    'Array.Clear(Plan(X, Y))  'doesn't work
                    'Try to clear one element in the whole array when the clear button is selected
                    'No cell shape nor color, if there is something it will be cleared
                Case 1
                    Plan(X, Y) = New CellValue
                    'will show an inputbox so it prompts user to add machineID
                    mcid = InputBox("Enter MachineID", "MachineID")
                    Plan(X, Y).CellName = mcid
                    Plan(X, Y).CellLocX = X
                    Plan(X, Y).CellLocY = Y
                    Plan(X, Y).CellColor = Color.Black
                    If chbxnigt.Checked Then
                        Plan(X, Y).CellShape = Shape.Circle
                        'if the button is pressed then shape will be a circle
                    Else : Plan(X, Y).CellShape = Shape.Square
                    End If
                    Label5.Text = Plan(X, Y).CellName
                    'Checks if checkbox is selected will put a circle else a square as SHAPE!

                    'Case 2: eventually will save/update the array to xml
                Case 2
                    MessageBox.Show("MachineID is " & Plan(X, Y).CellName & "   X-Location is " & Plan(X, Y).CellLocX & "  Y-Location is  " & Plan(X, Y).CellLocY)
                    Label5.Text = Plan(X, Y).CellName
            End Select
            PictureBox1.Invalidate()
            'this is so that the picturebox can be redrawn everytime.
            Command = -1   'One click only per selection

        End If
        Return LocXY = Label1.Text
    End Function


    Public Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
        Dim W As Integer = PictureBox1.Width
        Dim H As Integer = PictureBox1.Height
        Dim CellW As Integer = W \ SizeW
        Dim CellH As Integer = H \ SizeH
        Dim P As Pen = New Pen(Color.Gray, 1)
        For I As Integer = 0 To W Step CellW
            e.Graphics.DrawLine(P, I, 0, I, H)
        Next
        For I As Integer = 0 To H Step CellH
            e.Graphics.DrawLine(P, 0, I, W, I)
        Next

        For i As Integer = 0 To SizeW - 1
            For j As Integer = 0 To SizeH - 1
                If Not Plan(i, j) Is Nothing Then
                    fillcell(e.Graphics, i, j, Plan(i, j).CellColor, Plan(i, j).CellShape)
                End If
            Next
        Next
    End Sub

    Private Sub fillcell(ByVal g As Graphics, ByVal I As Integer, ByVal j As Integer, ByVal C As Color, ByVal S As Shape)
        Dim CellW As Integer = PictureBox1.Width \ SizeW
        Dim CellH As Integer = PictureBox1.Height \ SizeH
        Dim x As Integer = I * CellW
        Dim y As Integer = j * CellH
        Select Case S
            Case Shape.Blank ' Do Nothing
                Label5.Text = ""
            Case Shape.Square
                g.FillRectangle(New SolidBrush(C), New Rectangle(x, y, CellW, CellH))
            Case Shape.Circle
                g.FillEllipse(New SolidBrush(C), New Rectangle(x, y, CellW, CellH))
        End Select

    End Sub

  
End Class

Friend Class CellValue
    Public CellColor As Color = Color.White
    Public CellShape As Shape = Shape.Blank
    Public CellName As String = ""
    Public CellLocX As String = ""
    Public CellLocY As String = ""
End Class

Friend Enum Shape
    Blank
    Square
    Circle
End Enum

Will be thankfull for any comments you might have