vb.net - Taking "ten" values from a textbox, splitting them into 10 single values and outputting into a column -
i using modified version of below code send information entered in combo boxs , textboxs on form 2. labels form3
public class form1 private sub button1_click(sender object, e eventargs) handles button1.click dim f new formvb2() f.textbox1value = textbox1.text f.showdialog() end sub end class public class form2 public property textbox1value string private sub form2_load(sender object, e eventargs) handles me.load textbox1.text = textbox1value end sub end class
thanks @steven doggart,
i looking take process little further.... lets textbox5 on form 2 has following data... 27, 34, 56, 94, 23 want data taken form3 , output on 5 differnt labels 27 34 56 94 23
the problems thinking straight away need labels in place ready input these (if data can split) or can coded create , place data? form2 has 10 text boxs , each of these have 1 50 differnet values input, , want take data each textbox on form2, output them individual values on form3 in column.
if ever hit 15rep can put screenshots show process little better further info needed, please let me know.
thanks alot in advance advice/help/suggestions!
splitting data possible, depends on actual format of data. if data formatted comma followed space between each value, can use string.split
method, this:
dim data string = "27, 34, 56, 94, 23" dim values() string = data.split({", "}, stringsplitoptions.none)
the string.split
method returns array of strings each item in array 1 of delimited values.
as far displaying them on form
, if want display them in column of label
controls, need create new label
each item in array. either need have them on form, design-time, or need dynamically instantiate label
controls @ run-time. neither option recommend, however. if need display column of data, there better controls use sort of thing label
.
i recommend using listbox
control display them. advantage of listbox
control, besides convenience, can display number of items. if there many items fit in control, show scroll bar user can scroll , down through items. here's how fill listbox
string array:
listbox1.items.addrange(values)
alternatively, if need use label
control, reason, display each item on separate line in single label control. that, you'd need join of items using newline
string delimiter, instance:
label1.text = string.join(environment.newline, values)
raja provided excellent example of how loop through textbox
controls on form , build arraylist
containing of split values. caution you, however, find all textbox
controls on form, if have other text boxes, need alter logic little bit. real suggestion improve upon did is, instead of using arraylist
, should using list(of string)
. arraylist
not type-specific, it's less safe, , therefore not recommended. it's older class days of .net, before generics supported. now-a-days, if need type-unspecific list, people recommend using list(of object)
rather arraylist
.
to build list of strings multiple text boxes, , add them listbox
, can this:
dim allvalues new list(of string)() each textbox in me.controls.oftype(of textbox)() allvalues.addrange(i.text.split({", "}, stringsplitoptions.none)) next listbox1.items.addrange(allvalues.toarray())
Comments
Post a Comment