Visual Basic > Visual Basic Forums > Visual Basic General > Can Any One Simplify CrazyPennie CODE
Ask a questionAsk a question
 

AnswerCan Any One Simplify CrazyPennie CODE

  • Saturday, November 07, 2009 12:57 AMShariqDON Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    In my Previous Thread < My First DATA Base Application > About DATABASE Crazypenie Give me Code:


    Public Class Form1
        Dim DtaSet As New DataSet
        Dim WithEvents DGrid As New DataGridView
        Dim WithEvents button1 As New Button
        Dim Tbl As New DataTable
        Public PathName As String = "C:\Tst\"
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.Size = New Size(600, 700)
            Me.Location = New Point(10, 10)
            Me.StartPosition = FormStartPosition.Manual
            'A datagridview to see and edit the data
            DGrid.Width = 400
            DGrid.Height = 600
            Me.Controls.Add(DGrid)
            'Show the data in Tbl in the datagridview
            DGrid.DataSource = Tbl
            'A dataset to manage the data
            DtaSet.Tables.Add(Tbl)
            'A table to hold the data
            Tbl.Columns.Add("Items")
            Tbl.Columns.Add("Description")
            Tbl.Columns.Add("Value")
            Tbl.Columns.Add("Total")
            Tbl.Columns.Add("Extra1")
            Tbl.Columns.Add("Extra2")
            Tbl.Columns.Add("Extra3")
            ' A save data button
            button1.Location = New Point(440, 600)
            button1.Text = "Save Data"
            Me.Controls.Add(button1)
            If Not IO.Directory.Exists(PathName) Then  'If it don't exist
                IO.Directory.CreateDirectory(PathName) 'Create a new directory for the database 
            End If
            If IO.File.Exists(PathName & "Main.xml") Then
                Tbl.ReadXml(PathName & "Main.xml") 'Load existing data if exist 
            Else
                Tbl.WriteXml(PathName & "Main.xml") 'If dont exist, create it
            End If
       End Sub
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Tbl.WriteXml(PathName & "Main.xml") 'save the data entered in the DataGridView
        End Sub
    End Class
    

    Why I need to Simplify Code

    Because He Not Drag And Drop Tools From Toolbox, He Import Every things by code Like this:

        Dim DtaSet As New DataSet
        Dim WithEvents DGrid As New DataGridView
        Dim WithEvents button1 As New Button
        Dim Tbl As New DataTable

    I want to Simplify It, Please helpme to make it simplify, Its difficult to Understand

    T h a n k s
    www.shariqdon.media.officelive.com
    • Edited byShariqDON Saturday, November 07, 2009 1:01 AM
    •  

