Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

Is it possibel for me to use the information in the Assembly file everywhere I want?

 

For instance, I wanted to use specially the version number int eh caption on the form and on a label in the about screen and if I change the version number I jsut change in the assembly info and then the caption and lablel would change automatically or when I compile the program they will get the desired values.

 

Is it possible? How can I achieve that?

Posted
But the content of those variables (Application.ProductName and Aplication.ProductVersion) are set where? In the assembly information or should I set them elsewhere?
Posted

Can't make it work...

 

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       frmMain.ActiveForm.Text = Application.ProductName + " v" + Application.ProductVersion
   End Sub

 

I have the above code i my form but I get this error when compiling:

 

 

An unhandled exception of type 'System.NullReferenceException' occurred in Underworld Mines.exe

 

Additional information: Object reference not set to an instance of an object.

 

What's the problem and how should I fix it?

Posted

I still can't make it work...

 

I only have one form in my solution wich is frmMain.vb and then, when the form loads I want it to put on the titlebar the name and version of the application and all the code I have is the following one (part of it, you have already seen):

 

Public Class frmMain
   Inherits System.Windows.Forms.Form

Windows Form Designer generated code

   Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       frmMain.ActiveForm.Text = Application.ProductName + " v" + Application.ProductVersion
   End Sub
End Class

 

I have tried to use Me.Text but can't understand how this works...

  • Administrators
Posted

Under .Net a Form is just a class - you can no longer just refer to the form name, instead you create an instance of the class and assign it to a variable.

If the form in question is the startup object then VB sorts that out for you behind the scenes.

Me as a variable always refers to the current cobject (in this case the instance of frmMain) and Me.Text should set the form's caption. Did you try the me.text? If so was there a problem?

 

You may want to have a look here for a bit more info on working with forms under .Net

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

I worked now...

you see, I typed me.text adn then typed a space and a I got a popup saying: Text () as String and if I pressed Return I would ge automatically () so I thought I had to do something like this: Me.Text ("blablabla") but it wasn't working but now I figured it out I could make it like Me.Text = "blablabla"

 

Another thing, the Application.ProductVersion outputs something like 0.6.0.0 and I ahve this information in the assemblyinfo file: <Assembly: AssemblyVersion("0.6")>

 

How can I make it just to output 0.6??

 

Thanks for everything.

Posted

Use the SubString Method

 

Me.Text  = Application.ProductName + " v" + Application.ProductVersion.SubString(0,3)

"Nobody knows what I do until I stop doing it."
Posted

There's an null object somewhere in your code.

Verify ProductName and ProductVersion. take a look also at ActiveForm so it's not null.

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted
Use the SubString Method

 

Me.Text  = Application.ProductName + " v" + Application.ProductVersion.SubString(0,3)

right..... lol, thanks a lot... I just can't see why I didn't remembered that before...

 

@Arch4ngel

What do u mean? I have barely no code at all...

 

The files I have with code are frmMain.vb and AssemblyInfo.vb and here's the code on each file:

 

frmMain.vb

