2016-09-08 10 views
1

OKこれはどちらの言語にも堪能ではないので、これが簡単な質問であれば私を許してください。私はVB.Netにもっと慣れており、これを既存のプロジェクトに実装したいので、C#からVB.netにいくつかのサンプルコードを移譲しようとしています。私は簡単なクラスと簡単なフォームを持っています。私はevents.requiredの継承ラインにエラーがあり、解決方法がわかりません。C#to VB.Net問題

C#は素晴らしい MyClassのC#

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using com.handpoint.api; 
namespace WindowsGettingStartedApp 
{ 
    class MyClass : Events.Required 
    { 
     Hapi api; 
     Device device; 
     private Form1 UIClass; 
     public MyClass(Form1 form1) 
     { 
      InitApi(); 
      UIClass = form1; 
     } 
     public void InitApi() 
     { 
      string sharedSecret = "0102030405060708091011121314151617181920212223242526272829303132"; 
      api = HapiFactory.GetAsyncInterface(this).DefaultSharedSecret(sharedSecret); 
      // The api is now initialized, and we've set a default shared secret 
      // The shared secret is a unique string shared between the card reader and your mobile application. 
      // It prevents other people from connecting to your card reader. 
      // You should replace this default shared secret by the one sent by our support team. 
     } 
     public void DiscoverDevices() 
     { 
      api.ListDevices(ConnectionMethod.BLUETOOTH); 
      // This triggers the search for all the bluetooth devices around. 
      // You can also search for USB and Serial as a connection method 
     } 
     public void DeviceDiscoveryFinished(List<Device> devices) 
     { 
      foreach (Device device in devices) 
      { 
       if (device.Name != null) 
       { 
        if (device.Name.Equals("PP0513901435")) 
        // Put the name of your device, find it by pressing C then up arrow on your card reader keypad 
        { 
         this.device = device; 
         // We'll remember the device for this session, and you should too 
         api.UseDevice(this.device); 
         // Connection to the device is handled automatically in the API 
        } 
       } 
      } 
     } 
     // You can also connect directly to a specific device without having to discover the other devices around : 
     public void DirectConnect() 
     { 
      Device device = new Device("PP0513901435", "68:AA:D2:00:D5:27", "", ConnectionMethod.BLUETOOTH); 
      // The MAC Adress always has to be written in UPPER CASE 
      // new Device("name", "address", "port", ConnectionMethod); 
      api.UseDevice(device); 
     } 
     public bool Pay() 
     { 
      return api.Sale(new BigInteger("1000"), Currency.GBP); 
      // Let´s start our first payment of 10 pounds 
     } 
     public void SignatureRequired(SignatureRequest signatureRequest, Device device) 
     { 
      // You'll be notified here if a sale process needs a signature verification 
      // A signature verification is needed if the cardholder uses an MSR or a chip & signature card 
      // This method will not be invoked if a transaction is made with a Chip & PIN card 
      api.SignatureResult(true); // This line means that the cardholder ALWAYS accepts to sign the receipt. 
      // A specific line will be displayed on the merchant receipt for the cardholder to be able to sign it 
     } 
     public void EndOfTransaction(TransactionResult transactionResult, Device device) 
     { 
      UIClass.DisplayReceipts(transactionResult.MerchantReceipt, transactionResult.CustomerReceipt); 
     } 
     public void Disconnect() 
     { 
      api.Disconnect(); 
     } 
    } 
} 

C#は偉大なのForm1

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
namespace WindowsGettingStartedApp 
{ 
    public partial class Form1 : Form 
    { 
     MyClass my; 
     public Form1() 
     { 
      InitializeComponent(); 
      my = new MyClass(this); 
     } 
     private void PayButton_Click(object sender, EventArgs e) 
     { 
      my.Pay(); 
     } 
     private void ConnectButton_Click(object sender, EventArgs e) 
     { 
      my.DiscoverDevices(); 
      // my.DirectConnect(); 
     } 
     private void DisconnectButton_Click(object sender, EventArgs e) 
     { 
      my.Disconnect(); 
     } 
     public delegate void UpdateReceiptsCallback(string MerchantReceipt, string CustomerReceipt); 
     public void DisplayReceipts(string MerchantReceipt, string CustomerReceipt) 
     { 
      // Only need to check for one of the webBrowsers 
      if (MerchantReceiptBrowser.InvokeRequired) 
      { 
       UpdateReceiptsCallback d = new UpdateReceiptsCallback(DisplayReceipts); 
       this.Invoke(d, new object[] { MerchantReceipt, CustomerReceipt }); 
      } 
      else 
      { 
       MerchantReceiptBrowser.DocumentText = MerchantReceipt; 
       CardholderReceiptBrowser.DocumentText = CustomerReceipt; 
      } 
     } 
    } 
} 

マイVB.Net MyClassの変換

Imports System.Collections.Generic 
Imports System.Linq 
Imports System.Text 
Imports com.handpoint.api 
Namespace WindowsGettingStartedApp 

Class [MyClass] 
    Inherits Events.Required 

を作品上の行がエラーを取得します動作します。クラス他のクラスからのみ継承できます

Private api As Hapi 
    Private device As Device 
    Private UIClass As Form1 
    Public Sub New(form1 As Form1) 
     InitApi() 
     UIClass = form1 
    End Sub 
    Public Sub InitApi() 
     Dim sharedSecret As String = "0102030405060708091011121314151617181920212223242526272829303132" 
     api = HapiFactory.GetAsyncInterface(Me).DefaultSharedSecret(sharedSecret) 
     ' The api is now initialized, and we've set a default shared secret 
     ' The shared secret is a unique string shared between the card reader and your mobile application. 
     ' It prevents other people from connecting to your card reader. 
     ' You should replace this default shared secret by the one sent by our support team. 
    End Sub 
    Public Sub DiscoverDevices() 
     api.ListDevices(ConnectionMethod.BLUETOOTH) 
     ' This triggers the search for all the bluetooth devices around. 
     ' You can also search for USB and Serial as a connection method 
    End Sub 
    Public Sub DeviceDiscoveryFinished(devices As List(Of Device)) 
     For Each device As Device In devices 
      If device.Name IsNot Nothing Then 
      If device.Name.Equals("PP0513901435") Then 
        ' Put the name of your device, find it by pressing C then up arrow on your card reader keypad 
        Me.device = device 
        ' We'll remember the device for this session, and you should too 
         ' Connection to the device is handled automatically in the API 
        api.UseDevice(Me.device) 
       End If 
      End If 
     Next 
    End Sub 
    ' You can also connect directly to a specific device without having to discover the other devices around : 
    Public Sub DirectConnect() 
     Dim device As New Device("PP0513901435", "68:AA:D2:00:D5:27", "", ConnectionMethod.BLUETOOTH) 
     ' The MAC Adress always has to be written in UPPER CASE 
     ' new Device("name", "address", "port", ConnectionMethod); 
     api.UseDevice(device) 
    End Sub 
    Public Function Pay() As Boolean 
     Return api.Sale(New BigInteger("1000"), Currency.GBP) 
     ' Let´s start our first payment of 10 pounds 
    End Function 
    Public Sub SignatureRequired(signatureRequest As SignatureRequest, device As Device) 
     ' You'll be notified here if a sale process needs a signature verification 
     ' A signature verification is needed if the cardholder uses an MSR or a chip & signature card 
     ' This method will not be invoked if a transaction is made with a Chip & PIN card 
     api.SignatureResult(True) 
     ' This line means that the cardholder ALWAYS accepts to sign the receipt. 
     ' A specific line will be displayed on the merchant receipt for the cardholder to be able to sign it 
    End Sub 

    Public Sub EndOfTransaction(transactionResult As TransactionResult, device As Device) 
     UIClass.DisplayReceipts(transactionResult.MerchantReceipt, transactionResult.CustomerReceipt) 
    End Sub 
    Public Sub Disconnect() 
     api.Disconnect() 
    End Sub 
End Class 
End Namespace 

マイVB.NetをForm1

