I have a form with a calendar and a textbox with 2 buttons. The calendar is the vb 2010 tool and the textbox overlaps it so that when a day is selected on the calendar you can make an appointment for that day. i have a save button and a back buton... I am having trouble with the save feature... there is always a file error... here is my code

Imports System.IO

Public Class Form2
    Dim m As MsgBoxResult
    Dim t As String
    'Private cal As String = "C:\cal.txt"

    Private Sub MonthCalendar1_DateSelected(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateSelected
        t = MonthCalendar1.SelectionRange.Start.ToString & MonthCalendar1.SelectionRange.Start.Day.ToString
        Try
            If File.Exists(t & ".txt") = True Then
                MonthCalendar1.Enabled = False
                MonthCalendar1.Hide()
                TextBox1.Enabled = True
                TextBox1.Show()
                Button1.Enabled = True
                Button1.Show()
                Button2.Enabled = True
                Button2.Show()
                TextBox1.Text = File.ReadAllText(t & ".txt")
            Else
                m = MsgBox("Would you like to enter information for this day?", MsgBoxStyle.YesNo)
                If m = MsgBoxResult.Yes Then
                    MonthCalendar1.Enabled = False
                    MonthCalendar1.Hide()
                    TextBox1.Enabled = True
                    TextBox1.Show()
                    TextBox1.Text = ""
                    Button1.Show()
                    Button1.Enabled = True
                    Button2.Show()
                    Button2.Enabled = True
                End If
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Enabled = False
        TextBox1.Hide()
        Button1.Show()
        Button1.Enabled = False
        Button2.Show()
        Button2.Enabled = False
        MonthCalendar1.Enabled = True
        MonthCalendar1.Show()

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'IO.File.WriteAllText(cal, TextBox1.Text)
        Try
            If TextBox1.Text = "" Then
                If File.Exists(t & ".txt") = True Then
                    File.Delete(t & ".txt")
                End If
            End If
            If TextBox1.Text.Length > 0 Then
                File.WriteAllText(t, TextBox1.Text)
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim m1 As MsgBoxResult
        t = MonthCalendar1.SelectionRange.Start.ToString & MonthCalendar1.SelectionRange.Start.Day.ToString
        'If IO.File.Exists(cal) Then
        'TextBox1.Text = IO.File.ReadAllText(cal)
        'End If
        If Date.Today = MonthCalendar1.TodayDate And File.Exists(t & ".txt") = True Then
            m1 = MsgBox("You have appointments today. Would you like to view them?", MsgBoxStyle.YesNo)
            If m1 = MsgBoxResult.Yes Then
                MonthCalendar1.Enabled = False
                MonthCalendar1.Hide()
                TextBox1.Enabled = True
                TextBox1.Show()
                Button1.Show()
                Button1.Enabled = True
                Button2.Show()
                Button2.Enabled = True
                TextBox1.Text = File.ReadAllText(t & ".txt")
            End If
        End If
    End Sub
End Class

Any help?

Recommended Answers

All 2 Replies

Please give the error code and description so we can solve it...

interface for calender appointment system

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.