Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading Assembly & Form Communication

Status
Not open for further replies.

0CODE

Programmer
Feb 8, 2004
63
CA
1) THIS IS A CLASS, HOW WOULD I READ THESE PROPERTIES FROM IT (EX: MSGBOX(assem.copyright)) to get that property

===========================================================

Imports System.Reflection

Public Class Assem

Public ReadOnly Property ProjectDescription()
Get
Dim asm As AssemblyDescriptionAttribute
asm = Attribute.GetCustomAttribute([Assembly].GetExecutingAssembly, GetType(AssemblyDescriptionAttribute))
Return asm.Description
End Get
End Property

Public ReadOnly Property Copyright()
Get
Dim asm As AssemblyCopyrightAttribute
asm = Attribute.GetCustomAttribute([Assembly].GetExecutingAssembly, GetType(AssemblyCopyrightAttribute))
Return asm.Copyright
End Get
End Property

Public ReadOnly Property Company()
Get
Dim asm As AssemblyCompanyAttribute
asm = Attribute.GetCustomAttribute([Assembly].GetExecutingAssembly, GetType(AssemblyCompanyAttribute))
Return asm.Company
End Get
End Property

Public ReadOnly Property Title()
Get
Dim asm As AssemblyTitleAttribute
asm = Attribute.GetCustomAttribute([Assembly].GetExecutingAssembly, GetType(AssemblyTitleAttribute))
Return asm.Title
End Get
End Property

Public ReadOnly Property Trademark()
Get
Dim asm As AssemblyTrademarkAttribute
asm = Attribute.GetCustomAttribute([Assembly].GetExecutingAssembly, GetType(AssemblyTrademarkAttribute))
Return asm.Trademark
End Get
End Property

Public ReadOnly Property VersionMajor()
Get
Dim Ver As [Assembly]
Return Ver.GetExecutingAssembly().GetName().Version.Major
End Get
End Property

Public ReadOnly Property VersionMinor()
Get
Dim Ver As [Assembly]
Return Ver.GetExecutingAssembly().GetName().Version.Minor
End Get
End Property

Public ReadOnly Property VersionBuild()
Get
Dim Ver As [Assembly]
Return Ver.GetExecutingAssembly().GetName().Version.Build
End Get
End Property

Public ReadOnly Property VersionRevision()
Get
Dim Ver As [Assembly]
Return Ver.GetExecutingAssembly().GetName().Version.Revision
End Get
End Property

Public ReadOnly Property Version()
Get
Dim p_VerMajor, p_VerMinor, p_Build, p_Revision As String

Dim Ver As [Assembly]
p_VerMajor = Ver.GetExecutingAssembly().GetName().Version.Major
p_VerMinor = Ver.GetExecutingAssembly().GetName().Version.Minor
p_Build = Ver.GetExecutingAssembly().GetName().Version.Build
p_Revision = Ver.GetExecutingAssembly().GetName().Version.Revision

Return p_VerMajor & "." & p_VerMinor & "." & p_Build & "." & p_Revision
End Get
End Property

Public Sub Dispose()
Me.Dispose()
End Sub

End Class

===========================================================



2)I have a few forms on this project, and for the startup form I placed this code in the auto generated code region:

================

Public Sub New()
MyBase.New()

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

cstart = Me
'Add any initialization after the InitializeComponent() call

End Sub

=================

This is the first procedure in the auto generated code*
and as you can see I added "cstart = me", and on a class I have i set "Public cstart As fstart" because fstart is the startup form and I cant set "cstart" to equal a "new fstart" since it wont be opened by any command like (cstart.show). Anyway this works fine and I can communicate
between this form on other forms, but on the class where I declared "Public cstart As fstart" i also have this line of code:

"Public listfonta As New Font(cstart.contactl.Font, FontStyle.Regular)"

and as you can see it is getting a property from the startup form which is set it to equal "me" on the line I added in the auto-gen code. The problem is that the class with the "listfonta" variable and the other code executes before the auto-gen code does for the startup form, and this creates an error when its trying to set the "listfonta" variable since "cstart" isn't set to anything yet. Is there any way to make it excecute the code on the class after the auto-gen code on the startup form, or possible change the orded of which forms / classes excecute? and is there some set order defaultedly that the forms / classes excecute?
_________
thanks
 
1. You instantiate it first by dimming a variable of that type, and then setting it to a new instance (using the "new" keyword). You then just call the property/method that you want.

2. Similar answer - you need to instantiate it before you are able to call your form.

This is the VB.NET language specification:
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/vbls7/html/vblrfVBSpec9_6.htm

and this is the VB language concepts for the New keyword:
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/vbcn7/html/vaconUsingNewKeyword.htm

Just cut & paste those lines into your help browser.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
The solution for the 1st one works great, thanks alot. But when I copy/paste the link

"ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/vbls7/html/vblrfVBSpec9_6.htm"

(VB.NET one) it does not find the html page. I am using VB.NET 2002 and I have the 5 CD package.
 
[tt]Sorry, I'm on VS.NET 2003, and that link must be different on the 2002 edition.

Here's the info from MSDN:
=======================[/tt]
The New operator is used to create new instances of types. There are three forms of New expressions: [ul][li]Object-creation expressions are used to create a new instances of class types and value types.[/li]
[li]Array-creation expressions are used to create new instances of array types. [/li]
[li]Delegate-creation expressions are used to create new instances of delegate types. [/li][/ul]The New operator implies creation of an instance of a type, but does not necessarily imply dynamic allocation of memory. In particular, instances of value types require no additional memory beyond the variables in which they reside, and no dynamic allocations occur when New is used to create instances of value types.

NewExpression ::=
ObjectCreationExpression |
ArrayCreationExpression |
DelegateCreationExpression


[tt]=============================
In your case, you are doing Object Creation:
=============================[/tt]
An object-creation expression is used to create a new instance of a class type or a structure type. The type of an object creation expression must be a class type or a structure type and cannot be a MustInherit class. Given an object creation expression of the form New T(A), where T is a class type or structure type and A is an optional argument list, overload resolution determines the correct constructor of T to call. If no constructor is callable, a compile-time error occurs; otherwise the expression results in the creation of a new instance of T using the chosen constructor. If there are no arguments, the parentheses may be omitted.

ObjectCreationExpression ::= New TypeName [ ( [ ArgumentList ] ) ]


[tt]===========================
Hope this helps.

Chip H.
[/tt]

If you want to get the best response to a question, please check out FAQ222-2244 first
 
looks good but im just a bit confused how all that works, what would i specificly need to do in order to fix my problem, which i mentioned in my 1st thread.

thanks
 
Just because you've declared a class doesn't mean that you've allocated any memory for it. You do that through the New keyword.
Code:
Dim myAssem As New Assem

Console.writeline(myAssem.Title)
myAssem.Dispose
myAssem = Nothing

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
where would i add this code, and would this fix the problem that the form hasn't loaded before the variable dimmed in the module is declared?

thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top