1

基本的に通貨コンバーターである Windows Phone 7.1 アプリケーションを作成しようとしています。メソッドを使用DownloadStringAsyncして、特定の Web サイトから為替レートを含む短い文字列を取得しています。Visual Studio 2010 でテストしたところ、DownloadString問題なく動作しました。ただし、電話アプリケーション用ではありません。ここで何をする必要がありますか? 私は本当にそれを理解することはできません。

Partial Public Class MainPage
Inherits PhoneApplicationPage
Dim webClient As New System.Net.WebClient
Dim a As String
Dim b As String
Dim result As String = Nothing
' Constructor
Public Sub New()
    InitializeComponent()
End Sub

Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
    a = "USD"
    b = "GBP"
    webClient = New WebClient
    Dim result As String = webClient.DownloadStringAsync(New Uri("http://rate-exchange.appspot.com/currency?from=" + a + "&to=" + b) as String)
    TextBox1.Text = result
End Sub

クラス終了

4

2 に答える 2

3

ここでいくつか間違っています:

  1. DownloadStringAsync値を返しません ( voidC# 用語ではメソッド)
  2. 変数のDownloadStringCompletedイベントを処理する必要があります。WebClientイベント ハンドラで結果を取得できます。

コードを次のように変更して、上記を機能させることができます。

Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
    a = "USD"
    b = "GBP"
    webClient = New WebClient
    'Add the event handler here
    AddHandler webClient.DownloadStringCompleted, AddressOf webClient_DownloadStringCompleted            
    Dim url As String = "http://rate-exchange.appspot.com/currency?from=" & a & "&to=" & b            
    webClient.DownloadStringAsync(New Uri(url))
End Sub

Private Sub webClient_DownloadStringCompleted(ByVal sender as Object,ByVal e as DownloadStringCompletedEventArgs)
    TextBox1.Text = e.result
End Sub
于 2014-07-23T03:57:31.223 に答える