vb.net - VB project - Inside was outside the bounds of the array -


i'm working following vb code:

option strict on option infer on  public class mainform      private readbuffer string = string.empty     private bytenumber integer = 1     private bytetoread integer = 1     private byteend(2) char     private comopen boolean       private sub form1_formclosed(byval sender system.object, _                                  byval e system.windows.forms.formclosedeventargs) _                                  handles mybase.formclosed         if comopen serialport1.close()     end sub       private sub form1_load(byval sender system.object, byval e system.eventargs) handles mybase.load         sensorbutton.checked = true         ' read avaiable com ports:         dim portnames string() = system.io.ports.serialport.getportnames         if portnames nothing             msgbox("there no com ports detected!")             me.close()         end if         cbocomport.items.addrange(portnames)         cbocomport.text = portnames(0)         cbobaudrate.text = "115200"      end sub       private sub btncomopen_click(byval sender system.object, byval e system.eventargs) handles btncomopen.click          ' device params         serialport1              .parityreplace = &h3b                    ' replace ";" when parity error occurs             .portname = cbocomport.text             .baudrate = cint(cbobaudrate.text)             .parity = io.ports.parity.none             .databits = 8             .stopbits = io.ports.stopbits.one             .handshake = io.ports.handshake.none             .rtsenable = false             .receivedbytesthreshold = 1             'threshold: 1 byte in buffer > event fired             .newline = vbcr         ' cr must last char in frame. terminates serialport.readline             .readtimeout = 10000          end          ' check whether device avaiable:         try             serialport1.open()             comopen = serialport1.isopen         catch ex exception             comopen = false             msgbox("error open: " & ex.message)             picopen.backcolor = color.red         end try          if comopen             picopen.backcolor = color.green             cbocomport.enabled = false             cbobaudrate.enabled = false         end if      end sub      ''' <summary>     ''' close comport     ''' </summary>     private sub button_close_click(byval sender system.object, byval e system.eventargs) handles btncomclose.click         if comopen             ' clear input buffer             serialport1.discardinbuffer()             serialport1.close()         end if         comopen = false         picopen.backcolor = color.red         picdatareceived.backcolor = color.gray         cbocomport.enabled = true         cbobaudrate.enabled = true     end sub      ''' <summary>     ''' clear textboxes     ''' </summary>     private sub button_clear_click(byval sender system.object, byval e system.eventargs) handles btnclear.click         tbrx.text = string.empty          txtimer.stop()     end sub      ''' <summary>     ''' write content of textbox port     ''' </summary>     private sub button_send_click(byval sender system.object, byval e system.eventargs) handles btnsend.click         ...      end sub      ''' <summary>     ''' close app     ''' </summary>     private sub button_ende_click(byval sender system.object, byval e system.eventargs) handles btnexit.click         if comopen             ' clear input buffer             serialport1.discardinbuffer()             serialport1.close()         end if         comopen = false         me.close()     end sub      ''' <summary>     ''' send control panel key com port     ''' </summary>     ''' <param name="sender">return key name</param>     private sub tasten_click(byval sender system.object,                              byval e system.eventargs)           dim key string = ctype(sender, button).text         if comopen serialport1.write(key)      end sub      ''' <summary>     ''' timer datareceived event     ''' </summary>     private sub timer1_tick(byval sender system.object, _                             byval e system.eventargs) handles timer1.tick         picdatareceived.backcolor = color.gray         timer1.enabled = false     end sub 

econdary thread ''' private sub serialport1_datareceived(byval sender system.object, _ byval e system.io.ports.serialdatareceivedeventargs) _ handles serialport1.datareceived ...

    end sub      public sub doupdate(byval sender object, byval e system.eventargs) 

...

    end sub      .....  end class 

the original code found here: https://code.msdn.microsoft.com/windowsapps/serialport-sample-in-vbnet-fb040fb2

i've modified code suit needs , seeing error "index outside bounds of array" when run application debug folder on separate pc (the files work no flaws on pc visual studio). thought issue modification, looks original file cannot run. have attempted initialize ints "bytenumber" , "bytetoread" value of 1, bit still issue. causing it?

the exception text is:

************** exception text ************** system.indexoutofrangeexception: index outside bounds of array.    @ lmuengineering.mainform.form1_load(object sender, eventargs e) in c:\users\---\onedrive\frmmain.vb:line 38    @ system.eventhandler.invoke(object sender, eventargs e)    @ system.windows.forms.form.onload(eventargs e)    @ system.windows.forms.control.createcontrol(boolean fignorevisible)    @ system.windows.forms.control.createcontrol()    @ system.windows.forms.control.wmshowwindow(message& m)    @ system.windows.forms.control.wndproc(message& m)    @ system.windows.forms.control.controlnativewindow.wndproc(message& m)    @ system.windows.forms.nativewindow.callback(intptr hwnd, int32 msg, intptr wparam, intptr lparam) 


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -