Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Reading from a text file

  • 29-11-2004 08:11PM
    #1
    Registered Users, Registered Users 2 Posts: 3,946 ✭✭✭


    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, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    [wiki]GTFW[/wiki]


  • Registered Users, Registered Users 2 Posts: 3,946 ✭✭✭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: 96,197 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, Registered Users 2 Posts: 3,946 ✭✭✭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, Registered Users 2 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: 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