PC Review


Reply
Thread Tools Rate Thread

How to create a Public Form property

 
 
Sarah Smith
Guest
Posts: n/a
 
      1st Mar 2004
Hello,

I've been trying to create a public property on one form that is
"Setable" from another form.

I have a Sub Main() which creates 2 public instances of the two forms
that make up the project and then loads the first main form using
ShowDialog.

The menu on this form lets you display the second form.

From the second form, I'd like to be able to set a property I've added
to the first form and then close the second form.

(This is a database detail/list view.)

I have created the property in the first form like this:

Public Property intRecordNumber() As Integer

Get
intRecordNumber = intSelectedRow
End Get

Set(ByVal Value As Integer)
nRecord = Value
Call DisplayRecord()
End Set

End Property

VS complains that I am making a reference to a "non-shared member" but
both frmMain and frmListView were declared publicly in the code module
that contains Sub Main().

Can anyone help??

SS.
 
Reply With Quote
 
 
 
 
William Ryan eMVP
Guest
Posts: n/a
 
      1st Mar 2004
Sarah:

Are either intRecordNumber or nRecord declared as shared?
"Sarah Smith" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
>
> I've been trying to create a public property on one form that is
> "Setable" from another form.
>
> I have a Sub Main() which creates 2 public instances of the two forms
> that make up the project and then loads the first main form using
> ShowDialog.
>
> The menu on this form lets you display the second form.
>
> From the second form, I'd like to be able to set a property I've added
> to the first form and then close the second form.
>
> (This is a database detail/list view.)
>
> I have created the property in the first form like this:
>
> Public Property intRecordNumber() As Integer
>
> Get
> intRecordNumber = intSelectedRow
> End Get
>
> Set(ByVal Value As Integer)
> nRecord = Value
> Call DisplayRecord()
> End Set
>
> End Property
>
> VS complains that I am making a reference to a "non-shared member" but
> both frmMain and frmListView were declared publicly in the code module
> that contains Sub Main().
>
> Can anyone help??
>
> SS.



 
Reply With Quote
 
Sarah Smith
Guest
Posts: n/a
 
      1st Mar 2004


intRecordNumber is the property I've added to a form - FrmMain - and
I'm trying to make publicly available to other forms.

Like this:

Public Property intRecordNumber() As Integer


nRecord is a form level variable in the form with the property which
should be given a value in the property Set method:

Set(ByVal Value As Integer)
nRecord = Value
Call DisplayRecord()
End Set

Here's the code again:

Public Property intRecordNumber() As Integer

Get
intRecordNumber = intSelectedRow
End Get

Set(ByVal Value As Integer)
nRecord = Value
Call DisplayRecord()
End Set

End Property

I'm used to VB6, so I'm not sure about "Shared" properties or
variables ...

SS.

On Mon, 1 Mar 2004 08:46:42 -0500, "William Ryan eMVP"
<(E-Mail Removed)> wrote:

>Sarah:
>
>Are either intRecordNumber or nRecord declared as shared?
>"Sarah Smith" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>> Hello,
>>
>> I've been trying to create a public property on one form that is
>> "Setable" from another form.
>>
>> I have a Sub Main() which creates 2 public instances of the two forms
>> that make up the project and then loads the first main form using
>> ShowDialog.
>>
>> The menu on this form lets you display the second form.
>>
>> From the second form, I'd like to be able to set a property I've added
>> to the first form and then close the second form.
>>
>> (This is a database detail/list view.)
>>
>> I have created the property in the first form like this:
>>
>> Public Property intRecordNumber() As Integer
>>
>> Get
>> intRecordNumber = intSelectedRow
>> End Get
>>
>> Set(ByVal Value As Integer)
>> nRecord = Value
>> Call DisplayRecord()
>> End Set
>>
>> End Property
>>
>> VS complains that I am making a reference to a "non-shared member" but
>> both frmMain and frmListView were declared publicly in the code module
>> that contains Sub Main().
>>
>> Can anyone help??
>>
>> SS.

>


 
Reply With Quote
 
Chris Tacke, eMVP
Guest
Posts: n/a
 
      1st Mar 2004
These look fine. Can you show the Main() code where you create the Form
instances and try to set the properties?

--
Chris Tacke, eMVP
Co-Founder and Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net


"Sarah Smith" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
>
> intRecordNumber is the property I've added to a form - FrmMain - and
> I'm trying to make publicly available to other forms.
>
> Like this:
>
> Public Property intRecordNumber() As Integer
>
>
> nRecord is a form level variable in the form with the property which
> should be given a value in the property Set method:
>
> Set(ByVal Value As Integer)
> nRecord = Value
> Call DisplayRecord()
> End Set
>
> Here's the code again:
>
> Public Property intRecordNumber() As Integer
>
> Get
> intRecordNumber = intSelectedRow
> End Get
>
> Set(ByVal Value As Integer)
> nRecord = Value
> Call DisplayRecord()
> End Set
>
> End Property
>
> I'm used to VB6, so I'm not sure about "Shared" properties or
> variables ...
>
> SS.
>
> On Mon, 1 Mar 2004 08:46:42 -0500, "William Ryan eMVP"
> <(E-Mail Removed)> wrote:
>
> >Sarah:
> >
> >Are either intRecordNumber or nRecord declared as shared?
> >"Sarah Smith" <(E-Mail Removed)> wrote in message
> >news:(E-Mail Removed)...
> >> Hello,
> >>
> >> I've been trying to create a public property on one form that is
> >> "Setable" from another form.
> >>
> >> I have a Sub Main() which creates 2 public instances of the two forms
> >> that make up the project and then loads the first main form using
> >> ShowDialog.
> >>
> >> The menu on this form lets you display the second form.
> >>
> >> From the second form, I'd like to be able to set a property I've added
> >> to the first form and then close the second form.
> >>
> >> (This is a database detail/list view.)
> >>
> >> I have created the property in the first form like this:
> >>
> >> Public Property intRecordNumber() As Integer
> >>
> >> Get
> >> intRecordNumber = intSelectedRow
> >> End Get
> >>
> >> Set(ByVal Value As Integer)
> >> nRecord = Value
> >> Call DisplayRecord()
> >> End Set
> >>
> >> End Property
> >>
> >> VS complains that I am making a reference to a "non-shared member" but
> >> both frmMain and frmListView were declared publicly in the code module
> >> that contains Sub Main().
> >>
> >> Can anyone help??
> >>
> >> SS.

