public variable not public

  • Thread starter Laurence Nuttall
  • Start date
L

Laurence Nuttall

I have a class, and a public varible defined in one of the
..VB files of that class.

I also have a form in that class, but I cannot
reference the variable in the class from the form,
even though the form is in the class.

Thanks in Advance,

Laurence Nuttall
Programmer Analyst III
UCLA - Division of Continuing Education
 
B

Bernie Yaeger

Hi Laurence,

Show us some code - it should be simple to access the variable you refer to.

Bernie Yaeger
 
R

Richard

A riddle, wrapped in a mystery inside an enigma.
Sorry Laurence you might have to post again.
I cant work out what your saying.
I have a class, and a public varible defined in one of the
.VB files of that class.

Generally you only have one .vb file per class. In fact i thought you
could ONLY have 1 vb file per class. How many do you have?
I also have a form in that class, but I cannot
reference the variable in the class from the form,
even though the form is in the class.

A form is a class. Is that what you mean? You wouldn't declare a form
inside another class, i dont see when nesting in way would make sense
and i know the designer would throw a hissy.

Post a little code, or check your namespaces and the scope on your
Class with the public variable.

hth
Richard
 
L

Laurence Nuttall

Here is the code,

'----------------------------------------------------------------------------

Public Class AboutBox

Public Title As String
Private Enum FadeDirection
FadeIn = 1
FadeOut = 2
End Enum

Private TheFadeDirection As FadeDirection


Public Sub New()

End Sub

Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub

Public Sub ShowAbout(ByVal TheApp As System.Diagnostics.FileVersionInfo)

Dim frmAboutObj As New frmAbout

With frmAboutObj
.lblProductName.Text = TheApp.ProductName
.lblCompanyName.Text = TheApp.CompanyName
.lblVersion.Text = TheApp.ProductVersion
.lblComment.Text = TheApp.Comments
.lblFileDescription.Text = TheApp.FileDescription
.lblExeName.Text = TheApp.FileName
.lblLegalCopyright.Text = TheApp.LegalCopyright()
.Text = Title
TheFadeDirection = FadeDirection.FadeIn
.Show()
.tmrFade.Enabled = True
End With

End Sub
End Class

'-------------------------------------------------------------------------------------------------



The FadeDirection cannot be seen from a form in the class
AboutBox.

Larry

'------------------------------------------------------------------
 
D

Duncan Mackenzie

That is because "TheFadeDirection" is private. You may have declared an
instance of your Form inside the AboutBox class, but frmAbout is still not
*inside* the AboutBox class.... it cannot see private members of another
class like that.
 
R

Richard

Hi Laurence,

This might be a double post. I hit enter and everything went to crap.
If so i cant remember where i was so i'll reply again. Its late so im
just going to do a code dump of what i think you want.

1. Remove the Enum from ur class and define it separately

Public Enum FadeDirection As Integer
FadeIn = 1
FadeOut = 2
End Enum

2. We're going to gut AboutBox, it does nothing. Put the following
into frmAbout

Private _fadeDirection As FadeDirection

Property FadeDirection() As FadeDirection
Get
Return _fadeDirection
End Get
Set(ByVal Value As FadeDirection)
_fadeDirection = Value
End Set
End Property


3. Change frmAbout Constructor to whats below plus what you have for
it:

Public Sub New(ByVal TheApp As
System.Diagnostics.FileVersionInfo, ByVal fadeDirection As
FadeDirection, Title as String)

MyBase.New()
InitializeComponent()

With Me
.lblProductName.Text = TheApp.ProductName
.lblCompanyName.Text = TheApp.CompanyName
.lblVersion.Text = TheApp.ProductVersion
.lblComment.Text = TheApp.Comments
.lblFileDescription.Text = TheApp.FileDescription
.lblExeName.Text = TheApp.FileName
.lblLegalCopyright.Text = TheApp.LegalCopyright()
.Text = Title
.FadeDirection = fadeDirection
.tmrFade.Enabled = True
End With

End Sub

4. Do this whereever you need too
Dim frmAboutObj As New frmAbout(theApp, FadeDirection.FadeIn,
"MyTitle")
frmAboutObj.Show

5. Note im not sure how important ur timing is with
..tmrFade.Enabled = True

thats for you to decide, if u note the diff between original code and
this.

6. Throw away the rest of that AboutBox class. It does nothing.

hth
Richard

*Im going home *
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

public variable not public in class 1
Can't show form in class Library module 2
Pattern Property 4
Capitalize First letter of keywords 1
Call a procedure 3
debug.write 4
An Unhandled Exception 9
ListView Items 3

Top