Hey there! Sign in to join this conversationNew here? Join for free

Visual Basic - Saving data and reading it back Watch

    • Thread Starter
    Offline

    8
    ReputationRep:
    Hi there,

    I am well aware Visual Basic is referred to as an 'easy' programming language, and in most cases I'd agree. However I'm having trouble getting the data I input to save for me to then have it read back to me. I'm sure it's a simple fix, but I'm new to programming and would appreciate the help.
    And no, this is not homework/coursework.
    Code I've done so far:
    Imports System.IO
    Module Module1
    Structure Employee
    Dim EmployeeNumber As Integer
    Dim EmployeeName As String
    Dim Surname As String
    Dim Department As String
    Dim StartDate As Date
    Dim Salary As Integer
    End Structure
    Sub Main()
    Dim Employees(2) As Employee
    Dim Answer As Integer
    Console.WriteLine("Menu: ")

    Console.WriteLine(" 1. Input the data.")
    Console.WriteLine(" 2. Display the data.")
    Console.WriteLine(" 3. Quit.")
    Answer = Console.ReadLine
    If Answer = "1" Then
    Using FileWriter As New StreamWriter("Records.csv", False)
    For Count = 0 To 2
    FileWriter.WriteLine(Employees(C ount))
    Console.WriteLine("Input the employee number for Employee " & Count + 1)
    Employees(Count).EmployeeNumber = Console.ReadLine
    Console.WriteLine("Input the employee name for Employee")
    Employees(Count).EmployeeName = Console.ReadLine
    Console.WriteLine("Input the employee Surname")
    Employees(Count).Surname = Console.ReadLine
    Console.WriteLine("Input the employee department")
    Employees(Count).Department = Console.ReadLine
    Console.WriteLine("Input the employee salary")
    Employees(Count).Salary = Console.ReadLine
    Console.WriteLine("Input the employee start date")
    Employees(Count).StartDate = Console.ReadLine
    Console.WriteLine()
    Next
    End Using
    ElseIf Answer = "2" Then
    Using FileReader As New StreamReader("Records.csv")
    For Count = 0 To 2
    'Employees(Count) = FileReader.ReadLine()
    Console.WriteLine("Employee " & Count + 1 & " Number: " & Employees(Count).EmployeeNumber)
    Console.WriteLine("Employee " & Count + 1 & " Name: " & Employees(Count).EmployeeName)
    Console.WriteLine("Employee " & Count + 1 & " Surname: " & Employees(Count).Surname)
    Console.WriteLine("Employee " & Count + 1 & " Department: " & Employees(Count).Department)
    Console.WriteLine("Employee " & Count + 1 & " Salary: " & Employees(Count).Salary)
    Console.WriteLine("Employee " & Count + 1 & " Start Date: " & Employees(Count).StartDate)
    Console.WriteLine()
    Next
    End Using
    ElseIf Answer = "3" Then
    Exit Sub
    Else
    Console.WriteLine("Error - Try again.")
    Do
    Answer = Console.ReadLine
    Loop Until Answer = "1" Or Answer = "2" Or Answer = "3"
    End If
    'Employees(0).EmployeeName = Console.ReadLine
    'Console.WriteLine("Employee 1's Number: " & Employees(0).EmployeeNumber)
    Console.ReadLine()

    End Sub





    End Module
    • Official TSR Representative
    Offline

    15
    ReputationRep:
    Sorry you've not had any responses about this. Are you sure you've posted in the right place? Here's a link to our subject forum which should help get you more responses if you post there.


    Just quoting in Danny Dorito so she can move the thread if needed :wizard:
    Spoiler:
    Show
    (Original post by Danny Dorito)
    x
    Offline

    22
    ReputationRep:
    (Original post by Prudator)
    Hi there,

    I am well aware Visual Basic is referred to as an 'easy' programming language, and in most cases I'd agree. However I'm having trouble getting the data I input to save for me to then have it read back to me. I'm sure it's a simple fix, but I'm new to programming and would appreciate the help.
    And no, this is not homework/coursework.
    Code I've done so far:
    Imports System.IO
    Module Module1
    Structure Employee
    Dim EmployeeNumber As Integer
    Dim EmployeeName As String
    Dim Surname As String
    Dim Department As String
    Dim StartDate As Date
    Dim Salary As Integer
    End Structure
    Sub Main()
    Dim Employees(2) As Employee
    Dim Answer As Integer
    Console.WriteLine("Menu: "

    Console.WriteLine(" 1. Input the data."
    Console.WriteLine(" 2. Display the data."
    Console.WriteLine(" 3. Quit."
    Answer = Console.ReadLine
    If Answer = "1" Then
    Using FileWriter As New StreamWriter("Records.csv", False)
    For Count = 0 To 2
    FileWriter.WriteLine(Employees(C ount))
    Console.WriteLine("Input the employee number for Employee " & Count + 1)
    Employees(Count).EmployeeNumber = Console.ReadLine
    Console.WriteLine("Input the employee name for Employee"
    Employees(Count).EmployeeName = Console.ReadLine
    Console.WriteLine("Input the employee Surname"
    Employees(Count).Surname = Console.ReadLine
    Console.WriteLine("Input the employee department"
    Employees(Count).Department = Console.ReadLine
    Console.WriteLine("Input the employee salary"
    Employees(Count).Salary = Console.ReadLine
    Console.WriteLine("Input the employee start date"
    Employees(Count).StartDate = Console.ReadLine
    Console.WriteLine()
    Next
    End Using
    ElseIf Answer = "2" Then
    Using FileReader As New StreamReader("Records.csv"
    For Count = 0 To 2
    'Employees(Count) = FileReader.ReadLine()
    Console.WriteLine("Employee " & Count + 1 & " Number: " & Employees(Count).EmployeeNumber)
    Console.WriteLine("Employee " & Count + 1 & " Name: " & Employees(Count).EmployeeName)
    Console.WriteLine("Employee " & Count + 1 & " Surname: " & Employees(Count).Surname)
    Console.WriteLine("Employee " & Count + 1 & " Department: " & Employees(Count).Department)
    Console.WriteLine("Employee " & Count + 1 & " Salary: " & Employees(Count).Salary)
    Console.WriteLine("Employee " & Count + 1 & " Start Date: " & Employees(Count).StartDate)
    Console.WriteLine()
    Next
    End Using
    ElseIf Answer = "3" Then
    Exit Sub
    Else
    Console.WriteLine("Error - Try again."
    Do
    Answer = Console.ReadLine
    Loop Until Answer = "1" Or Answer = "2" Or Answer = "3"
    End If
    'Employees(0).EmployeeName = Console.ReadLine
    'Console.WriteLine("Employee 1's Number: " & Employees(0).EmployeeNumber)
    Console.ReadLine()

    End Sub





    End Module
    Go to stack overflow and ask on there
 
 
 
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    What newspaper do you read/prefer?
    Help with your A-levels

    All the essentials

    The adventure begins mug

    Student life: what to expect

    What it's really like going to uni

    Rosette

    Essay expert

    Learn to write like a pro with our ultimate essay guide.

    Uni match

    Uni match

    Our tool will help you find the perfect course for you

    Study planner

    Create a study plan

    Get your head around what you need to do and when with the study planner tool.

    Study planner

    Resources by subject

    Everything from mind maps to class notes.

    Hands typing

    Degrees without fees

    Discover more about degree-level apprenticeships.

    A student doing homework

    Study tips from A* students

    Students who got top grades in their A-levels share their secrets

    Study help links and info

    Can you help? Study help unanswered threadsRules and posting guidelines

    Sponsored content:

    HEAR

    HEAR

    Find out how a Higher Education Achievement Report can help you prove your achievements.

    Groups associated with this forum:

    View associated groups
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

    Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

    Quick reply
    Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.