Sunday 15 July 2012

vb.net 2010 - Creating error-checking for multiple textbox fields vb2010 -



vb.net 2010 - Creating error-checking for multiple textbox fields vb2010 -

i new vb , attempting expand on basic256 programme created in class other night. created console version of app (code below) , windows forms version. need help creating error checking text boxes. textbox1 looking prevent blank field. textbox3 wanting require positive number no more 2 decimal places. also, know code overly complicated, cleaning suggestions appreciated.

console code

module module1 sub main() dim check_num(10) string dim description(10) string dim amount(10) decimal dim total_bal(10) decimal dim pointer integer dim x integer pointer = 0 start: console.clear() console.writeline("enter check number check") console.writeline("enter b balance inquiry") console.writeline("enter c bank charge") console.writeline("enter d deposit") console.writeline("enter f if finished") console.writeline("enter choice: ") check_num(pointer) = console.readline() select case check_num(pointer) case "b", "b" x = 0 x = 0 10 if total_bal(x) = 0 x = x - 1 if x < 0 x = 0 end if else if total_bal(x) <> 0 goto cont end if end if console.writeline("balance is: {0}", total_bal(x)) console.writeline("press key continue...") console.readkey(true) goto start cont: next x case "d", "d" x = 0 x = 0 10 if total_bal(x) = 0 console.writeline("amount of deposit: ") amount(x) = console.readline() console.writeline("descripiton of transaction: ") description(x) = console.readline() if x = 0 total_bal(x) = total_bal(x) + amount(x) else total_bal(x) = total_bal(x - 1) + amount(x) end if goto start end if next x case "f", "f" end case else x = 0 x = 0 10 if total_bal(x) = 0 console.writeline("amount of debit: ") amount([x]) = console.readline() console.writeline("descripiton of transaction: ") description$([x]) = console.readline() if x = 0 total_bal(x) = total_bal(x) - amount(x) else total_bal(x) = total_bal(x - 1) - amount(x) end if goto start end if next x end select goto start end sub end module

windows forms code

public class form1 dim check_num(10) string dim description(10) string dim amount(10) decimal dim total_bal(10) decimal dim pointer integer = 0 dim x integer private sub radiobutton1_checkedchanged(byval sender system.object, byval e system.eventargs) handles radiobutton1.checkedchanged if radiobutton1.checked = true label3.visible = true textbox3.visible = true label2.visible = true textbox1.visible = true button1.visible = true end if end sub private sub radiobutton2_checkedchanged(byval sender system.object, byval e system.eventargs) handles radiobutton2.checkedchanged if radiobutton2.checked = true label3.visible = true textbox3.visible = true label2.visible = true textbox1.visible = true button1.visible = true end if end sub private sub radiobutton3_checkedchanged(byval sender system.object, byval e system.eventargs) handles radiobutton3.checkedchanged if radiobutton3.checked = true label3.visible = true textbox3.visible = true label2.visible = true textbox1.visible = true button1.visible = true end if end sub private sub radiobutton4_checkedchanged(byval sender system.object, byval e system.eventargs) handles radiobutton4.checkedchanged if radiobutton4.checked = true label3.visible = false textbox3.visible = false label2.visible = false textbox1.visible = false button1.visible = false end if x = 0 x = 0 10 if total_bal(x) = 0 x = x - 1 if x < 0 x = 0 end if goto line1 end if next x line1: label4.visible = true textbox2.visible = true textbox2.text = total_bal(x).tostring("n2") messagebox.show("press ok clear screen.") label4.visible = false textbox2.visible = false radiobutton4.checked = false end sub private sub button1_click(byval sender system.object, byval e system.eventargs) handles button1.click if radiobutton1.checked = true x = 0 x = 0 10 if total_bal(x) = 0 if textbox3.text <> string.empty if not decimal.tryparse(textbox3.text, amount(x)) messagebox.show("please utilize 12345.67 format only.") textbox3.focus() else amount(x) = textbox3.text description(x) = textbox1.text goto line1 end if end if end if next x line1: if x = 0 total_bal(x) = total_bal(x) - amount(x) else total_bal(x) = total_bal(x - 1) - amount(x) end if messagebox.show("check number " & description(x) & " withdrawn" & vbcrlf & "in amount of $" & amount(x)) end if if radiobutton2.checked = true x = 0 x = 0 10 if total_bal(x) = 0 if textbox3.text <> string.empty if not decimal.tryparse(textbox3.text, amount(x)) messagebox.show("please utilize 12345.67 format only.") textbox3.focus() else amount(x) = textbox3.text description(x) = textbox1.text goto line2 end if end if end if next x line2: if x = 0 total_bal(x) = total_bal(x) - amount(x) else total_bal(x) = total_bal(x - 1) - amount(x) end if messagebox.show("a fee " & description(x) & " withdrawn" & vbcrlf & "in amount of $" & amount(x)) end if if radiobutton3.checked = true x = 0 x = 0 10 if total_bal(x) = 0 if textbox3.text <> string.empty if not decimal.tryparse(textbox3.text, amount(x)) messagebox.show("please utilize 12345.67 format only.") textbox3.focus() else amount(x) = textbox3.text description(x) = textbox1.text goto line3 end if end if end if next x line3: if x = 0 total_bal(x) = total_bal(x) + amount(x) else total_bal(x) = total_bal(x - 1) + amount(x) end if messagebox.show("a deposit " & description(x) & " made" & vbcrlf & "in amount of $" & amount(x)) end if radiobutton1.checked = false radiobutton2.checked = false radiobutton3.checked = false radiobutton4.checked = false textbox1.clear() textbox2.clear() textbox3.clear() label3.visible = false textbox3.visible = false label2.visible = false textbox1.visible = false button1.visible = false end sub private sub button2_click(byval sender system.object, byval e system.eventargs) handles button2.click dim response integer response = messagebox.show("do want exit?", "", _ messageboxbuttons.yesno, messageboxicon.question) if response = vbyes me.close() end if end sub private sub button3_click(byval sender system.object, byval e system.eventargs) handles button3.click radiobutton1.checked = false radiobutton2.checked = false radiobutton3.checked = false radiobutton4.checked = false textbox1.clear() textbox2.clear() textbox3.clear() array.clear(check_num, 0, check_num.length) array.clear(description, 0, description.length) array.clear(amount, 0, amount.length) array.clear(total_bal, 0, total_bal.length) end sub end class

for textbox1, add together check on whatever button utilize on particular text box. check this

if textbox1.text = string.empty (or can utilize "") 'throw error of sort end if

for textbox2, add together keypress event handler text box. this

private sub textbox1_keypress(sender system.object, e system.windows.forms.keypresseventargs) handles txtbox1.keypress dim ikeypress integer = asc(e.keychar) dim hasdecimal boolean = false if ikeypress < 48 or ikeypress > 57 ' allow numbers e.handled = true end if select case ikeypress case 46 'decimal if hasdecimal = false e.handled = true hasdecimal = true end if end select end sub

vb.net-2010 error-checking

No comments:

Post a Comment