Why aren't these two simple if statements working?

timehacker11

New member
Joined
May 17, 2013
Messages
1
Programming Experience
1-3
I have to if statements that work with a NSTextBox, determining it's length. However, when ever I press the button that has the methods, all my TextView displays is "24".

My MonoMac Code:
C#:
[FONT=Menlo][COLOR=#3364a4]String [/COLOR][COLOR=#444444]input [/COLOR][COLOR=#444444]= [/COLOR][COLOR=#444444]inputString[/COLOR][COLOR=#444444].[/COLOR][COLOR=#444444]ToString[/COLOR][COLOR=#444444]([/COLOR][COLOR=#444444])[/COLOR][COLOR=#444444];[/COLOR]
[COLOR=#009695]if[/COLOR][COLOR=#444444]([/COLOR][COLOR=#444444]input[/COLOR][COLOR=#444444].[/COLOR][COLOR=#444444]Length [/COLOR][COLOR=#444444]=[/COLOR][COLOR=#444444]= [/COLOR][COLOR=#f57d00]0[/COLOR][COLOR=#444444])[/COLOR]
[COLOR=#444444]{[/COLOR]
[COLOR=#3364a4]NSAlert [/COLOR][COLOR=#444444]warnLength [/COLOR][COLOR=#444444]= [/COLOR][COLOR=#009695]new [/COLOR][COLOR=#3364a4]NSAlert[/COLOR][COLOR=#444444]([/COLOR][COLOR=#444444])[/COLOR][COLOR=#444444];[/COLOR]
[COLOR=#444444]warnLength[/COLOR][COLOR=#444444].[/COLOR][COLOR=#444444]InformativeText[/COLOR][COLOR=#444444]=[/COLOR][COLOR=#f57d00]"[/COLOR][COLOR=#f57d00]There is no input string[/COLOR][COLOR=#f57d00]"[/COLOR][COLOR=#444444];[/COLOR]
[COLOR=#444444]warnLength[/COLOR][COLOR=#444444].[/COLOR][COLOR=#444444]MessageText[/COLOR][COLOR=#444444]=[/COLOR][COLOR=#f57d00]"[/COLOR][COLOR=#f57d00]No String[/COLOR][COLOR=#f57d00]"[/COLOR][COLOR=#444444];[/COLOR]
[COLOR=#444444]warnLength[/COLOR][COLOR=#444444].[/COLOR][COLOR=#444444]RunModal[/COLOR][COLOR=#444444]([/COLOR][COLOR=#444444])[/COLOR][COLOR=#444444];[/COLOR]
[COLOR=#444444]}[/COLOR]
[COLOR=#009695]if[/COLOR][COLOR=#444444]([/COLOR][COLOR=#444444]input[/COLOR][COLOR=#444444].[/COLOR][COLOR=#444444]Length [/COLOR][COLOR=#444444]> [/COLOR][COLOR=#f57d00]0[/COLOR][COLOR=#444444])[/COLOR]
[COLOR=#444444]{[/COLOR]
[COLOR=#444444]outputContent[/COLOR][COLOR=#444444].[/COLOR][COLOR=#444444]Value [/COLOR][COLOR=#444444]= [/COLOR][COLOR=#444444]input[/COLOR][COLOR=#444444].[/COLOR][COLOR=#444444]Length[/COLOR][COLOR=#444444].[/COLOR][COLOR=#444444]ToString[/COLOR][COLOR=#444444]([/COLOR][COLOR=#444444])[/COLOR][COLOR=#444444];[/COLOR]
[COLOR=#444444]}[/COLOR][/FONT]

Code for Windows should be: (can't recall right at this moment what is what on Windows)
C#:
[FONT=Menlo][COLOR=#3364a4]String [/COLOR][COLOR=#444444]input [/COLOR][COLOR=#444444]= [/COLOR][COLOR=#444444]TextBox1[/COLOR][COLOR=#444444].Text[/COLOR][COLOR=#444444]([/COLOR][COLOR=#444444])[/COLOR][COLOR=#444444];[/COLOR]
[COLOR=#009695]if[/COLOR][COLOR=#444444]([/COLOR][COLOR=#444444]input[/COLOR][COLOR=#444444].[/COLOR][COLOR=#444444]Length [/COLOR][COLOR=#444444]=[/COLOR][COLOR=#444444]= [/COLOR][COLOR=#f57d00]0[/COLOR][COLOR=#444444])[/COLOR]
[COLOR=#444444]{[/COLOR]
[COLOR=#3364a4]MessageBox.Show("There is no input string", "No String", MessageBoxButtons.OK, MessageBoxIcon.Error);[/COLOR]
[COLOR=#444444]}[/COLOR]
[COLOR=#009695]if[/COLOR][COLOR=#444444]([/COLOR][COLOR=#444444]input[/COLOR][COLOR=#444444].[/COLOR][COLOR=#444444]Length [/COLOR][COLOR=#444444]> [/COLOR][COLOR=#f57d00]1[/COLOR][COLOR=#444444])[/COLOR]
[COLOR=#444444]{[/COLOR]
[COLOR=#444444]RichTextBox1[/COLOR][COLOR=#444444].[/COLOR][COLOR=#444444]Text [/COLOR][COLOR=#444444]= [/COLOR][COLOR=#444444]input[/COLOR][COLOR=#444444].[/COLOR][COLOR=#444444]Length[/COLOR][COLOR=#444444].[/COLOR][COLOR=#444444]ToString[/COLOR][COLOR=#444444]([/COLOR][COLOR=#444444])[/COLOR][COLOR=#444444];[/COLOR]
[COLOR=#444444]}[/COLOR][/FONT]

Any ideas? Thanks,
timehacker11.
 
That second code snippet is going to display an error message dialogue if the TextBox is empty and do nothing if it contains a single character. The latter is not your intention I'm guessing. If the TextBox contains more than one character then the number of characters will be displayed in the RichTextBox. If you see 24 then I can only conclude that the TextBox contains 24 characters.
 
Back
Top Bottom