Reply to topic  [ 24 posts ]  Go to page Previous  1, 2
Learning to program 
Author Message
Spends far too much time on here
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 4876
Location: Newcastle
Reply with quote
EddArmitage wrote:
Sorry, I wasn't being serious. This probably wasn't the thread for it though.


Not really the place ;)

_________________
Twitter
Charlie Brooker:
Macs are glorified Fisher-Price activity centres for adults; computers for scaredy cats too nervous to learn how proper computers work; computers for people who earnestly believe in feng shui.


Mon Jun 07, 2010 1:20 am
Profile
Doesn't have much of a life
User avatar

Joined: Tue May 05, 2009 5:52 pm
Posts: 1899
Reply with quote
EddArmitage wrote:
Having seen it here, it would appear to be something like
Code:
String strVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();


to retrieve the version number as a string.

How would I use that in the code? Pasting it after Version Number gives errors so I am missing something.
What I have at the moment is this:

Code:
 private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {

            MessageBox.Show("Made by james016 \r\nVersion Number:");
        }


Many thanks.

_________________
Image

My Flickr Page

Now with added ball and chain.


Mon Jun 07, 2010 8:31 am
Profile
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 6:36 pm
Posts: 5158
Location: /dev/tty0
Reply with quote
james016 wrote:
EddArmitage wrote:
Having seen it here, it would appear to be something like
Code:
String strVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();


to retrieve the version number as a string.

How would I use that in the code? Pasting it after Version Number gives errors so I am missing something.
What I have at the moment is this:

Code:
 private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {

            MessageBox.Show("Made by james016 \r\nVersion Number:");
        }


Many thanks.


I would have thought:
Code:
 private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            String strVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
            MessageBox.Show("Made by james016 \r\nVersion Number: " + strVersion);
        }


Mon Jun 07, 2010 9:54 am
Profile WWW
Doesn't have much of a life
User avatar

Joined: Tue May 05, 2009 5:52 pm
Posts: 1899
Reply with quote
Thank you Ben

That worked :D

_________________
Image

My Flickr Page

Now with added ball and chain.


Mon Jun 07, 2010 10:23 am
Profile
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 6:36 pm
Posts: 5158
Location: /dev/tty0
Reply with quote
james016 wrote:
Thank you Ben

That worked :D


No problem, I've not done C# before, but after having a look, this is slightly more correct:

Code:
 private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            StringBuilder strVersion = new StringBuilder("Made by james016 \r\nVersion Number: ");
            MyStringBuilder.Append(System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
            MessageBox.Show(strVersion);
        }


Strings in both Java and C# are immutable (i.e. they can't be changed). In the snippet I have you before, the code had to take two Strings and stick them together to create a third String. This is generally bad practise as you're using twice as much memory.
The StringBuilder I've used above has the same effect, but enlarges the amount of memory it uses to accommodate the new text.

EDIT: Sorry James, accidentally posted an opening square bracket at the end there. Also, you may need to include System.Text.StringBuilder
I can't test it as I don't have a C# editor/compiler here...


Last edited by forquare1 on Mon Jun 07, 2010 2:58 pm, edited 1 time in total.



Mon Jun 07, 2010 10:44 am
Profile WWW
Doesn't have much of a life
User avatar

Joined: Tue May 05, 2009 5:52 pm
Posts: 1899
Reply with quote
Unless I am missing something, copying and pasting that code gave me some errors.

On the plus side I managed to make a .msi file for installation. :)

_________________
Image

My Flickr Page

Now with added ball and chain.


Mon Jun 07, 2010 1:09 pm
Profile
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 5288
Location: ln -s /London ~
Reply with quote
james016 wrote:
Unless I am missing something, copying and pasting that code gave me some errors.

I would guess you've copied the opening square bracket after the closing curly brace?

Do you understand what the code is doing/how it works, and how/why using a stringbuilder is better than combining two strings?

_________________
timark_uk wrote:
Gay sex is better than no sex

timark_uk wrote:
Edward Armitage is Awesome. Yes, that's right. Awesome with a A.


Mon Jun 07, 2010 2:07 pm
Profile
Spends far too much time on here
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 4876
Location: Newcastle
Reply with quote
forquare1 wrote:
james016 wrote:
Thank you Ben

That worked :D


No problem, I've not done C# before, but after having a look, this is slightly more correct:

Code:
 private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            StringBuilder strVersion = new StringBuilder("Made by james016 \r\nVersion Number: ");
            MyStringBuilder.Append(System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
            MessageBox.Show(strVersion);
        }


Strings in both Java and C# are immutable (i.e. they can't be changed). In the snippet I have you before, the code had to take two Strings and stick them together to create a third String. This is generally bad practise as you're using twice as much memory.
The StringBuilder I've used above has the same effect, but enlarges the amount of memory it uses to accommodate the new text.

EDIT: Sorry James, accidentally posted an opening square bracket at the end there. Also, you may need to include System.Text.StringBuilder
I can't test it as I don't have a C# editor/compiler here...


Simpler way I would suggest is:
Code:
 private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show(String.Format("Made by james016 {0}Version Number: {1}",
                                     Environment.NewLine,
                                     System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()));
        }


might need to change String to string but that simplifies it

instead or \r\n it's better practice to use Environment.Newline, different systems interpret the new line differently and can cause formatting issues, Environment.Newline is a target dependent variable

_________________
Twitter
Charlie Brooker:
Macs are glorified Fisher-Price activity centres for adults; computers for scaredy cats too nervous to learn how proper computers work; computers for people who earnestly believe in feng shui.


Mon Jun 07, 2010 5:21 pm
Profile
Doesn't have much of a life
User avatar

Joined: Tue May 05, 2009 5:52 pm
Posts: 1899
Reply with quote
Thank you for the tips. I will look at these tomorrow at work.

_________________
Image

My Flickr Page

Now with added ball and chain.


Mon Jun 07, 2010 7:02 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 24 posts ]  Go to page Previous  1, 2

Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.