当我想按下按钮时,它会给我错误“找不到钥匙”。我希望变量“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
结束班
答案 0 :(得分: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