[URGENT] How to make c# application react to .txt files menu

User Tag List

Results 1 to 5 of 5
  1. #1
    petergm's Avatar Member
    Reputation
    2
    Join Date
    Apr 2011
    Posts
    34
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [URGENT] How to make c# application react to .txt files

    Hello there!

    I just started coding a VERY simple World of Warcraft bot. I want the bot to react to a text file or xml file.

    That means that it should probably be something like this:

    the textfile:
    press 1,4,3
    goto x,y

    And then the bot react to the text file. I can not figure out how to do it.
    By basic idea would be:
    1. make a test .txt file (f.e press 1)
    2. make a class that opens and read the txt file.
    3. make a start button that when clicked calls the class.

    However I do not know how to do any of theese steps probably.

    I am new so I want it to be as SIMPLE as possible. Can anybody help me out? (It has to be in C#)

    [URGENT] How to make c# application react to .txt files
  2. #2
    Sychotix's Avatar Moderator Authenticator enabled
    Reputation
    1421
    Join Date
    Apr 2006
    Posts
    3,943
    Thanks G/R
    285/572
    Trade Feedback
    1 (100%)
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Open the file and parse it. Simple.

  3. #3
    petergm's Avatar Member
    Reputation
    2
    Join Date
    Apr 2011
    Posts
    34
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The thing is that I need the application to read the file. So I can easily just change the file if I want it to do something else.

    ---------- Post added at 06:02 PM ---------- Previous post was at 05:53 PM ----------

    I want it to read different "profiles"

  4. #4
    Sychotix's Avatar Moderator Authenticator enabled
    Reputation
    1421
    Join Date
    Apr 2006
    Posts
    3,943
    Thanks G/R
    285/572
    Trade Feedback
    1 (100%)
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Yes, like I said. Open the file and parse it. Google if you don't know how to do that... its extremely simple.

  5. #5
    hp94's Avatar Legendary
    Reputation
    742
    Join Date
    Nov 2009
    Posts
    587
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
           public static void WriteToFile(string stringToWrite)
            {
    
                TextWriter tw = new StreamWriter("FileName", true); //save AND append, don't rewrite it each stream write - false rewrites
    
                tw.WriteLine("[" + DateTime.Now + "]: " + stringToWrite);
    
    
                tw.Close();
             }
    
            public static string ReadFromFile(string fileName)
            {
                StreamReader reader = new StreamReader(fileName);
    
                string file = reader.ReadToEnd();
    
                reader.Close();
    
                return file;
            }
    Here's a snippet from one of my projects.

    For parsing inside a text file, you probably want to use try-catch-finally and always close the file (just as good practise). You should use Substring to cut away at your strings (since the streamreader goes line by line it's very easy just to use IndexOf in whatever format you want (such as Press|x|y|z or p|x|y|z or whatever). If you want something advanced (or just to learn), look into regular expressions.

Similar Threads

  1. How to make a nice application!
    By [RagDoll] in forum World of Warcraft Guides
    Replies: 25
    Last Post: 03-05-2009, 02:17 PM
  2. How to succesfully make an application to a guild!
    By acke in forum World of Warcraft Guides
    Replies: 30
    Last Post: 01-23-2009, 08:45 PM
  3. How to make any trial application last forever
    By Haitamo in forum World of Warcraft Guides
    Replies: 22
    Last Post: 05-14-2008, 04:05 PM
  4. How to Make a Character with Cool Letters
    By Cyboi in forum World of Warcraft Guides
    Replies: 62
    Last Post: 08-21-2007, 01:52 PM
All times are GMT -5. The time now is 01:01 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search