Results 1 to 12 of 12

Thread: Visual Studio 2013 Visual basic Easy program

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2014
    Posts
    8

    Visual Studio 2013 Visual basic Easy program

    So I am new to all of this I tried making a program that I need as soon as possible (Hope someone replies quick)

    So here is my code
    Imports System
    Imports System.IO


    Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim file As System.IO.StreamReader
    file =
    My.Computer.FileSystem.OpenTextFileReader("C:\Users\XXX\Desktop\stuff.txt")

    Dim file2 As System.IO.StreamWriter
    file2 = My.Computer.FileSystem.OpenTextFileWriter("C:\Users\XXX\Desktop\stuff2.txt", True)

    Dim line As String
    line = file.ReadLine()


    Dim words As String() = line.Split()
    Dim index As Integer = 0
    For Each word As String In words
    index += 1
    If String.Compare(word, "The", True) = 0 Then Exit For
    Next word

    If index < words.Length Then
    file2.WriteLine(words(index))
    file2.Close()
    Else
    file2.WriteLine("")
    file2.Close()
    End If
    End Sub
    End Class

    So What the program was supposed to do was read a certain txt file and then if it locates a word preceded by The it should place this word in the second file So it does that but the problem is I want it to Write them in the other file 1 after one On each line

    But when I test it it only prints the first line's word

    I hope you understand this and please reply Thanks

  2. #2
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,372

    Re: Visual Studio 2013 Visual basic Easy program

    you are only reading one line with this:
    line = file.ReadLine()

    so you only process the first line of the file. your way of searching for the word "the" is suboptimal (i.e. split and loop through the words). use .contains instead or learn regexp but maybe keep this for later.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2014
    Posts
    8

    Re: Visual Studio 2013 Visual basic Easy program

    SO is there any way to do this either with another bit of code or by improving this?

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2014
    Posts
    8

    Re: Visual Studio 2013 Visual basic Easy program

    Ok I will see what I can do then

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2014
    Posts
    8

    Re: Visual Studio 2013 Visual basic Easy program

    Could you give me an example?

  6. #6
    Addicted Member MetalInquisitor's Avatar
    Join Date
    Sep 2012
    Posts
    143

    Re: Visual Studio 2013 Visual basic Easy program

    Here is a basic tutorial. I recommend you read and do some exercises until you fully understand at least the first 4 chapters.

    http://www.homeandlearn.co.uk/NET/vbNet.html

  7. #7
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Visual Studio 2013 Visual basic Easy program

    Welcome to the forum. In future please provide a descriptive thread title. Right now your thread issue is meaningless to members. Next always post code inside of code or highlight tags. This can be written manually or via the tool menu interface. Finally only post code that we need to see. You have simply chucked us your whole class and said "work this out for your self".

    Break this into steps, your worrying about the end when the start is written poorly. This is step One. No splitting.

    vb Code:
    1. Imports System.IO
    2.  
    3. Public Class Form1
    4.  
    5.     Private ReadOnly FileLocation As String = "C:\Users\XXX\Desktop\stuff.txt"
    6.  
    7.     Private Sub Button1_Click(sender As Object, e As EventArgs)
    8.         Dim lines As String() = File.ReadAllLines(Me.FileLocation)
    9.     End Sub
    10. End Class

  8. #8

    Thread Starter
    New Member
    Join Date
    Jul 2014
    Posts
    8

    Re: Visual Studio 2013 Visual basic Easy program

    Thank you I will fix everything

  9. #9

    Thread Starter
    New Member
    Join Date
    Jul 2014
    Posts
    8

    Re: Visual Studio 2013 Visual basic Easy program

    Thanks

  10. #10

    Thread Starter
    New Member
    Join Date
    Jul 2014
    Posts
    8

    Re: Visual Studio 2013 Visual basic Easy program

    How should it look like now?

  11. #11
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Visual Studio 2013 Visual basic Easy program

    Quote Originally Posted by alaaemad15 View Post
    How should it look like now?
    how should what look now?

  12. #12

    Thread Starter
    New Member
    Join Date
    Jul 2014
    Posts
    8

    Re: Visual Studio 2013 Visual basic Easy program

    Quote Originally Posted by ident View Post
    how should what look now?
    How should the program look like now?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width