Turn on thread page Beta

Visual Basic - Saving data and reading it back watch

    • Thread Starter
    Offline

    9
    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 Rep
    Offline

    15
    ReputationRep:
     Official Rep
    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
 
 
 
Poll
Do you think parents should charge rent?
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

Groups associated with this forum:

View associated groups

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

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