Search the web
Sign In
New User? Sign Up
helpwithvb · A group for those who need help with Visual Basic
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Help with constructors and elementary OOP   Message List  
Reply | Forward Message #22038 of 22565 |
RE: [helpwithvb] Help with constructors and elementary OOP

Bob,

 

You may want to grab a copy of this book and check out chapter 5 for a coverage of constructors and more in designing encapsulated classes.

 

http://www.free-ebooks-download.org/free-ebook/dotnet/VB.NET/pro-vb-2008-and-the--net-3-5-platform.php

 

/tr

 

 

From: helpwithvb@yahoogroups.com [mailto:helpwithvb@yahoogroups.com] On Behalf Of Robert Dade
Sent: Monday, July 06, 2009 11:46 AM
To: helpwithvb@yahoogroups.com
Subject: [helpwithvb] Help with constructors and elementary OOP

 




Hello

I am a novice programmer who is doing an Open University [UK] degree level unit [for fun] on object oriented programming with VB Express Edition 2008.

I am trying to get my head around a number of ideas right now, the main ones at present being:
Constructors, what do they do, how, when and where to use them.

 

MY PROGRAM

I have a very small program with one form that allows me to populate a list and then to see those items appear in a list box on a form.

The form's controls consist of :

addNewNumberButton – please see the code  below.

addNewNumberTextBox: where I type in a string, in this case a number but it could be any string , to be added to the list, and then to the list box on the form.

 
numberListBox where the strings I type in to addNewNumberTextBox appear.

 

Here is the form’s code:

Public Class Form1
    Private numberList As List(Of String)
    Public Sub New()
        numberList = New List(Of String)

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

    End Sub

 

    Private Sub addNewNumberButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addNewNumberButton.Click

        numberList.Add(addNewNumberTextBox.Text)
        addNewNumberTextBox.Clear()
        addNewNumberTextBox.Focus()
        updateView()

    End Sub

    Private Sub updateView()
        numberListBox.Items.Clear()
        For Each digit As String In numberList
            numberListBox.Items.Add(digit)

        Next
    End Sub
End Class

 

I also have an empty class called Lists_AddNumber.

 

MY FIRST PROBLEM

What I want to do is to use the class Lists_AddNumber to contain the code [that currently operates in the form’s code] which sets up a list to accept strings in exactly the same way that the form’s code does.

I would be grateful for an idiot-proof solution to this problem.

MY SECOND PROBLEM

Can anyone please give me some absolutely elementary guidance as to

    1. What a constructor is [in VB 2008] and what does it do?
    2. Where do you use it – in the form file or in a separate class file?
    3. What is the syntax of a constructor?

 

Best wishes to all you clever folks out there.

Hope that you can point me in the right direction.

Many thanks.

Bob Dade





Mon Jul 6, 2009 5:45 pm

timrupp804
Offline Offline
Send Email Send Email

Forward
Message #22038 of 22565 |
Expand Messages Author Sort by Date

Hello I am a novice programmer who is doing an Open University [UK] degree level unit [for fun] on object oriented programming with VB Express Edition 2008. I...
Robert Dade
rwdade
Offline Send Email
Jul 6, 2009
3:45 pm

Bob, You may want to grab a copy of this book and check out chapter 5 for a coverage of constructors and more in designing encapsulated classes. ...
Timothy Rupp
timrupp804
Offline Send Email
Jul 6, 2009
5:46 pm

Hi Bob: MY FIRST PROBLEM What I want to do is to use the class Lists_AddNumber to contain the code [that currently operates in the form's code] which sets up a...
Neiger, Bruce D
thezorch
Offline Send Email
Jul 6, 2009
8:53 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help