Wednesday, 15 February 2012

vb.net - Arithmetic operation resulted in an overflow. -



vb.net - Arithmetic operation resulted in an overflow. -

i'm making programme remove pain of hex editing old dos game (sensible world of soccer).

the programme removes limit of number of players can purchase (5), removes maximum number of seasons can compete (20).

i'm trying create can edit transfer budget i'm getting arithmetic operation resulted in overflow. error when run code select 50million option.

here total code programme (the transfer limit & maximum season limit both work):

imports system.io public class swos_editor_2013 dim transferbudget string private sub opentoolstripmenuitem_click(sender object, e eventargs) handles opentoolstripmenuitem.click '######### '#warning# '######### 'dim reply dialogresult 'answer = messagebox.show("make backup of career file click ok proceed. take no responsibility damaged career files", ' "*please read before proceeding*", messageboxbuttons.ok, messageboxicon.asterisk) '########################## '#progress bar set options# '########################## progressbar1.minimum = 0 progressbar1.maximum = 2 progressbar1.value = 0 '################## '#tool tip options# '################## dim tooltip1 new tooltip tooltip1.autopopdelay = 5000 tooltip1.initialdelay = 1000 tooltip1.reshowdelay = 500 tooltip1.showalways = true '################################### '#open swos career file editing# '################################### me.openfiledialog1.initialdirectory = "c:\" me.openfiledialog1.title = "select career file editing" me.openfiledialog1.defaultext = "*.car" me.openfiledialog1.filename = "" me.openfiledialog1.filter = "career file(*.car)|*.car" me.openfiledialog1.multiselect = false '################### '#ok button pressed# '################### if me.openfiledialog1.showdialog() = windows.forms.dialogresult.ok '############################## '#increase progress bar 50%# '############################## if progressbar1.value < progressbar1.maximum progressbar1.value += 1 end if '################ '#enable buttons# '################ btn_save.enabled = true btn_trans_limit.enabled = true btn_career_limit.enabled = true cb_combo.enabled = true end if end sub '####################### '#enable combo box drop# '####################### private sub cb_combo_checkedchanged(byval sender object, e eventargs) handles cb_combo.checkedchanged combobox1.enabled = true end sub '######################## '#select transfer budget# '######################## private sub combobox1_dropdownclosed(byval sender object, e eventargs) handles combobox1.dropdownclosed select case combobox1.selecteditem case = "-£10 1000000 (are crazy challenge)" transferbudget = "100" case = "-£2 1000000 (mid level challenge)" transferbudget = "200" case = "-£500k (lower league challenge)" transferbudget = "500" case = "£500k (tough)" transferbudget = "05" case = "£5 million" transferbudget = "5" case = "£10 million" transferbudget = "10" case = "£25 million" transferbudget = "25" case = "£50 million" transferbudget = "50000000" case = "£99 million" transferbudget = "999" end select end sub '####################################### '#exit if exit clicked dropdown# '####################################### private sub exittoolstripmenuitem_click(sender object, e eventargs) handles exittoolstripmenuitem.click me.close() end sub '####################### '#not got bloody clue# '####################### private shared function inlineassignhelper(of t)(byref target t, value t) t target = value homecoming value end function '################################################################## '#apply changes made drop downwards box , radio button if selected# '################################################################## public sub savechanges() dim amount integer dim fpath string = openfiledialog1.filename using stream = new filestream(fpath, filemode.open, fileaccess.readwrite) dim result integer = 0 dim buffer byte() = new byte(3) {} stream.position = 54748 if (stream.read(buffer, 0, 4) <> 4) throw new exception(("didn't read 4 bytes when should have: " _ + (result + "bytes read"))) end if stream.position = &hd5dc buffer = bitconverter.getbytes(amount) stream.write(buffer, 0, 4) stream.position = &hd880 if btn_career_limit.checked stream.writebyte(0) else stream.writebyte(1) end if stream.position = &hd5c4 if btn_trans_limit.checked stream.writebyte(&hff) else stream.writebyte(0) end if 'stream.write(buffer, 0, 4) 'stream.position = &hd5dc 'if testbutton.checked ' stream.writebyte("3b9ac9ff") 'end if **if cb_combo.checked = true stream.position = &hd5dc stream.writebyte(transferbudget) ######this overflow error#####** end if end using end sub '############################################### '#save above changes & set progress bar 100%# '############################################### private sub btn_save_click(sender object, e eventargs) handles btn_save.click savechanges() if progressbar1.value < progressbar1.maximum progressbar1.value += 1 end if end sub '######################################################################################################################################### '# tool tip (mouse hover) # '# # private sub btn_trans_limit_checkedchanged(sender object, e eventargs) handles btn_trans_limit.mousehover '# tooltip1.settooltip(btn_trans_limit, "removes 5 player transfer limit") '# end sub private sub btn_career_limit_checkedchanged(sender object, e eventargs) handles btn_career_limit.mousehover '# '# '# tooltip1.settooltip(btn_career_limit, "removes 20 season limit") '# end sub private sub combobox1_mousehover(sender object, e eventargs) handles combobox1.mousehover '# '# '# tooltip1.settooltip(combobox1, "select transfer budget") '# end sub private sub btn_save_mousehover(sender object, e eventargs) handles btn_save.mousehover '# '# '# tooltip1.settooltip(btn_save, "save changes career file") end sub private sub cb_combo_mousehover(sender object, e eventargs) handles cb_combo.mousehover '# '# '# tooltip1.settooltip(cb_combo, "tick if want edit transfer budget") '# end sub '######################################################################################################################################### end class

any help appreciated.

you passing string (transferbudget) filestream.writebyte method. writebyte method takes byte, not string. if had option strict on, should, result in compile error. however, since have option strict off, allows compile , automatically inserts type conversion string byte you. type conversion operation throw overflow exception if value in string outside of minimum , maximum value of byte (0 - 255). here's code set transferbudget variable:

select case combobox1.selecteditem case = "-£10 1000000 (are crazy challenge)" transferbudget = "100" case = "-£2 1000000 (mid level challenge)" transferbudget = "200" case = "-£500k (lower league challenge)" transferbudget = "500" 'gah! case = "£500k (tough)" transferbudget = "05" case = "£5 million" transferbudget = "5" case = "£10 million" transferbudget = "10" case = "£25 million" transferbudget = "25" case = "£50 million" transferbudget = "50000000" 'gah! case = "£99 million" transferbudget = "999" 'gah! end select

as can see, there several values there greater 255.

vb.net

No comments:

Post a Comment