Results 1 to 2 of 2

Thread: Assign each line of a text file to a variable

  1. #1
    Join Date
    Jan 2011
    Posts
    1

    Assign each line of a text file to a variable

    Hi,

    I have what should hopefully be a very simple scenario.

    I have a batch file which relies on a text file to retrieve a set of values, line by line. Each line represents a server name. To illustrate, let's say the servers are listed as follows:

    WebServer 1
    AppServer 2
    DatabaseServer 3

    For each server name listed in the text file, the batch script should assign it to a unique variable and then perform some other process (e.g. deploy some files), as required for that particular server.

    I believe the For Loop will be best suited for this particular requirement and would be extremely grateful if anyone could assist.

    Thank you.

  2. #2
    Join Date
    Dec 2007
    Posts
    2,291

    Re: Assign each line of a text file to a variable

    Below is an example code that you can try:

    Dim linetext as string = objReader.ReadLine
    Dim aryTextFile() as string = linetext.Split(" ")
    Dim tend as Double = Val(aryTextFile(0))
    MsgBox(tend.ToString)

    That will put the first part of the first line into the variable tend. To get the remaining variables, read the next line (another .Readline), split it, and put the results into the next variable.

    linetext = objReader.ReadLine
    aryTextFile = linetext.Split(" ")
    Dim texp as Double = Val(aryTextFile(0))
    MsgBox(texp.ToString)

Similar Threads

  1. HELP - add new line in text file without format changed
    By newbie1818 in forum Software Development
    Replies: 2
    Last Post: 13-09-2011, 05:17 PM
  2. Assign a text file from hard disk into a VBA string variable
    By AbiCgail in forum Software Development
    Replies: 5
    Last Post: 15-07-2011, 10:49 AM
  3. How to move to next line by PHP in text file?
    By Ramona19 in forum Software Development
    Replies: 4
    Last Post: 09-06-2011, 07:09 AM
  4. How to let Java read text file line by line.
    By Visala28 in forum Software Development
    Replies: 3
    Last Post: 04-08-2009, 11:30 PM
  5. Replies: 1
    Last Post: 10-12-2008, 12:36 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,923,475.07895 seconds with 16 queries