Pa 2

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Pa 2 as PDF for free.

More details

  • Words: 706
  • Pages: 3
option strict on public class shipping dim inttounces as integer 'declare global variables dim intcounter as integer private sub btnexit_click(byval sender as system.object, byval e as system.eventargs) handles btnexit.click me.close() 'close the program end sub private sub btncalculate_click(byval sender as system.object, byval e as system.eventargs) handles btncalculate.click callall() 'execute all subroutines needed to perform function lstoutput.items.add(txtid.text & " " & txtpounds.text & " lbs " & txtounces.text & " oz " & txtcost.text) 'print data to listbox end sub private sub callall() dim e as integer = 0 'declare hella variables because i believe i need them dim intlb as integer dim intoz as integer dim tb as textbox = txtpounds dim x as integer dim testp as integer = 0 dim testo as integer = 0 testp = txtpounds.text.indexof("+") + txtpounds.text.indexof("-") + txtpounds.text.indexof("*") + txtpounds.text.indexof("/") + 4 'check for mathmatical functions testo = txtounces.text.indexof("+") + txtounces.text.indexof("-") + txtounces.text.indexof("*") + txtounces.text.indexof("/") + 4 if testp > 0 then 'return result of check badsymbol() tb = txtpounds selfocus(tb) e = 1 elseif testo > 0 then 'return result of check badsymbol() tb = txtounces selfocus(tb) e = 1 end if if e = 0 then try 'begin try catch if txtpounds.text = "" then 'convert a blank box to 0 intlb = 0 txtpounds.text = "0" else intlb = convert.toint32(txtpounds.text) 'continue with inputed number end if catch ex as exception tb = txtpounds 'set up focus box/error message/block check on second box msgbox("you must enter a positive whole integer for pounds!", , "you goofed up!") e = 1 end try try if txtounces.text = "" then 'convert a blank box to 0

int0z = 0 txtounces.text = "0" else intoz = convert.toint32(txtounces.text) 'take value if 16 < intoz then 'correct lb/oz values (17oz = 1lb, 10z)

corrected values

value set

x = intoz \ 16 intoz = intoz mod 16 intlb = x + intlb txtpounds.text = convert.tostring(intlb)

'show

txtounces.text = convert.tostring(intoz) end if end if catch ex as exception tb = txtounces 'error message/focus box/block script

msgbox("you must enter a positive whole integer for ounces!", , "you goofed up!") e = 1 end try end if if e = 0 then 'block or execute script convertlb(intlb, intoz) 'call subroutines txtid.text = nextid() 'set function to textbox totalweight() totalcost() txtpounds.focus() 'set focus/select txtpounds.selectall() else selfocus(tb) 'focus on errored box end if end sub private sub convertlb(byval l as integer, byval o as integer) dim x as integer l = l * 16 'convert lbs to ounces inttounces = l + o + inttounces 'add all oz up x = l + o cost(x) 'calculate cost for package end sub private function nextid() as string intcounter = intcounter + 1 'counter if intcounter < 10 then 'place beginning zeroes/return value return "awb00" & convert.tostring(intcounter) elseif intcounter < 100 then return "awb0" & convert.tostring(intcounter) else return "awb" & convert.tostring(intcounter) end if end function private sub totalcost() dim x as decimal 'declare some variables x = inttounces * 0.12d 'calculate total cost txttotalcost.text = formatcurrency(x) 'post total cost end sub private sub totalweight() dim intlb as integer 'declare some variables dim intoz as integer

intlb = inttounces \ 16 'convert oz back to lbs intoz = inttounces mod 16 txtweighttotal.text = intlb & " lbs, " & intoz & " oz" 'print total weight to txtbox end sub private sub btnclear_click(byval sender as system.object, byval e as system.eventargs) handles btnclear.click intcounter = 0 'clear everything and reset values/focus inttounces = 0 lstoutput.items.clear() txtid.text = "" txtpounds.text = "" txtounces.text = "" txtcost.text = "" txtweighttotal.text = "0 lbs 0 oz" txttotalcost.text = "$0.00" txtpounds.focus() txtpounds.selectall() end sub private sub cost(byval x as integer) dim y as decimal y = x * 0.12d 'calculate item shipping cost txtcost.text = formatcurrency(y) 'print said shipping cost end sub private sub selfocus(byval tb as textbox) tb.focus() 'select focus for desired textbox tb.selectall() end sub private sub txtpounds_enter(byval sender as system.object, byval e as system.eventargs) handles txtpounds.enter txtpounds.selectall() 'highlight value in txtpounds end sub private sub txtounces_enter(byval sender as system.object, byval e as system.eventargs) handles txtounces.enter txtounces.selectall() 'highlight value in txtounces end sub private sub badsymbol() msgbox("just enter a positive integer, digits only, please.", , "what are you thinkin?") 'return error end sub end class

Related Documents

Pa 2
November 2019 7
Pa 2
November 2019 8
Pa
May 2020 33
Pa
May 2020 39
Pa Examen 2.docx
June 2020 5
Exerc 4bim Pa 2
November 2019 17