Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Final Project and I need serious help.

rapwellsrapwells Posts: 3Member
You will create an application that reads and writes a sequential file. The sequential file contains a Rolodex with a notes field. The notes field contains RTF text instead of plain text. The sequential file is located in Doc Sharing and is called FinalProjectDataFile.txt.

The fields contain the following data:

Comments

  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭
    I've seen this exact project before on this forum.

    Are you having problems with something I can help you with.
  • rapwellsrapwells Posts: 3Member
    I have gotten most of it completed. I am having a problem with a little code.
    [code]
    'Richard M Wells
    'IT293 Final Project
    'Still needs a 100

    Imports System.IO
    Public Class frmMain

    Dim ArrayCount As Integer
    Dim ArrayCurrentIndex As Integer
    Dim MyPersonArray() As Person
    Dim IsNew As Boolean
    'Give someone Structure ha ha
    Structure Person
    Dim FirstName As String
    Dim LastName As String
    Dim address As String
    Dim city As String
    Dim state As String
    Dim zipcode As String
    Dim lastcontractdate As String
    Dim notes As String
    End Structure
    'Took the bar out
    Sub ShowNavigateStatusBarInfo()
    TIndex.Text = ArrayCurrentIndex + 1
    TCount.Text = MyPersonArray.Length
    End Sub
    'To try and Read a Sequential File

    Sub ReadSequentialFile(ByRef PersonArr As Person())
    Dim sBuffer As String
    Dim PersonCount As Integer
    Using oReader As StreamReader = File.OpenText(Application.StartupPath & "Doc SharingFinalProjectDataFile.txt")
    While Not (oReader.EndOfStream)
    ReDim Preserve PersonArr(PersonCount)
    sBuffer = oReader.ReadLine
    Dim CurrentPerson() As String
    CurrentPerson = Split(sBuffer, "','")
    With PersonArr(PersonCount)
    .FirstName = CurrentPerson(0).ToString
    .LastName = CurrentPerson(1).ToString
    .address = CurrentPerson(2).ToString
    .city = CurrentPerson(3).ToString
    .state = CurrentPerson(4).ToString
    .zipcode = CurrentPerson(5).ToString
    .lastcontractdate = CurrentPerson(6).ToString
    .notes = CurrentPerson(7).ToString()
    End With
    PersonCount += 1
    End While
    End Using
    End Sub
    'To clear the screen
    Sub ClearScreen()
    txtFirstName.ResetText()
    txtLastName.ResetText()
    txtAddress.ResetText()
    txtCity.ResetText()
    txtState.ResetText()
    mskZipCode.ResetText()
    dtpContactDate.Text = Now.Date.ToString
    rtxtNotes.ResetText()
    txtFirstName.Focus()
    End Sub
    'Write Array Data To Text File (FinalProjectDataFile.txt)
    Sub WriteSequentialFile()
    If MyPersonArray Is Nothing Then Exit Sub
    If MyPersonArray.Length = 0 Then Exit Sub
    Dim myWriteString As String = ""
    Dim i As Integer
    Dim ioFile As New StreamWriter(Application.StartupPath & "Doc SharingFinalProjectDataFile.txt")

    For i = 0 To MyPersonArray.Length - 1
    myWriteString = ""
    myWriteString = MyPersonArray(i).FirstName
    myWriteString = myWriteString & "','" & MyPersonArray(i).LastName
    myWriteString = myWriteString & "','" & MyPersonArray(i).address
    myWriteString = myWriteString & "','" & MyPersonArray(i).city
    myWriteString = myWriteString & "','" & MyPersonArray(i).state
    myWriteString = myWriteString & "','" & MyPersonArray(i).zipcode
    myWriteString = myWriteString & "','" & MyPersonArray(i).lastcontractdate
    myWriteString = myWriteString & "','" & MyPersonArray(i).notes
    ioFile.WriteLine(myWriteString)
    Next
    ioFile.Close()
    MessageBox.Show("Successfully Saved File To the Database!", "Final Project", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub



    Private Sub mnuAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAdd.Click
    IsNew = True
    ClearScreen()
    End Sub

    Private Sub TFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TFirst.Click
    IsNew = False

    If MyPersonArray Is Nothing Then
    MessageBox.Show("There is no record to show today!", "Final Project", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Exit Sub
    End If

    If MyPersonArray.Length > 0 Then
    With MyPersonArray(0)
    txtFirstName.Text = .FirstName
    txtLastName.Text = .LastName
    txtAddress.Text = .address
    txtCity.Text = .city
    txtState.Text = .state
    mskZipCode.Text = .zipcode
    dtpContactDate.Text = .lastcontractdate
    ShowNotesToRichTextBox(.notes)
    ArrayCurrentIndex = 0
    ShowNavigateStatusBarInfo()
    End With
    Else
    MessageBox.Show("There is no record to show today!", "Final Project", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End If
    End Sub

    Private Sub mnuChange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuChange.Click
    Dim myIndex As Integer = -1
    If IsNew = True Then
    If MyPersonArray Is Nothing Then
    myIndex = 0
    Else
    myIndex = MyPersonArray.Length
    End If
    ReDim Preserve MyPersonArray(myIndex)
    Else
    If MyPersonArray Is Nothing Then
    MessageBox.Show("Cannot Update at This Time!", "Final Project", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Exit Sub
    End If
    myIndex = ArrayCurrentIndex
    End If
    ArrayCurrentIndex = ArrayCount
    With MyPersonArray(myIndex)
    .FirstName = txtFirstName.Text.Trim
    .LastName = txtLastName.Text.Trim
    .address = txtAddress.Text.Trim
    .city = txtCity.Text.Trim
    .state = txtState.Text.Trim
    .zipcode = mskZipCode.Text
    .lastcontractdate = dtpContactDate.Text
    .notes = GetNotesString()
    End With

    If IsNew = True Then
    MessageBox.Show("Successfully Added!", "Final Project", MessageBoxButtons.OK, MessageBoxIcon.Information)
    ArrayCurrentIndex = MyPersonArray.Length - 1
    Else
    MessageBox.Show("Successfully Updated!", "Final Project", MessageBoxButtons.OK, MessageBoxIcon.Information)
    ArrayCurrentIndex = myIndex
    End If

    IsNew = False
    ShowNavigateStatusBarInfo()
    End Sub
    'Getting better
    Private Sub TLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TLast.Click
    IsNew = False
    If MyPersonArray Is Nothing Then
    MessageBox.Show("There is no record Please hang up and try again!", "Final Project", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Exit Sub
    End If
    If MyPersonArray.Length > 0 Then
    ArrayCurrentIndex = MyPersonArray.Length - 1
    With MyPersonArray(ArrayCurrentIndex)
    txtFirstName.Text = .FirstName
    txtLastName.Text = .LastName
    txtAddress.Text = .address
    txtCity.Text = .city
    txtState.Text = .state
    mskZipCode.Text = .zipcode
    dtpContactDate.Text = .lastcontractdate
    ShowNotesToRichTextBox(.notes)
    ArrayCurrentIndex = MyPersonArray.Length - 1
    ShowNavigateStatusBarInfo()
    End With
    Else
    MessageBox.Show("There is no record Please hang up and try again!", "Final Project", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End If
    End Sub

    Private Sub TPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TPrevious.Click
    IsNew = False
    If MyPersonArray Is Nothing Then
    MessageBox.Show("There is no record Please hang up and try again!", "Final Project", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Exit Sub
    End If
    If ArrayCurrentIndex > 0 Then
    ArrayCurrentIndex = ArrayCurrentIndex - 1
    With MyPersonArray(ArrayCurrentIndex)
    txtFirstName.Text = .FirstName
    txtLastName.Text = .LastName
    txtAddress.Text = .address
    txtCity.Text = .city
    txtState.Text = .state
    mskZipCode.Text = .zipcode
    dtpContactDate.Text = .lastcontractdate
    ShowNotesToRichTextBox(.notes)
    ShowNavigateStatusBarInfo()
    End With
    Else
    MessageBox.Show("There is no record Please hang up and try again!", "Final Project", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End If
    End Sub

    Private Sub TNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TNext.Click
    IsNew = False
    If MyPersonArray Is Nothing Then
    MessageBox.Show("There is no record Please hang up and try again!", "Final Project", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Exit Sub
    End If
    If ArrayCurrentIndex < MyPersonArray.Length - 1 Then
    ArrayCurrentIndex = ArrayCurrentIndex + 1
    With MyPersonArray(ArrayCurrentIndex)
    txtFirstName.Text = .FirstName
    txtLastName.Text = .LastName
    txtAddress.Text = .address
    txtCity.Text = .city
    txtState.Text = .state
    mskZipCode.Text = .zipcode
    dtpContactDate.Text = .lastcontractdate
    ShowNotesToRichTextBox(.notes)
    ShowNavigateStatusBarInfo()
    End With
    Else
    MessageBox.Show("There is no record Please hang up and try again!", "Final Project", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End If
    End Sub
    'From Nodes data to show in Rich Text Box
    Sub ShowNotesToRichTextBox(ByVal NotesString As String)
    Dim MyNote() As String
    MyNote = Split(NotesString, "\")
    rtxtNotes.Lines = MyNote
    End Sub
    'To Store Data From Rich Text box to Nodes data format
    Function GetNotesString() As String
    Dim myString As String = ""
    Dim i As Integer

    For i = 0 To rtxtNotes.Lines.Length - 1
    myString = myString & "\" & rtxtNotes.Lines.GetValue(i).ToString
    Next

    If rtxtNotes.Text.Trim <> "" Then
    Return myString.Substring(2, myString.Length - 2)
    Else
    Return ""
    End If
    End Function
    'Try and load everything correctly
    Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    mnuSave.Enabled = False
    mnuFirst.Enabled = False
    mnuPrevious.Enabled = False
    mnuNext.Enabled = False
    mnuLast.Enabled = False
    mnuAdd.Enabled = False
    mnuChange.Enabled = False
    mnuDelete.Enabled = False

    TSave.Enabled = False
    TFirst.Enabled = False
    TPrevious.Enabled = False
    TNext.Enabled = False
    TLast.Enabled = False

    End Sub
    ' Enable some Control
    Sub EnableControl()
    mnuSave.Enabled = True
    mnuFirst.Enabled = True
    mnuPrevious.Enabled = True
    mnuNext.Enabled = True
    mnuLast.Enabled = True
    mnuAdd.Enabled = True
    mnuChange.Enabled = True
    mnuDelete.Enabled = True

    TSave.Enabled = True
    TFirst.Enabled = True
    TPrevious.Enabled = True
    TNext.Enabled = True
    TLast.Enabled = True
    End Sub

    Private Sub TOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TOpen.Click
    ReadSequentialFile(MyPersonArray)
    If MyPersonArray Is Nothing Then
    ArrayCount = 0
    ArrayCurrentIndex = -1
    TIndex.Text = 0
    TCount.Text = 0
    mnuAdd_Click(sender, e)
    Else
    If MyPersonArray.Length > 0 Then
    ArrayCurrentIndex = 0
    TFirst_Click(sender, e)
    End If
    End If
    EnableControl()
    MessageBox.Show("Open from the Final Project", "Final Project", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub

    Private Sub mnuFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFirst.Click
    TFirst_Click(sender, e)
    End Sub

    Private Sub mnuPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuPrevious.Click
    TPrevious_Click(sender, e)
    End Sub

    Private Sub mnuNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuNext.Click
    TNext_Click(sender, e)
    End Sub

    Private Sub mnuLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuLast.Click
    TLast_Click(sender, e)
    End Sub

    Private Sub mnuOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOpen.Click
    TOpen_Click(sender, e)
    End Sub

    Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click
    Me.Close()
    End Sub

    Private Sub mnuDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuDelete.Click

    If IsNew = True Then
    MessageBox.Show("Cannot Delete!", "Final Project", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Exit Sub
    End If

    Dim PersonTemp() As Person = Nothing
    Dim c As Integer
    'Array Copy To Delete the Selected File
    For x As Integer = 0 To UBound(MyPersonArray)
    If x <> ArrayCurrentIndex Then
    ReDim Preserve PersonTemp(c)
    PersonTemp(c) = MyPersonArray(x)
    c += 1
    End If
    Next x
    'Reasign Temp Array To Person Array Which we use hopefully
    For i As Integer = 0 To UBound(PersonTemp)
    ReDim Preserve MyPersonArray(i)
    MyPersonArray(i) = PersonTemp(i)
    Next

    MessageBox.Show("Successfully Delete!", "Final Project", MessageBoxButtons.OK, MessageBoxIcon.Information)
    TFirst_Click(sender, e)

    End Sub

    Private Sub TSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TSave.Click
    WriteSequentialFile()
    End Sub

    Private Sub mnuSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSave.Click
    TSave_Click(sender, e)
    End Sub

    Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter

    End Sub


    'For closing when not sure what to do
    Private Sub ToolStripButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton5.Click
    Me.Close()

    End Sub
    End Class
    [code]
  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭
    Ok, just tell me what line the code is crashing on, and what the exact error message it gives (the more details the better).

    I will skim through that code and see if anything jumps out, but without your form, I cannot execute the code. No need to send the form, we can figure this out simply by you giving me the line it crashs on and the error.

    -Sean
Sign In or Register to comment.