c# - How to use variables from another class -
alright, here go. kinda new programming , c#, i'm learning john sharp's visual c#: step step book. (i wonder if dude's last name sharp)
anyway, i'm trying create application me transpose note. it's windows forms app , i'm using 2 classes: form1.cs code happens , vars.cs variables stored.
my problem want use string vars.notechosen , define comboboxnote's selected item (e.g. c). whenever this, however, when execute vars.notechosen = combonote.selectedtext;
"object reference not set instance of object." error. ideas? (combonote combobox)
this vars.cs
namespace transposer { class vars { public static bool rbtransposeup = true; public static string notechosen = ""; // public static string totranspose = ""; // public static int note = 0; public static string boxresulttext = note.tostring(); } }
and part of form1.cs
namespace transposer { public partial class transposer : form { public transposer() { vars.notechosen = combonote.selectedtext; vars.totranspose = combonote.text; initializecomponent(); }
...
what doing wrong?
move lines after call initializecomponent();
it's call creating combonote object.
that is
public transposer() { initializecomponent(); // constructs combonote vars.notechosen = combonote.selectedtext; vars.totranspose = combonote.text; }
Comments
Post a Comment