Jump to content

Input/Output Program Problem

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
Bondi

Bondi

    Newbie

  • Members
  • Pip
  • 6 posts
I know this is a really simple fix, but as part of my college assignment, I have to create a program that calculates how many spaces are in a document.

I keep getting two errors which are the _ in the code which was on the worksheet and I put that in.

Imports System.IO

Module Module1


    Sub Main()

        Dim inFile As StreamReader = File.OpenText("History.dat")

        Dim inputString As String

        Dim linecount As Integer

        Dim blankCount As Integer

        Dim index As Integer

        Dim outFile As StreamWriter = File.CreateText("Data.out")


        While (inFile.Peek <> -1)

            inputString = inFile.ReadLine

            linecount += 1

            blankCount = 0

            index = inputString.IndexOf(" ")


            While (index <> -1)

                blankCount += 1

                If (inputString.Length <> 1) Then

                    inputString = inputString.Substring (index + 1, [COLOR="red"][B]_[/B][/COLOR] inputString.Length - (index +1))

                    index = inputString.IndexOf(" ")

                Else

                    index = -1

                End If

            End While

            outFile.WriteLine("Line" & linecount & "Contains" [COLOR="red"][B]_[/B][/COLOR] & blankCount & "blanks.")

        End While

        outFile.Close()

        inFile.Close()

        Console.WriteLine("Finished.")

        Console.Write("Press Enter To Quit")

        Console.Read()

    End Sub


End Module

I get the two errors:

Identifier Unexpected


- Bondi

#2
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
Underlines are used to tell that the code continue on the next line(if you want to split a command over more than one line). Since you have them in the middle of a line they are causing an error. You can just remove the underlines.

Edited by Vswe, 17 January 2011 - 08:39 AM.


#3
Bondi

Bondi

    Newbie

  • Members
  • Pip
  • 6 posts
Thank you, I sound so stupid now :c-grin:



- Bondi