c# - Declaring the value of a string based on a given text -
i'm quite new programming i'm gonna ask how can declare value of string based on object text.
so based on title.text of interface. going determine string value. here code tried:
public mainmenu() { initializecomponent(); initializeoffice(); } public string office; public void initializeoffice() { if (officename.text == "accounting office") { office = "accounting"; } else if (officename.text == "registrar's office") { office = "registrar"; }
i using office string variable determine folder paths because both accounting , registrar offices have different directories. example:
using (streamwriter objwriter = file.appendtext("c:desktop\\" + office + "\\finished\\" + ticketnumber.text +".txt"))
can me out? seems string office shows "accounting" value if office text different.
additional:
if (chooseservice.text == "") { messagebox.show("please specify department."); } else { this.hide(); mainmenu login = new mainmenu(); login.show(); login.officename.text = chooseservice.text; }
this content of officename fetched. chooseservice object combobox choices of different offices.
so problem here mainmenu form initialising title before setting string use determine 'office' should set to.
try this:
if (string.isnullorempty(chooseservice.text)) messagebox.show("please specify department."); else { this.hide(); mainmenu login = new mainmenu(chooseservice.text); login.show(); }
then modify mainmenu form so:
public mainmenu(string department) { initializecomponent(); initializeoffice(department); } public string office; public void initializeoffice(string department) { if (department == "accounting office") { office = "accounting"; } else if (department == "registrar's office") { office = "registrar"; }
this guarantee main menu class has information needs display correct value (or use set path). move initialisation of title out of constructor of mainmenu class , call initailiszeoffice string value chooseservice.text, either work bvut prefer code supplied. neater imo.
Comments
Post a Comment