vb.net - Duplicating items on listbox -
vb.net - Duplicating items on listbox -
i have programme records homework in list box, , sorts date due. however, when seek sort info date, so, duplicates each item in list box. can rectified closing programme , opening again, inconvenient. there way prepare this?
here code 2
frmsplashscreen:
imports system.io public class frmsplashscreen dim dates() date = {} dim temparray() string = {} dim temparray2() string = {} dim path string = application.startuppath dim newuser boolean = false dim sorted boolean = false private sub btnadd_click(sender object, e eventargs) handles btnadd.click if lstdate.items.contains("no assignments yet!") lstdate.items.clear() end if frmadd.show() me.hide() end sub private sub me_mouseenter(sender object, e eventargs) handles me.mouseenter if sorted = false , lstdate.items.contains("no assignments yet!") = false sortbydate() end if end sub private sub frmsplashscreen_load(sender object, e eventargs) handles mybase.load if file.exists(path & "assignments.crw") = false newuser = true lstdate.items.add("no assignments yet!") else fileopen(1, path & "assignments.crw", openmode.input) while not eof(1) dim output string = lineinput(1) lstassignments.items.add(mid(output, instr(output, "-") + 1, instr(output, "_") - (instr(output, "-") + 1))) lstan.items.add(mid(output, instr(output, "_") + 1, output.length)) lstdate.items.add(mid(output, 1, instr(output, "-") - 1)) array.resize(temparray, temparray.length + 1) temparray(temparray.length - 1) = output end while end if fileclose(1) if lstdate.items.contains("no assignments yet!") = false sortbydate() end if end sub private sub sortbydate() each x in lstdate.items msgbox(x) array.resize(dates, dates.length + 1) dates(dates.length - 1) = x next array.sort(dates) ' sort dates. temparray2 = {} ' empty temparray2 resizing dim counter integer = 0 ' declare counter each x in dates ' looping through dates... dim result integer ' ...declare result. each y in temparray ' nestled loop check each result against 1 another. time looping through temparray. result = instr(y, x) ' search x (the date) in y (the line of file) if result <> 0 ' if found... array.resize(temparray2, temparray2.length + 1) counter = counter + 1 temparray2(counter - 1) = y ' add together y array temparray2 in chronological order. end if next next dim num integer = 0 ' declare num lstan.items.clear() lstassignments.items.clear() lstdate.items.clear() temparray = {} lstan.items.clear() lstassignments.items.clear() lstdate.items.clear() each x in temparray2 array.resize(temparray, temparray2.length) temparray(num) = x lstassignments.items.add(mid(x, instr(x, "-") + 1, instr(x, "_") - (instr(x, "-") + 1))) lstan.items.add(mid(x, instr(x, "_") + 1, x.length)) lstdate.items.add(mid(x, 1, instr(x, "-") - 1)) num += 1 next ' loop through temparray2 making temparray exact same , adding array listbox. sorted = true end sub private sub sortmylife() if file.exists(path & "assignments.crw") = false newuser = true lstdate.items.add("no assignments yet!") else fileopen(1, path & "assignments.crw", openmode.input) while not eof(1) dim output string = lineinput(1) lstassignments.items.add(mid(output, instr(output, "-") + 1, instr(output, "_") - (instr(output, "-") + 1))) lstan.items.add(mid(output, instr(output, "_") + 1, output.length)) lstdate.items.add(mid(output, 1, instr(output, "-") - 1)) array.resize(temparray, temparray.length + 1) temparray(temparray.length - 1) = output end while end if fileclose(1) if lstdate.items.contains("no assignments yet!") = false sortbydate() end if end sub private sub checkbox1_checkedchanged(sender object, e eventargs) handles checkbox1.checkedchanged if checkbox1.checked = true phone call sortmylife() checkbox1.checked = false end if end sub end class
frmadd (for adding new assignment)
public class frmadd dim temparray() string = {} dim temparray2() string = {} dim dates() date = {} dim sorted boolean private sub btnadd_click(sender object, e eventargs) handles btnadd.click dim datedue date = dtpdue.text dim subject string = cbxsbjct.text dim additional string = rtfan.text dim path string = application.startuppath & "assignments.crw" if datedue > now() if subject <> "choose subject" fileopen(1, path, openmode.append) dim output string = dtpdue.text & "-" & subject & "_" & additional if frmsplashscreen.lstassignments.items.contains("no assignments yet!") frmsplashscreen.lstassignments.items.clear() frmsplashscreen.lstdate.items.clear() frmsplashscreen.lstan.items.clear() end if frmsplashscreen.lstassignments.items.add(mid(output, instr(output, "-") + 1, instr(output, "_") - (instr(output, "-") + 1))) frmsplashscreen.lstan.items.add(mid(output, instr(output, "_") + 1, output.length)) frmsplashscreen.lstdate.items.add(dtpdue.text) printline(1, output) fileclose(1) each x in frmsplashscreen.lstdate.items msgbox(x) next me.close() frmsplashscreen.show() else msgbox("please come in subject in box provided") end if else msgbox("please come in date in future", vbinformation, "error") end if end sub end class
thank help!
have tried simple listboxholiday.items.clear
before sort happens?
vb.net visual-studio-2012
Comments
Post a Comment