Read file line by line and...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jonas

    Read file line by line and...


    I want the user to be able to write like http://www.google.com in one
    textBox and Google in an other textBox.

    Than I want the user to press a button when done. The text will then be past
    like http://www.google.com,Google in to a file.

    I want the user to be able to send as many links with names as they want to
    that file. Then I want my program to be able to read from that file as I
    start the program from a button at my form and use it in the program.

    I am using MS Agent and I want the user to be able to write down links like
    i described and then when I start the agent I want the agent to "build"
    this:

    All the names the user wrote:

    Merlin.Commands .RemoveAll
    Merlin.Commands .Add "Google", "Google", "Google"
    Merlin.Commands .Add "Lunarstorm ", "Lunarstorm ", "Lunarstorm "
    Merlin.Commands .Add "Back", "Back", "Back"
    Merlin.Commands .Add "Forward", "Forward", "Forward"
    Merlin.Commands .Add "Close", "Close", "Close"

    The Names and the URL the user wrote down:

    Select Case UserInput.Name
    Case "Google"
    URL= "http://www.google.se"
    objInternet.Nav igate Adress
    Case "Lunarstorm "
    URL= "http://www.lunarstorm. se"
    objInternet.Nav igate Adress

    Case "Back"
    objInternet.Bac k
    Case "Forward"
    objInternet.For ward

    Case "Close"
    objInternet.Qui t
    End Select

    I want to do something like this:

    Read the file line by line split the line at the "," and pot the left and
    right string in an array and then go to the next line and add that to the
    array as well and so on.

    Then I want to use it in the MS Agent as this, to be able to use the links:
    (As the Link names is the odd numbers I will just write out the odd
    numbers.)

    for (i=1, i<= aryLength(aryLi nk[i]), i=+2)
    {
    Merlin.Commands .Add "aryLinks[i]", "aryLinks[i]", "aryLinks[i]"
    }

    Merlin.Commands .Add "Back", "Back", "Back"
    Merlin.Commands .Add "Forward", "Forward", "Forward"
    Merlin.Commands .Add "Close", "Close", "Close"


    Then here it is a little harder, the Case Is the odd numbers in the Array
    and the URL is the even numbers.

    Select Case UserInput.Name

    Case "Google"
    URL= "http://www.google.se"
    objInternet.Nav igate URL
    Case "Lunarstorm "
    URL= "http://www.lunarstorm. se"
    objInternet.Nav igate URL

    These are not taken from the file:
    Case "Back"
    objInternet.Bac k
    Case "Forward"
    objInternet.For ward
    Case "Close"
    objInternet.Qui t
    End Select

    As you can see is this not a language that exist... I don't know how to do
    it in VB 6 It is not the same as using PHP with mySQL...

    I'm a newbe to VB and some other languages as well...So it's all a bit
    confusing...

    Plz show me in the right direction to get this to work :-)


  • BadOmen

    #2
    Re: Read file line by line and...

    This is what I have done...
    But I don't know how to use the Arrays that I need, so if anyone know this
    you are very welcome to show me :)

    I am reading from a text file containing this:


    http://www.google.com,Google
    http://www.lunarstorm.se,Lunarstorm
    http://www.microsoft.com,Microsoft

    With this function:


    Option Explicit

    Public URLAddress As String
    Public NameAddress As String

    Public Static Function ReadFile()

    Const ForReading = 1, ForWriting = 2
    Dim fso, f
    Dim LineHolder As String
    Set fso = CreateObject("S cripting.FileSy stemObject")
    Set f = fso.OpenTextFil e("c:\testfile. txt", ForReading)
    LineHolder = f.ReadLine

    Dim MyString, MyArray
    MyString = Split(LineHolde r, ",", -1, 1)

    ' *** MyString(0) contains "http://www.google.com" .
    ' *** MyString(1) contains "Google".
    ' *** MyString(2) contains " http://www.google.com" .
    ' *** MyString(3) contains "Lunarstorm ".
    ' *** (all odd numbers are URL's and all the even numbers are the Names)


    URLAddress = MyString(0) '***** This Must Contain all even numbers,
    0,2,4...
    NameAddress = MyString(1) '***** This Must Contain all odd numbers,
    1,3,5,...


    End Function


    '******I want to produce this:

    Case "Google"
    Address = "http://www.Google.com"
    objInternet.Nav igate Address



    Case "Lunarstorm "
    Address = "http://www.lunarstorm. se"
    objInternet.Nav igate Address

    Case "Microsoft"
    Address = "http://www.Microsoft.c om"
    objInternet.Nav igate Address


    '***** By looping the URLAddress and NameAddress

    Case NameAddress
    Address =URLAddress
    objInternet.Nav igate Address

    Yours, Jonas


    Comment

    Working...