From 0b248f302175ec69c93021ebf3b8ff2955b10c5c Mon Sep 17 00:00:00 2001 From: Souji Seta Date: Thu, 27 Nov 2014 14:15:32 -0600 Subject: [PATCH] * Util.cs: Reducing number of unnecessary UInt32 Parse error under Mono due to the Underscore character being at the end of strings. Also consolidated To[U]Int32 code from controls to use string version. * f1-Main.cs: Fixed issue that is causing by initializing the values of the GameOrigin combo box causing the SelectedValue field to be queried before it knows it's ValueMember. --- Misc/Util.cs | 77 +++++++++++++++++++++++++------------------------- PKX/f1-Main.cs | 13 ++++++--- 2 files changed, 47 insertions(+), 43 deletions(-) diff --git a/Misc/Util.cs b/Misc/Util.cs index ef1993ea0..06e766724 100644 --- a/Misc/Util.cs +++ b/Misc/Util.cs @@ -147,62 +147,56 @@ internal static uint rnd32() } internal static int ToInt32(TextBox tb) - { - string value = tb.Text; - if (String.IsNullOrEmpty(value)) - { return 0; } - try - { return Int32.Parse(value); } - catch - { return 0; } - } + { + string value = tb.Text; + return ToInt32(value); + } internal static uint ToUInt32(TextBox tb) - { - string value = tb.Text; - if (String.IsNullOrEmpty(value)) - { return 0; } - try - { return UInt32.Parse(value); } - catch - { return 0; } - } + { + string value = tb.Text; + return ToUInt32(value); + } internal static int ToInt32(MaskedTextBox tb) { string value = tb.Text; - if (String.IsNullOrEmpty(value)) - { return 0; } - try - { return Int32.Parse(value); } - catch - { return 0; } + return ToInt32(value); } internal static uint ToUInt32(MaskedTextBox tb) { string value = tb.Text; - if (String.IsNullOrEmpty(value)) - { return 0; } - try - { return UInt32.Parse(value); } - catch - { return 0; } + return ToUInt32(value); } internal static int ToInt32(String value) { - if (String.IsNullOrEmpty(value)) - { return 0; } + if (String.IsNullOrEmpty(value)) + { + return 0; + } try - { return Int32.Parse(value); } + { + value = value.TrimEnd(new char[]{'_'}); + return Int32.Parse(value); + } catch - { return 0; } + { + return 0; + } } internal static uint ToUInt32(String value) { if (String.IsNullOrEmpty(value)) - { return 0; } + { + return 0; + } try - { return UInt32.Parse(value); } + { + value = value.TrimEnd(new char[]{'_'}); + return UInt32.Parse(value); + } catch - { return 0; } + { + return 0; + } } internal static uint getHEXval(TextBox tb) { @@ -215,14 +209,19 @@ internal static int getIndex(ComboBox cb) { int val = 0; if (cb.SelectedValue == null) + { return 0; + } - try { val = Util.ToInt32(cb.SelectedValue.ToString()); } + try + { + val = Util.ToInt32(cb.SelectedValue.ToString()); + } catch { val = cb.SelectedIndex; if (val < 0) val = 0; - }; + } return val; } internal static string getOnlyHex(string str) diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index 86c26f278..9e0513497 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -1477,9 +1477,15 @@ private void InitializeLanguage() origin_list.Add(item); } + /* + * Moving the assignment of the Display and ValueMemeber to before the DataSource is assigned + as assigning the DataSource causes a onSelectedIndexChanged which causes a call + to updateOriginGame which access the SelectedValue property, but since there is no + ValueMember assigned it uses the cbItem to string method which returns the Text member + */ + CB_GameOrigin.DisplayMember = "Text"; + CB_GameOrigin.ValueMember = "Value"; CB_GameOrigin.DataSource = origin_list; - CB_GameOrigin.DisplayMember = "Text"; - CB_GameOrigin.ValueMember = "Value"; #endregion } @@ -2787,8 +2793,7 @@ private void updateOriginGame(object sender, EventArgs e) // Error handling for unset field try { - cbItem CBItem_GameOrigin = (cbItem)CB_GameOrigin.SelectedValue; - gameorigin = CBItem_GameOrigin.GetValue(); + gameorigin = Util.ToInt32(CB_GameOrigin.SelectedValue.ToString()); } catch { gameorigin = 0; }