Answers

  • Saturday, November 07, 2009 1:00 AMkaymaf Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    This is simple code to understand, if you Learn XML in vb.net you will understand it

    kaymaf
    If that what you want, take it. If not, ignored it and no complain
    • Marked As Answer byShariqDON Saturday, November 07, 2009 3:41 AM
    •  
  • Saturday, November 07, 2009 3:37 AMCrazypennie Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code


    ShariqDON,

    This code can not be simplify, remove a line and it dont work.

     Here is my code with more comments


    Public Class Form1
        ' Here I put a dataset in the application 
        Dim DtaSet As New DataSet
    
        ' Here I put a datadridview in the applidacion
        Dim WithEvents DGrid As New DataGridView
    
        ' Here I put a button in the applidacion
        Dim WithEvents button1 As New Button
    
        ' Here I put a data table in the applidacion
        Dim Tbl As New DataTable
    
        ' Here I create a variable to hold the path to save the data
        Public PathName As String = "C:\Tst\"
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            'This is to get the form to be 600 x 700
            'And to be at the location 10,10 on the screen
            Me.Size = New Size(600, 700)
            Me.Location = New Point(10, 10)
            Me.StartPosition = FormStartPosition.Manual
    
            ' This is to get the datadrid view size 400 x 600
            DGrid.Width = 400
            DGrid.Height = 600
    
            'This is to put the datagridview on the form
            Me.Controls.Add(DGrid)
    
            ' this tell that the datagridview will show the data that is the table tbl
            DGrid.DataSource = Tbl
    
            'This you will study that on your own
            'It is a collection of datatable that help on the management 
            'of your data. It is use here to automaticaly put the data that is
            'the datatable in the datagridview, and also, each time that you
            'will make a change in the datagridview, it will update the datatable.
            DtaSet.Tables.Add(Tbl)
    
            'For a table to be a table, it has to be some column
            'so I created some here.
            'a datatable has an unlimited number of row. they are 
            ' created so the data fits in it
            Tbl.Columns.Add("Items")
            Tbl.Columns.Add("Description")
            Tbl.Columns.Add("Value")
            Tbl.Columns.Add("Total")
            Tbl.Columns.Add("Extra1")
            Tbl.Columns.Add("Extra2")
            Tbl.Columns.Add("Extra3")
    
            ' Here I put a button for you to save the data
            button1.Location = New Point(440, 600)
            button1.Text = "Save Data"
            Me.Controls.Add(button1)
    
            'This does create the directory that I put in PathName if it does not exist
            If Not IO.Directory.Exists(PathName) Then  'If it don't exist
                IO.Directory.CreateDirectory(PathName) 'Create a new directory for the database 
            End If
    
            'This does load the data that is in the XML file into the datatable.
            'If the file does not exist it create it.
            'So, If you are following, once this will have put the data from the file
            'into the data table, the dataset will automaticaly put the data into the 
            'datagridview because you have code upthere 'Dgrid.datasource=Tbl'
            If IO.File.Exists(PathName & "Main.xml") Then
                Tbl.ReadXml(PathName & "Main.xml") 'Load existing data if exist 
            Else
                Tbl.WriteXml(PathName & "Main.xml") 'If dont exist, create it
            End If
        End Sub
    
        'So now that the datagridview is populated, you are making any change 
        'that you want in it and the dataset does update the datatable for you
    
    
        'Now, you want to save. you press the button. and save the table
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
            Tbl.WriteXml(PathName & "Main.xml")
        End Sub
    End Class
    
    • Marked As Answer byShariqDON Saturday, November 07, 2009 3:41 AM
    •  
  • Saturday, November 07, 2009 1:10 AMShariqDON Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Yes You alright But If this Code is simplify Then i m able to Understad it More then Before

    i Have Problem with Drage and Drop DataSet tool And DataTable tool

    Just helpme to make it Simplify

    By The way I Already Start Learning About DATABASE Stuff...


    Thanks you

    www.shariqdon.media.officelive.com
    • Marked As Answer byShariqDON Saturday, November 07, 2009 3:41 AM
    •  
  • Saturday, November 07, 2009 3:42 AMCrazypennie Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    ShariqDON,

    Just another comment,

    You can figure out how to code many things intuitively, but not the database, you have to read and study.

    And there is a lot to learn.
    • Marked As Answer byShariqDON Saturday, November 07, 2009 11:44 AM
    •  

