1

Why does this not work :

            if (This_Ver.Text == New_Ver.Text)
            {
                MAIN_PANEL.Visible = true;
            }
            else if (This_Ver.Text != New_Ver.Text)
            {
            DialogResult dialogResult = MessageBox.Show("An update has been found!" + Environment.NewLine + "Would you like to download and install it?", "Update found!", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
            if (dialogResult == DialogResult.Yes)
            {
                MAIN_PANEL.Visible = false;
                UPDATE_PANEL.Visible = true;
                USERNAME_TEXT.Enabled = false;
                PASSWORD_TEXT.Enabled = false;
                LOGIN_BUTTON.Enabled = false;
                MAIN_PANEL.Visible = false;
                UPDATE_NOW_BUTTON.Enabled = true;
            }
            else if (dialogResult == DialogResult.No)
            {
                UPDATE_NOW_BUTTON.Enabled = true;
                MAIN_PANEL.Visible = true;
            }
        }

I am trying to compare the new version and the current running version. It should open the updater panel when the textboxes does not contain the same version.

But It doesn't work. It always opens the updater panel.

EDIT :

value : This_Ver.Text : V1.1.13.1

value : New_Ver.Text : V1.1.13.1

3 Answers3

2

Try like below may be it will help you you..

change your code

FROM :

if (This_Ver.Text == New_Ver.Text)

TO :

if (This_Ver.Text.ToUpper().Trim().Equals(This_Ver.Text.ToUpper().Trim()))
Pandian
  • 8,848
  • 2
  • 23
  • 33
  • This fixed my problem thanks. But I have one last question what does Trim? – Menno van Leeuwen Apr 12 '13 at 10:55
  • Trim() - is String function that eliminates leading and trailing whitespace of a string.. try this link for full details... http://msdn.microsoft.com/en-us/library/t97s7bs3.aspx – Pandian Apr 12 '13 at 10:57
  • Hmmm intresting, Thanks a lot. – Menno van Leeuwen Apr 12 '13 at 10:58
  • @Pandian: The most common method for string comparisons is using `==` There are small differences in the behavior of using`equal' that the string be non-null. This can be problematic in certain algorithms, but good in others. refer sir jon skeet's answer http://stackoverflow.com/questions/3678792/are-string-equals-and-operator-really-same and http://www.dotnetperls.com/string-equals – Satinder singh Apr 12 '13 at 11:12
  • @Satindersingh: Yes i agree with you most string comparison methods have `==` and `String.Compare`. but i have mostly used `Equals` in my Program so i have suggest this method too... – Pandian Apr 12 '13 at 11:22
1

Try Something like this

string value1 = This_Ver.Text.Trim();
string value2 = New_Ver.Text.Trim();
if(value1  == value2 )
 {
   //hide your panel
 }
 else
 {
    // code something
 }

if value matches it hides otherwise it goes to else part where you do some logic code.

Aslo want to know what values are you getting in value1,value2 while debugging on IF Condition

Satinder singh
  • 10,100
  • 16
  • 60
  • 102
0

You must use (This_Ver.Text.Equals(New_Ver.Text)) because == comparator will not work. As in Java, == comparator do object references comparation. In contrast, Equals method compares strings content.

Good Luck.

emigue
  • 492
  • 3
  • 13