> >

>



 
Reply With Quote
 
William Ryan eMVP
Guest
Posts: n/a
 
      1st Mar 2004
Sarah:

This compiles fine for me:

Private nRecord As Integer
Private intSelectedRow As Integer

Public Property intRecordNumber() As Integer
Get
Return intSelectedRow
End Get
Set(ByVal Value As Integer)
nRecord = Value
Call DisplayRecord()
End Set
End Property
Private Sub DisplayRecord()
'Do something in here which sets the value of intSelectedRow
End Sub

However, you may want to opt for something a little more traditional..

Private nRecord As Integer
Private intSelectedRow As Integer

Public Property RecordNumber() As Integer
Get
Return nRecord
End Get
Set(ByVal Value As Integer)
nRecord = Value
End Set
End Property

Syntactically everything looks good unless you have Private Shared Property
or something like that...
"Sarah Smith" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
>
> intRecordNumber is the property I've added to a form - FrmMain - and
> I'm trying to make publicly available to other forms.
>
> Like this:
>
> Public Property intRecordNumber() As Integer
>
>
> nRecord is a form level variable in the form with the property which
> should be given a value in the property Set method:
>
> Set(ByVal Value As Integer)
> nRecord = Value
> Call DisplayRecord()
> End Set
>
> Here's the code again:
>
> Public Property intRecordNumber() As Integer
>
> Get
> intRecordNumber = intSelectedRow
> End Get
>
> Set(ByVal Value As Integer)
> nRecord = Value
> Call DisplayRecord()
> End Set
>
> End Property
>
> I'm used to VB6, so I'm not sure about "Shared" properties or
> variables ...
>
> SS.
>
> On Mon, 1 Mar 2004 08:46:42 -0500, "William Ryan eMVP"
> <(E-Mail Removed)> wrote:
>
> >Sarah:
> >
> >Are either intRecordNumber or nRecord declared as shared?
> >"Sarah Smith" <(E-Mail Removed)> wrote in message
> >news:(E-Mail Removed)...
> >> Hello,
> >>
> >> I've been trying to create a public property on one form that is
> >> "Setable" from another form.
> >>
> >> I have a Sub Main() which creates 2 public instances of the two forms
> >> that make up the project and then loads the first main form using
> >> ShowDialog.
> >>
> >> The menu on this form lets you display the second form.
> >>
> >> From the second form, I'd like to be able to set a property I've added
> >> to the first form and then close the second form.
> >>
> >> (This is a database detail/list view.)
> >>
> >> I have created the property in the first form like this:
> >>
> >> Public Property intRecordNumber() As Integer
> >>
> >> Get
> >> intRecordNumber = intSelectedRow
> >> End Get
> >>
> >> Set(ByVal Value As Integer)
> >> nRecord = Value
> >> Call DisplayRecord()
> >> End Set
> >>
> >> End Property
> >>
> >> VS complains that I am making a reference to a "non-shared member" but
> >> both frmMain and frmListView were declared publicly in the code module
> >> that contains Sub Main().
> >>
> >> Can anyone help??
> >>
> >> SS.

> >

>



 
Reply With Quote
 
Sarah Smith
Guest
Posts: n/a
 
      1st Mar 2004
On Mon, 1 Mar 2004 10:01:11 -0500, "Chris Tacke, eMVP"
<(E-Mail Removed)> wrote:

>These look fine. Can you show the Main() code where you create the Form
>instances and try to set the properties?


Hi,

Thanks for looking at this.

I have a code module with Sub Main() and this is the startup object
for the project:

Public FrmMain As New FrmMain
Public frmList As New frmListView


Public Sub Main()

FrmMain.ShowDialog() 'show the main form


End Sub


FrmMain has a menu, which displays the frmListView form (with a grid
attached to a DataView object. (This works fine).

I want to be able to select a row in the grid, then tap a button
'select' to close the List form and return to the detailed form
(FrmMain) - and go to the selected record.

I thought if I created a public property, I could 'Set' the record
number and call a sub routine to locate and display the record.

Something like:

FrmMain.intSelectedRow = intRow
Me.Close() 'close the list view form


SS.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I create a form for leasing property? D Microsoft Word Document Management 1 19th Feb 2009 04:18 PM
Passing value through to another form using public property Richard Microsoft VB .NET 2 28th Jul 2005 03:08 AM
Windows Form Control public property not shown in intellisense. =?Utf-8?B?SmFtZXMgTGk=?= Microsoft Dot NET Framework Forms 0 8th Feb 2005 04:03 AM
reference a public property in another Form? nick Microsoft Dot NET Framework Forms 1 28th Oct 2004 05:02 AM
create/use form event/property to validate txtEntry Rich Microsoft VB .NET 7 12th Feb 2004 04:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:33 AM.