Public Class frmMain
   Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

   Public Sub New()
       MyBase.New()

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

       'Add any initialization after the InitializeComponent() call

   End Sub

   'Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub

   'Required by the Windows Form Designer
   Private components As System.ComponentModel.IContainer

   'NOTE: The following procedure is required by the Windows Form Designer
   'It can be modified using the Windows Form Designer.  
   'Do not modify it using the code editor.
   Friend WithEvents mnuMain As System.Windows.Forms.MainMenu
   Friend WithEvents mnuFile As System.Windows.Forms.MenuItem
   Friend WithEvents mnuFame As System.Windows.Forms.MenuItem
   Friend WithEvents mnuHelp As System.Windows.Forms.MenuItem
   Friend WithEvents mnuSingle As System.Windows.Forms.MenuItem
   Friend WithEvents mnuMulti As System.Windows.Forms.MenuItem
   Friend WithEvents mnuSettings As System.Windows.Forms.MenuItem
   Friend WithEvents mnuExit As System.Windows.Forms.MenuItem
   Friend WithEvents mnuContents As System.Windows.Forms.MenuItem
   Friend WithEvents mnuReadme As System.Windows.Forms.MenuItem
   Friend WithEvents mnuAbout As System.Windows.Forms.MenuItem
   Friend WithEvents mnuSpace1 As System.Windows.Forms.MenuItem
   Friend WithEvents mnuSpace2 As System.Windows.Forms.MenuItem
   Friend WithEvents mnuSpace3 As System.Windows.Forms.MenuItem
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmMain))
       Me.mnuMain = New System.Windows.Forms.MainMenu
       Me.mnuFile = New System.Windows.Forms.MenuItem
       Me.mnuSingle = New System.Windows.Forms.MenuItem
       Me.mnuMulti = New System.Windows.Forms.MenuItem
       Me.mnuSpace1 = New System.Windows.Forms.MenuItem
       Me.mnuSettings = New System.Windows.Forms.MenuItem
       Me.mnuSpace2 = New System.Windows.Forms.MenuItem
       Me.mnuExit = New System.Windows.Forms.MenuItem
       Me.mnuFame = New System.Windows.Forms.MenuItem
       Me.mnuHelp = New System.Windows.Forms.MenuItem
       Me.mnuContents = New System.Windows.Forms.MenuItem
       Me.mnuReadme = New System.Windows.Forms.MenuItem
       Me.mnuSpace3 = New System.Windows.Forms.MenuItem
       Me.mnuAbout = New System.Windows.Forms.MenuItem
       '
       'mnuMain
       '
       Me.mnuMain.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuFile, Me.mnuFame, Me.mnuHelp})
       '
       'mnuFile
       '
       Me.mnuFile.Index = 0
       Me.mnuFile.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuSingle, Me.mnuMulti, Me.mnuSpace1, Me.mnuSettings, Me.mnuSpace2, Me.mnuExit})
       Me.mnuFile.Text = "&File"
       '
       'mnuSingle
       '
       Me.mnuSingle.Index = 0
       Me.mnuSingle.Text = "&Single Player"
       '
       'mnuMulti
       '
       Me.mnuMulti.Index = 1
       Me.mnuMulti.Text = "&Multi Player"
       '
       'mnuSpace1
       '
       Me.mnuSpace1.Index = 2
       Me.mnuSpace1.Text = "-"
       '
       'mnuSettings
       '
       Me.mnuSettings.Index = 3
       Me.mnuSettings.Text = "&Settings"
       '
       'mnuSpace2
       '
       Me.mnuSpace2.Index = 4
       Me.mnuSpace2.Text = "-"
       '
       'mnuExit
       '
       Me.mnuExit.Index = 5
       Me.mnuExit.Text = "&Exit"
       '
       'mnuFame
       '
       Me.mnuFame.Index = 1
       Me.mnuFame.Text = "H&all of Fame"
       '
       'mnuHelp
       '
       Me.mnuHelp.Index = 2
       Me.mnuHelp.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuContents, Me.mnuReadme, Me.mnuSpace3, Me.mnuAbout})
       Me.mnuHelp.Text = "&Help"
       '
       'mnuContents
       '
       Me.mnuContents.Index = 0
       Me.mnuContents.Text = "&Contents"
       '
       'mnuReadme
       '
       Me.mnuReadme.Index = 1
       Me.mnuReadme.Text = "&Readme"
       '
       'mnuSpace3
       '
       Me.mnuSpace3.Index = 2
       Me.mnuSpace3.Text = "-"
       '
       'mnuAbout
       '
       Me.mnuAbout.Index = 3
       Me.mnuAbout.Text = "About"
       '
       'frmMain
       '
       Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
       Me.BackColor = System.Drawing.SystemColors.Control
       Me.ClientSize = New System.Drawing.Size(459, 264)
       Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
       Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
       Me.MaximizeBox = False
       Me.Menu = Me.mnuMain
       Me.MinimizeBox = False
       Me.Name = "frmMain"
       Me.TransparencyKey = System.Drawing.Color.Red

   End Sub

#End Region

   Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Me.Text = Application.ProductName + " v" + Application.ProductVersion.Substring(0, 3)
   End Sub
End Class

 

AssemblyInfo.vb

Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices

' General Information about an assembly is controlled through the following 
' set of attributes. Change these attribute values to modify the information
' associated with an assembly.

' Review the values of the assembly attributes

<Assembly: AssemblyTitle("Underworld Mines")> 
<Assembly: AssemblyDescription("Just a minesweeper game like the windows one but with a few differences.")> 
<Assembly: AssemblyCompany("Nazgulled")> 
<Assembly: AssemblyProduct("Underworld Mines")> 
<Assembly: AssemblyCopyright("Nazgulled")> 
<Assembly: AssemblyTrademark("")> 
<Assembly: CLSCompliant(True)> 

'The following GUID is for the ID of the typelib if this project is exposed to COM
<Assembly: Guid("087B99D8-2506-4081-AF9B-BF3C9BF3E39C")> 

' Version information for an assembly consists of the following four values:
'
'      Major Version
'      Minor Version 
'      Build Number
'      Revision
'
' You can specify all the values or you can default the Build and Revision Numbers 
' by using the '*' as shown below:

<Assembly: AssemblyVersion("0.6")> 

 

Where's that null object?

Posted

Try a few If Object = Nothing Then

 

 

Me.Text = Application.ProductName + " v" + Application.ProductVersion.SubString(0,3)Maybe it's ProductName or ProductVersion... but something is null somewhere if it throws you a NullException....

 

Am I right or Am I doing some round corner ?

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted
I have the above code i my form but I get this error when compiling:

An unhandled exception of type 'System.NullReferenceException' occurred in Underworld Mines.exe

 

Additional information: Object reference not set to an instance of an object.

What's the problem and how should I fix it?

How do you call that ?

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted

oh that... I forgot about that completly... but nevermind, that was a problem when I was not able to make this -> Me.Text = Application.ProductName + " v" + Application.ProductVersion <- work, now it works fine and that error does not appear anymore...

 

That's why I wasn't following you :P

 

Thanks everyone for the help ;)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...