Imports System.Collections.Generic 
Imports System.ComponentModel 
Imports System.Data 
Imports System.Drawing 
Imports System.Linq 
Imports System.Text 
Imports System.Windows.Forms 
Namespace WindowsGettingStartedApp 
Public Partial Class Form1 
    Inherits Form 
    Private my As [MyClass] 
    Public Sub New() 
     InitializeComponent() 

上の行は私にエラーを与えている 'のInitializeComponent' 宣言されていません。保護レベルのためにアクセスできない場合があります。 フォーム上のオブジェクトを参照するときに上記のエラーが発生します。

 my = New [MyClass](Me) 
    End Sub 
    Private Sub PayButton_Click(sender As Object, e As EventArgs) 
     my.Pay() 
    End Sub 
    Private Sub ConnectButton_Click(sender As Object, e As EventArgs) 
     my.DiscoverDevices() 
     ' my.DirectConnect(); 
    End Sub 

    Private Sub DisconnectButton_Click(sender As Object, e As EventArgs) 
     my.Disconnect() 
    End Sub 
    Public Delegate Sub UpdateReceiptsCallback(MerchantReceipt As String, CustomerReceipt As String) 
    Public Sub DisplayReceipts(MerchantReceipt As String, CustomerReceipt As String) 
     ' Only need to check for one of the webBrowsers 
     If MerchantReceiptBrowser.InvokeRequired Then 
      Dim d As New UpdateReceiptsCallback(AddressOf DisplayReceipts) 
      Me.Invoke(d, New Object() {MerchantReceipt, CustomerReceipt}) 
     Else 
      MerchantReceiptBrowser.DocumentText = MerchantReceipt 
      CardholderReceiptBrowser.DocumentText = CustomerReceipt 
     End If 
    End Sub 
End Class 
End Namespace 

マイForm1.Designer.vb

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ 
Partial Class Form1 
Inherits System.Windows.Forms.Form 

'Form overrides dispose to clean up the component list. 
<System.Diagnostics.DebuggerNonUserCode()> _ 
Protected Overrides Sub Dispose(ByVal disposing As Boolean) 
    Try 
     If disposing AndAlso components IsNot Nothing Then 
      components.Dispose() 
     End If 
    Finally 
     MyBase.Dispose(disposing) 
    End Try 
End Sub 

'Required by the Windows Form Designer 
Private components As System.ComponentModel.IContainer 

'NOTE: The following procedure is required by the Windows Form Designer 
'It can be modified using the Windows Form Designer. 
'Do not modify it using the code editor. 
<System.Diagnostics.DebuggerStepThrough()> _ 
Private Sub InitializeComponent() 
    components = New System.ComponentModel.Container 
    Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font 
    Me.Text = "Form1" 
End Sub 
End Class 

任意の洞察力は素晴らしいことです。私は何かシンプルなものを欠いていると確信していますが、再び初心者です。私はエラーを受けている箇所を太字にしました。助けてくれてありがとう。それはInitializeComponentは、フォームデザイナファイルで宣言されているため、2番目のエラーがある

Implements Events.Required 

代わりの

Inherits Events.Required 

を読む必要がありますのでEvents.Requiredインターフェイスがあるので

+0

コードを二重引用符で囲まないように投稿を修正してください。 –

答えて

3

最初のエラーがあるあなたがないかもしれませんあなたのアプリケーションに含まれています。このフォームの外観を調べる場合は、プロジェクトに新しいフォームを追加します。

+0

ありがとうございます。インプリメンテーションは依然としてエラーを出す。今はサブが含まれていなければならないと言います。私はあなたがデザイナーと何かをしていると思う。私がしたことは、新しい形で作られました。単純に上記のコードをコピーして貼り付けたよりも簡単です。私はフォームデザイナーに何か不足していると思いますが、何がわからないのでしょうか?方向性に感謝します。他に何が見つかるかわかります。上記のデザイナーコードを追加しました。再度、感謝します。 – nathan

+1

インターフェイスの各メンバーの後に、 'implements events.required.whatever'を追加する必要があります。インターフェイスのチュートリアルを参照してください。 – FloatingKiwi