Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Declaring variables from class

Declaring variables from class

Scheduled Pinned Locked Moved Visual Basic
helptutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    harrysk
    wrote on last edited by
    #1

    Hello, Ive got the following problem: I don't know how to create a NEW member everytime i click the button. I've got: Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click Dim Mem1 As New Member Mem1.Title = Me.cmbTitle.Text Mem1.Forename = Me.tbForename.Text Mem1.Surname = Me.tbSurname.Text Mem1.Address = Me.tbAddress.Text Mem1.Town = Me.tbTown.Text Mem1.Postcode = Me.tbPostcode.Text Mem1.DateOfBirth = Me.tbDob.Text Mem1.Telephone = Me.tbNumber.Text Mem1.CustomerID = Me.tbID.Text End Sub But it doesn't create anew member each time?????:(( Any help will be much appreciated.

    D 1 Reply Last reply
    0
    • H harrysk

      Hello, Ive got the following problem: I don't know how to create a NEW member everytime i click the button. I've got: Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click Dim Mem1 As New Member Mem1.Title = Me.cmbTitle.Text Mem1.Forename = Me.tbForename.Text Mem1.Surname = Me.tbSurname.Text Mem1.Address = Me.tbAddress.Text Mem1.Town = Me.tbTown.Text Mem1.Postcode = Me.tbPostcode.Text Mem1.DateOfBirth = Me.tbDob.Text Mem1.Telephone = Me.tbNumber.Text Mem1.CustomerID = Me.tbID.Text End Sub But it doesn't create anew member each time?????:(( Any help will be much appreciated.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Of course not. All you did was create a Member object, called it Mem1, set a bunch of properties on it, then forgot about when the Sub finished. What are you trying to save this object in? You don't have any code in here to save the object anywhere. You need to store the object somewhere, like in a collection, that was created outside this function you posted. Currently, the Member object you created only exists inside this function. For instance, if you wanted to create a new TextBox control on a form you could:

      Private Sub btnNewTextBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewTextBox.Click
      Dim myNewTextBox As New TextBox
      myNewTextBox.Text = "Some text..."
      End Sub

      Just like you did with your Member object. But, you'll never see this TextBox to be able to do anything with it because at the end of the function, the new object is detroyed because nothing outside this function can get to it. What you need to do is add it to a collection that was created outside this function. In my example, its the form's Controls collection:

      Private Sub btnNewTextBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewTextBox.Click
      Dim myNewTextBox As New TextBox
      myNewTextBox.Text = "Some text..."
      Me.Controls.Add(myNewTextBox)
      End Sub

      RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      H 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Of course not. All you did was create a Member object, called it Mem1, set a bunch of properties on it, then forgot about when the Sub finished. What are you trying to save this object in? You don't have any code in here to save the object anywhere. You need to store the object somewhere, like in a collection, that was created outside this function you posted. Currently, the Member object you created only exists inside this function. For instance, if you wanted to create a new TextBox control on a form you could:

        Private Sub btnNewTextBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewTextBox.Click
        Dim myNewTextBox As New TextBox
        myNewTextBox.Text = "Some text..."
        End Sub

        Just like you did with your Member object. But, you'll never see this TextBox to be able to do anything with it because at the end of the function, the new object is detroyed because nothing outside this function can get to it. What you need to do is add it to a collection that was created outside this function. In my example, its the form's Controls collection:

        Private Sub btnNewTextBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewTextBox.Click
        Dim myNewTextBox As New TextBox
        myNewTextBox.Text = "Some text..."
        Me.Controls.Add(myNewTextBox)
        End Sub

        RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        H Offline
        H Offline
        harrysk
        wrote on last edited by
        #3

        how would i do this if i am to create more members from the same control??? i'm new to this.

        D 1 Reply Last reply
        0
        • H harrysk

          how would i do this if i am to create more members from the same control??? i'm new to this.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Same thing. Create the new member and add it to a collection that's been created outside the function your creating the new member in. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups