2014-10-09 30 views
0

我一直在试图获得以下条形码阅读器程序在Windows手机上工作。vb.net内联函数帮助使用dispatchtimer.tick

我按照以下网站上的步骤:http://developer.nokia.com/community/wiki/Generating_and_scanning_barcodes_using_ZXing_on_Windows_Phone

,并将它转换成vb.net,但有一行代码,这似乎是给我找麻烦。

网站上的示例使用C#和下面的代码块是

// This timer will be used to scan the camera buffer every 250ms and scan for any barcodes 
    _scanTimer = new DispatcherTimer(); 
    _scanTimer.Interval = TimeSpan.FromMilliseconds(250); 
    _scanTimer.Tick += (o, arg) => ScanForBarcode(); 

当这种转换的麻烦有一个我真的到VB.NET您会收到以下

' This timer will be used to scan the camera buffer every 250ms and scan for any barcodes 
_scanTimer = New DispatcherTimer() 
_scanTimer.Interval = TimeSpan.FromMilliseconds(250) 
_scanTimer.Tick += Function(o, arg) ScanForBarcode() 

我就上线获得两个错误都:

  1. 公共事件蜱(发送者为对象,E作为System.EventArgs)”是一个事件,并且不能直接调用。使用'RaiseEvent'语句来引发一个事件。

,如果我的RaiseEvent添加到行然后我得到以下错误

_scanTimer的开始”不是某一事件PhoneApp2.Scan'

  • ScanForBarcode()事件会产生以下错误:表达式不会生成值。
  • 对上述错误的任何帮助将不胜感激,因为我不知道该怎么办来纠正错误。

    感谢 加雷思

    回答

    1

    试试这个:

    AddHandler _scanTimer.Tick, Sub(o As Object, arg As EventArgs) 
               ScanForBarcode() 
              End Sub 
    

    还是要更加缩短:

    AddHandler _scanTimer.Tick, Sub(o As Object, arg As EventArgs) ScanForBarcode() 
    

    事件是使用在vb.net不同的模式加入。

    +0

    如果我添加了这个,我不会收到以下错误 – Gazza 2014-10-09 19:43:36

    +0

    'AddHandler'或'RemoveHandler'语句事件操作数必​​须是点限定表达式或简单名称。 – Gazza 2014-10-09 19:44:07

    +0

    对不起,修正了这个例子。我错过了ScanForBarCode不使用标准事件签名。 – 2014-10-09 19:44:25