Results 1 to 9 of 9

Thread: Self-Taught programmer in need of some basic help...

  1. #1

    Thread Starter
    Member cameronlanni's Avatar
    Join Date
    Jul 2007
    Posts
    49

    Self-Taught programmer in need of some basic help...

    I'll start out by saying that I'm fairly comfortable programming in VB (2005) but, since I'm self-taught, I don't know the proper terminology for most things, so I apologize in advance if this is hard to understand.

    Should be an easy question today: I have a fairly simple application and I now need to store some data to a .txt document. From what I read, it should be easy, but I can't seem to get it working right now.

    If the file path of the text document was: C:\Program Files\Poop.txt, how could I write the value of a variable (let's say the variable is called "intAge") to this text document? The simplest way would be awesome.

    Thank you in advance,
    Cameron

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Self-Taught programmer in need of some basic help...

    Thread moved from the 'VB6 and Earlier' forum to the 'VB.Net' (VB2002 and later) forum


    This way is rather simple:
    Code:
    My.Computer.FileSystem.WriteAllText("C:\Program Files\Poop.txt", intAge.ToString, False, System.Text.Encoding.Default)

  3. #3
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: Self-Taught programmer in need of some basic help...

    Quote Originally Posted by cameronlanni View Post
    I'll start out by saying that I'm fairly comfortable programming in VB (2005) but, since I'm self-taught, I don't know the proper terminology for most things, so I apologize in advance if this is hard to understand.

    Should be an easy question today: I have a fairly simple application and I now need to store some data to a .txt document. From what I read, it should be easy, but I can't seem to get it working right now.

    If the file path of the text document was: C:\Program Files\Poop.txt, how could I write the value of a variable (let's say the variable is called "intAge") to this text document? The simplest way would be awesome.

    Thank you in advance,
    Cameron
    Code:
    Imports System.IO
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim writer As StreamWriter = New StreamWriter("C:\VBForums.txt", True)
            writer.WriteLine("VBForums")
            writer.Close()
    
        End Sub
    End Class

  4. #4

    Thread Starter
    Member cameronlanni's Avatar
    Join Date
    Jul 2007
    Posts
    49

    Re: Self-Taught programmer in need of some basic help...

    Awesome. Thank you guys so much.
    31337 joke of the day

    Q: Why do they call HTML Hyper Text?

    A: Too much Java!

  5. #5

    Thread Starter
    Member cameronlanni's Avatar
    Join Date
    Jul 2007
    Posts
    49

    Question New Question...

    Instead of making a new post, I think I'll bump this one since this is all part of one larger question...

    How would I then go back into that text document, check to see what word (or number) is on line...let's say Line 25? How could I store the contents of Line 25 to a variable or how could I reference the contents of Line 25 for something like an If/Then Statement or to change the text in a Text Box to the contents of Line 25?


    Thanks again for all of your continuous help,
    Cameron

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

    Re: Self-Taught programmer in need of some basic help...

    vb Code:
    1. ' If you wanted to get all the lines into an Array
    2. ' Dim lines() As String = IO.File.ReadAllLines("C:\MyFile.txt")
    3. ' To view line 25 you would reference index 24 (we start from 0)
    4. ' MessageBox.Show(Lines(24))
    5.  
    6. ' Here we create a variable by reading all lines into an array
    7. ' and referencing index 24. Line 25
    8. Dim line As String = IO.File.ReadAllLines("C:\MyFile.txt")(24)
    9. Me.txtMyTextBox.Text = line

  7. #7

    Thread Starter
    Member cameronlanni's Avatar
    Join Date
    Jul 2007
    Posts
    49

    Re: Self-Taught programmer in need of some basic help...

    Great.

    So I could then do something like this?:

    Code:
    Dim line As String = IO.File.ReadAllLines("C:\MyFile.txt")(24)
    
    If line = "UR A WINRAR" Then
    
    'Carry Out Main Command
    
    Else 
    
    'Carry Out Secondary Command
    
    End If
    31337 joke of the day

    Q: Why do they call HTML Hyper Text?

    A: Too much Java!

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

    Re: Self-Taught programmer in need of some basic help...

    You need to try it to see But yes it will.

  9. #9

    Thread Starter
    Member cameronlanni's Avatar
    Join Date
    Jul 2007
    Posts
    49

    Re: Self-Taught programmer in need of some basic help...

    Thanks guys. I think I'm in business...!

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