When I want to press button it gives me error “key not found”. I want to have the default value of variable “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
End Class
Remove the first
dzien = CInt(IsolatedStorageSettings.ApplicationSettings("dzien"))line. It should look like this: