Click here to Skip to main content
15,875,581 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my program I need to be able to set appointments on calendar and receive reminders when the date of the ones I've set is coming closer, to save the details I am using text files. I have tried using the code below the problem is that whenever I try to save details related to an appointment the data is actually not saved and therefore the appointment is not set. Does anyone know where I am going wrong?thank you in advance.

button1= save and button2= back

What I have tried:

Imports System.IO


Public Class Form10

    Dim t As String
    Dim msg As MsgBoxResult

    Private Sub MonthCalendar1_DateSelected(sender As Object, e As DateRangeEventArgs) Handles MonthCalendar1.DateSelected
        t = MonthCalendar1.SelectionRange.Start.Month.ToString & MonthCalendar1.SelectionRange.Start.Day.ToString
        Try
            If File.Exists(t & "C:\Users\Windows 7 User\Desktop\bookings.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 & "C:\Users\Windows 7 User\Desktop\bookings.txt")


            Else

                msg = MsgBox("Would you like to create a booking for this date?", MsgBoxStyle.YesNo)
                If msg = MsgBoxResult.Yes Then

                    MonthCalendar1.Enabled = False
                    MonthCalendar1.Hide()
                    TextBox1.Enabled = True
                    TextBox1.Show()
                    TextBox1.Text = ""
                    button1.Enabled = True
                    button1.Show()
                    button2.Enabled = True
                    button2.Show()


                End If
            End If

        Catch ex As Exception
            MsgBox(ex.Message)

        End Try
    End Sub

    Private Sub button2_Click(sender As Object, e As EventArgs) Handles button2.Click
        TextBox1.Enabled = False
        TextBox1.Hide()
        button1.Enabled = False
        button1.Hide()
        button2.Enabled = False
        button2.Hide()
        MonthCalendar1.Enabled = True
        MonthCalendar1.Show()



    End Sub

    Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
        Try
            If TextBox1.Text = "" Then
                If File.Exists(t & "C:\Users\Windows 7 User\Desktop\bookings.txt") = True Then
                    File.Delete(t & "C:\Users\Windows 7 User\Desktop\bookings.txt")

                    If TextBox1.Text.Length > 0 Then
                        File.WriteAllText(t & "C:\Users\Windows 7 User\Desktop\bookings.txt", TextBox1.Text)




                    End If

                End If
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Form10_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim msg1 As MsgBoxResult
        t = MonthCalendar1.SelectionRange.Start.Month.ToString & MonthCalendar1.SelectionRange.Start.Day.ToString
        If Date.Today = MonthCalendar1.TodayDate And File.Exists(t & "C:\Users\Windows 7 User\Desktop\bookings.txt") = True Then

        End If
        If msg1 = MsgBox(" You have a booking set for today, would like to view it?", MsgBoxStyle.YesNo) Then
            If msg1 = MsgBoxResult.Yes 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 & "C:\Users\Windows 7 User\Desktop\bookings.txt")
            End If




        End If

    End Sub
End Class
Posted
Updated 18-Feb-18 8:10am
v2

1 solution

This does not look ok:
If File.Exists(t & "C:\Users\Windows 7 User\Desktop\bookings.txt")
it should be something like:
If File.Exists("C:\Users\Windows 7 User\Desktop\bookings" & t & ".txt")
And even better:
If File.Exists(My.Computer.FileSystem.SpecialDirectories.Desktop & 
"\bookings" & t & ".txt")
 
Share this answer
 
v2
Comments
faiqaa 18-Feb-18 15:01pm    
Initially it was something like this (t & ".txt"), this did not work either and I want to use a specific text file which I've already made called "bookings". I have tried the two methods suggested by you but it does not seem to work,I am allowed to type in the details of the booking by clicking on the date,then I click SAVE and BACK. I click on the same date again to view the booking instead of showing me what I previously wrote it asks me again whether I would like to book for the same date again. Thank you for your time.
RickZeeland 18-Feb-18 15:06pm    
Then just try to use "bookings.txt", if all goes well the file will be created in the folder where your .exe file is located.
If it does not work set breakpoints and inspect the code by hovering with your mouse above it ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900