vb.net - Loading text into a list box -
the main goal need achieve make details entered user (such minutes used , total cost etc.) shown user in 1 list once boxes have been filled out. able save text within box/listbox txt file on pc.
that pretty need do. cant seem happen , have no idea of how can that. code have far works how should.
public class form1 private sub form1_load(sender object, e eventargs) handles mybase.load end sub private sub btn1totalcost_click(sender object, e eventargs) handles btn1totalcost.click 'declaring variables. dim minutesallowed integer dim minutesused integer dim textsallowed integer dim textsused integer dim dataallowed integer dim dataused integer dim minutestotalcost double dim textstotalcost double dim datatotalcost double dim monthlycost double dim totalcost double minutesallowed = val(txtboxminutesallowed.text) minutesused = val(txtboxminutesused.text) textsallowed = val(txtboxtextsallowed.text) textsused = val(txtboxtextsused.text) dataallowed = val(txtboxdataallowed.text) dataused = val(txtboxdataused.text) minutestotalcost = val(txtboxtotalcost.text) textstotalcost = val(txtboxtotalcost.text) datatotalcost = val(txtboxtotalcost.text) totalcost = val(txtboxtotalcost.text) 'calculation minutes minutesallowed = val(txtboxminutesallowed.text) minutesused = val(txtboxminutesused.text) monthlycost = val(txtboxmonthlycost.text) 'if minutes allowed greater or equal minutes used, no charge added. if minutesallowed >= minutesused minutestotalcost = 0 else 'if minutes used greater minutes allowed, each minute multiplied 00.30p. minutestotalcost = (minutesused - minutesallowed) * 0.3 end if txtboxtotalcost.text = ctype(minutestotalcost + monthlycost, string) 'calculation texts textsallowed = val(txtboxtextsallowed.text) textsused = val(txtboxtextsused.text) monthlycost = val(txtboxmonthlycost.text) 'if texts allowed greater or equal texts used, no charge added. if textsallowed >= textsused textstotalcost = 0 else 'if texts used greater texts allowed, each text multiplied 00.15p. textstotalcost = (textsused - textsallowed) * 0.15 end if txtboxtotalcost.text = ctype(textstotalcost + monthlycost, string) 'calculation data dataallowed = val(txtboxdataallowed.text) dataused = val(txtboxdataused.text) monthlycost = val(txtboxmonthlycost.text) 'if data allowed greater or equal data used, no charge added. if dataallowed >= dataused datatotalcost = 0 else 'if data used greater data allowed, 10.00 added total cost. datatotalcost = 10 end if txtboxtotalcost.text = ctype(datatotalcost + monthlycost + textstotalcost + minutestotalcost, double) end sub end class
ok. code brutally honest isn't good. these lines
dim fullname string dim phonenumber decimal dim accnumber decimal dim minutesallowed integer dim textsallowed integer dim dataallowed integer dim minutesused integer dim textsused integer dim dataused integer dim monthlycost double dim totalcost double
are declaring variables of specific types - strings,decimals , integers , on. means can accept values same type. having option strict on in code correct these errors show errors have code. these lines should be:
fullname = "" phonenumber = 0d accnumber = 0d minutesallowed = 0 textsallowed = 0 dataallowed = 0 minutesused = 0 textsused = 0 dataused = 0 monthlycost = 0r totalcost = 0r
the reason you're having problems can't assign empty string integer or other number. option strict on, these errors show up. incidendtally better declaring phonenumber string allow dashes , brackets etc. if totalcost double monthlycost should double
the letters after numbers indicate type of number being asssigned. d means it's decimal 0 , r means it's double 0. in code stands, when variables declared, assigned default values anyway, don't need lines assigning values
moving on ..
listbox.items.add("full name: " + txtboxfullname.text) listbox.items.add("phone number: " + txtboxphonenumber.text)
and on
the lines above unrelated the variable declarations above. intentional? example txtboxfullname.text isn't same variable fullname @ , unless have other code, dont see need above variables. i'm guessing code you've posted incomplete. when you're posting question, need post relevant code. have here .. https://stackoverflow.com/help/mcve
listen plutonix - wise.
Comments
Post a Comment