Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Reading from a text file

Options
  • 29-11-2004 9:11pm
    #1
    Registered Users Posts: 3,969 ✭✭✭


    How can I tell VB to read characters from a text file? The characters are separated by a comma, and are varible in length. Like:

    1223A,AD43B,D45C,D43,DAC54,ADCBA4

    how can I get one of these values at a time, so I can read the first set of characters, use them, then go onto the next set?


Comments

  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    [wiki]GTFW[/wiki]


  • Registered Users Posts: 3,969 ✭✭✭mp3guy


    obviously if i'm posting on a forum i've already googled it


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 91,687 Mod ✭✭✭✭Capt'n Midnight


    in B it's

    do
    input #1,A$
    loop until EOF(1)

    hint A$ = " a string"


  • Closed Accounts Posts: 7,230 ✭✭✭scojones


    The answer to this is simple. My solution is in c#, so you can port it easily (i don't code vb that much) Do it like so:
    char c = ',';
    string sentence;
    string[] s;
    sentence = "1223A,AD43B,D45C,D43,DAC54,ADCBA4";
    s = sentence.Split(c);
    

    s will be populated with 1223A being in s[0], AD43B being in s[1] and so on.


  • Registered Users Posts: 3,969 ✭✭✭mp3guy


    thanks, i got it to work, with:
    dim mystring as string
    Do Until EOF(1)
    input #1, mystring$
    loop
    


  • Advertisement
  • Closed Accounts Posts: 92 ✭✭tempest


    mp3guy wrote:
    obviously if i'm posting on a forum i've already googled it

    Unfortunately it's not obvious that you have already googled it.

    If you come looking for help from people you should be a little more respectful. If someone says GTFW and they frequently answer questions then it's likely that they have good reason. It's also more than likely how you asked the question rather than what you asked.

    You should read the charter and in particular read:
    HOW TO ASK A QUESTION

    BTW look up the Scripting.FileSystemObject and Scripting.TextStream object for reading in a marginally more object oriented manner.


  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    mp3guy wrote:
    obviously if i'm posting on a forum i've already googled it

    First check on google

    http://www.builderau.com.au/program/windows/0,39024644,20267367,00.htm

    http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20941478.html

    Or you could of searched this forum as I am sure the same question has been asked more then once.

    Failing that the VB help screens should of been able to tell you (unless they removed sample code from it now?)


  • Closed Accounts Posts: 1,061 ✭✭✭dawballz


    Hobbes wrote:
    [wiki]GTFW[/wiki]

    and also in that link ( http://www.boards.ie/wiki/index.php/GTFW ):
    "....use Google (http://www.google.com) or another search engine to find the answer to such an obvious question rather then wasting people's time posting for the answer."

    People aren't forced to answer anything. If they don't want to reply they don't have to. Also if they feel they would be wasting their time posting, again, they don't have to post.
    Maybe he came accross this forum through a search of google for his question, so essentially he did search google for an answer.

    GTFW/STFW is ridiculous.


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    dawballz wrote:
    People aren't forced to answer anything. If they don't want to reply they don't have to. Also if they feel they would be wasting their time posting, again, they don't have to post.
    I wasted eight seconds of my time clicking the thread and reading it. I’m not getting those eight seconds back. If no one slaps him down two things will happen; he’ll never learn to STFW before posting and he’ll continue posting STFW/RTFM type questions on this and other boards.

    Now imagine, as often happens when we get a new crop of noobs starting CS courses every autumn, that he’s not the only one who asks such questions. Within a short while, half of the threads would end up a similar waste of our time. I’ve seen entire mailing lists and bulletin boards abandoned because no one was willing to police the signal to noise ratio.

    In short, flaming teaches people to look before they leap.


Advertisement