Results 1 to 6 of 6

Thread: Text Files [ Resolved ]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Location
    Canton, GA
    Posts
    487

    Text Files [ Resolved ]

    I am new so no yelling please

    ok here is what I want... please help

    I want to have a text file that reads:

    Background = Red
    Text = Blue
    Size = 5


    now how do I access it from my application and get the "values"
    by opening the file and reading line by line?

    and lets say later I may want to change setting to something else?? like change the size option to 10?? how do i read the file get the value and then change it??

    Please help

    Thanks,

    Anjari
    Last edited by Anjari; Dec 20th, 2002 at 05:22 AM.

  2. #2
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    the easy way is get some class that reads ini for u and do something like that with INI's...otherwise u'd must have to create ur own engine -_-;;;

    u can use xml too, but the sintax will be a kind diferent
    \m/\m/

  3. #3
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    to read a file:
    VB Code:
    1. ' at the top of the code
    2. imports system.io
    3.  
    4.  
    5. ' in a sub or function
    6. Dim sr As StreamReader = File.OpenText("filepath")
    7. Dim aLine As string
    8. aLine = sr.ReadLine()
    9.  
    10.  
    11. ' make sure you close the file! :)
    12. sr.Close()
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Location
    Canton, GA
    Posts
    487

    hmmmm

    Mr. Polite could you go into detail for a newbie?

    how do i pull each value?

    Thanks,

    Anjari

  5. #5
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: hmmmm

    Originally posted by Anjari
    Mr. Polite could you go into detail for a newbie?

    how do i pull each value?

    Thanks,

    Anjari
    well that;s just for reading the lines from the file here's how to read all the lines, one by one...
    btw this is my way of reading the values from the lines, you can come up with any way you want

    VB Code:
    1. ' open the file .... you should add an error handler
    2.         Dim sr As StreamReader = File.OpenText("c:\test.txt")
    3.         Dim aLine, value As String
    4.         Dim delimPos As Integer ' Holds the position of the delimiter ("=") in the line
    5.  
    6.  
    7.         ' Read until the end of the file
    8.         Do While sr.Peek() <> -1
    9.             ' Read a line from the file
    10.             aLine = sr.ReadLine()
    11.             delimPos = aLine.IndexOf("=")
    12.  
    13.  
    14.             If delimPos = -1 Then
    15.                 ' Error, no delimiter found!
    16.                 ' throw an error ...
    17.             Else
    18.                 ' Get the value from the line
    19.                 value = aLine.Substring(delimPos + 1)
    20.                 ' Remove extra spaces
    21.                 value = value.Trim()
    22.             End If
    23.  
    24.  
    25.             ' Do whatever you want with the value right here
    26.         Loop
    27.  
    28.         ' Close the file
    29.         sr.Close()

    hope this helps
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Location
    Canton, GA
    Posts
    487

    Works Great

    Thanks again...

    Anjari

    *** Don't Shoot the newbie! ***

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