0

当我想按下按钮时,它会给我错误“找不到密钥”。我想要变量“dzien”的默认值 = 0。

Imports System.IO.IsolatedStorage

Partial Public Class _1
Inherits PhoneApplicationPage
Private dzien As Integer

Public Sub New()
    InitializeComponent()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button2.Click
    dzien = CInt(IsolatedStorageSettings.ApplicationSettings("dzien"))
    Try
        dzien = CInt(IsolatedStorageSettings.ApplicationSettings("dzien"))
    Catch ex As KeyNotFoundException
        dzien = 0
    End Try
    If dzien = 0 Then
        TextBox1.Text += "dzien jest 0 !"
    End If
End Sub
Private Sub Class_1_Unloaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Unloaded
    IsolatedStorageSettings.ApplicationSettings("dzien") = dzien
End Sub

结束类

4

1 回答 1

1

删除第一dzien = CInt(IsolatedStorageSettings.ApplicationSettings("dzien"))行。它应该如下所示:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button2.Click
    Try
        dzien = CInt(IsolatedStorageSettings.ApplicationSettings("dzien"))
    Catch ex As KeyNotFoundException
        dzien = 0
    End Try
    If dzien = 0 Then
        TextBox1.Text += "dzien jest 0 !"
    End If
End Sub
于 2012-10-10T12:05:44.733 回答