All Replies

  • Saturday, November 07, 2009 1:00 AMkaymaf Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    This is simple code to understand, if you Learn XML in vb.net you will understand it

    kaymaf
    If that what you want, take it. If not, ignored it and no complain
    • Marked As Answer byShariqDON Saturday, November 07, 2009 3:41 AM
    •  
  • Saturday, November 07, 2009 1:10 AMShariqDON Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Yes You alright But If this Code is simplify Then i m able to Understad it More then Before

    i Have Problem with Drage and Drop DataSet tool And DataTable tool

    Just helpme to make it Simplify

    By The way I Already Start Learning About DATABASE Stuff...


    Thanks you

    www.shariqdon.media.officelive.com
    • Marked As Answer byShariqDON Saturday, November 07, 2009 3:41 AM
    •  
  • Saturday, November 07, 2009 3:37 AMCrazypennie Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code


    ShariqDON,

    This code can not be simplify, remove a line and it dont work.

     Here is my code with more comments


    Public Class Form1
        ' Here I put a dataset in the application 
        Dim DtaSet As New DataSet
    
        ' Here I put a datadridview in the applidacion
        Dim WithEvents DGrid As New DataGridView
    
        ' Here I put a button in the applidacion
        Dim WithEvents button1 As New Button
    
        ' Here I put a data table in the applidacion
        Dim Tbl As New DataTable
    
        ' Here I create a variable to hold the path to save the data
        Public PathName As String = "C:\Tst\"
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            'This is to get the form to be 600 x 700
            'And to be at the location 10,10 on the screen
            Me.Size = New Size(600, 700)
            Me.Location = New Point(10, 10)
            Me.StartPosition = FormStartPosition.Manual
    
            ' This is to get the datadrid view size 400 x 600
            DGrid.Width = 400
            DGrid.Height = 600
    
            'This is to put the datagridview on the form
            Me.Controls.Add(DGrid)
    
            ' this tell that the datagridview will show the data that is the table tbl
            DGrid.DataSource = Tbl
    
            'This you will study that on your own
            'It is a collection of datatable that help on the management 
            'of your data. It is use here to automaticaly put the data that is
            'the datatable in the datagridview, and also, each time that you
            'will make a change in the datagridview, it will update the datatable.
            DtaSet.Tables.Add(Tbl)
    
            'For a table to be a table, it has to be some column
            'so I created some here.
            'a datatable has an unlimited number of row. they are 
            ' created so the data fits in it
            Tbl.Columns.Add("Items")
            Tbl.Columns.Add("Description")
            Tbl.Columns.Add("Value")
            Tbl.Columns.Add("Total")
            Tbl.Columns.Add("Extra1")
            Tbl.Columns.Add("Extra2")
            Tbl.Columns.Add("Extra3")
    
            ' Here I put a button for you to save the data
            button1.Location = New Point(440, 600)
            button1.Text = "Save Data"
            Me.Controls.Add(button1)
    
            'This does create the directory that I put in PathName if it does not exist
            If Not IO.Directory.Exists(PathName) Then  'If it don't exist
                IO.Directory.CreateDirectory(PathName) 'Create a new directory for the database 
            End If
    
            'This does load the data that is in the XML file into the datatable.
            'If the file does not exist it create it.
            'So, If you are following, once this will have put the data from the file
            'into the data table, the dataset will automaticaly put the data into the 
            'datagridview because you have code upthere 'Dgrid.datasource=Tbl'
            If IO.File.Exists(PathName & "Main.xml") Then
                Tbl.ReadXml(PathName & "Main.xml") 'Load existing data if exist 
            Else
                Tbl.WriteXml(PathName & "Main.xml") 'If dont exist, create it
            End If
        End Sub
    
        'So now that the datagridview is populated, you are making any change 
        'that you want in it and the dataset does update the datatable for you
    
    
        'Now, you want to save. you press the button. and save the table
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
            Tbl.WriteXml(PathName & "Main.xml")
        End Sub
    End Class
    
    • Marked As Answer byShariqDON Saturday, November 07, 2009 3:41 AM
    •  
  • Saturday, November 07, 2009 3:42 AMCrazypennie Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    ShariqDON,

    Just another comment,

    You can figure out how to code many things intuitively, but not the database, you have to read and study.

    And there is a lot to learn.
    • Marked As Answer byShariqDON Saturday, November 07, 2009 11:44 AM
    •  
  • Saturday, November 07, 2009 5:19 AMbdbodger Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    What is an applidacion ?

    coding for fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
  • Saturday, November 07, 2009 11:44 AMShariqDON Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    What is an applidacion ?

    coding for fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .

    This is Simple DATABBASE Application
    www.shariqdon.media.officelive.com
  • Saturday, November 07, 2009 12:22 PMCrazypennie Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    What is an applidacion ?

    coding for fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .

    An applidacion is a something that means that it is late and time to go to bed