SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 5 of 5
  1. #1
    Member
    Join Date
    Aug 2008
    Posts
    97
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    setting array values from notpad

    This is more of a question on VB function, i assume:

    C:\accountno.txt contains the following values (1 account number per line)
    ---------------------------------

    100111
    110101
    120001
    122201
    122211
    100001
    ---------------------------------

    QTP needs to get the data from the file and assign it to a dynamic array such that:

    accountno(0) = 100111
    accountno(1) = 110101
    .
    .
    .
    accountno(5) = 100001


    Im not sure how QTP or VBScript can understan line breaks from notepad. Any thoughts?

  2. #2
    Moderator
    Join Date
    Jan 2007
    Location
    Pittsburgh, PA
    Posts
    2,497
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: setting array values from notpad

    Search online help for keywords "readall" and "split".

    Readall method is for reading the file content.

    Split function is for splitting data with a delimeter, here in this case the delimeter should be new vb line character(vbnewline).

  3. #3
    Advanced Member
    Join Date
    May 2007
    Posts
    609
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    2 Thread(s)
    Total Downloaded
    0

    Re: setting array values from notpad

    Just in case you're feeling lazy...

    <font class="small">Code:</font><hr /><pre>



    '************************************************* ************************************************** ************************************************** *************************
    '***
    '*** Function Name: GetListFromFile
    '*** Description: open a text file and read the contents into an array. each line of the file is one element in the array.
    '*** Author: Dennis Belew
    '*** Date Written: 06/17/2010
    '*** Inputs: inputFile -- the complete filepath and filename of the file to read
    '*** Outputs: N/A
    '*** Return Codes: N/A
    '***
    '************************************************* ************************************************** ************************************************** *************************
    public function GetListFromFile(inputFile)
    Dim returnArray()
    Set fso = createobject("Scripting.FileSystemObject")
    set inFile = fso.OpenTextFile(inputfile)
    x = 0
    While not inFile.AtEndOfStream
    ReDim Preserve returnArray(x)
    returnArray(x) = inFile.ReadLine
    x = x + 1
    Wend
    inFile.Close
    Set inFile = nothing
    Set fso = nothing

    GetListFromFile = returnArray
    end function
    </pre><hr />
    Dennis Belew

  4. #4
    Member
    Join Date
    Aug 2008
    Posts
    97
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: setting array values from notpad

    I actually found one:


    '-------------------------------------
    Option Explicit

    Dim objFSO, strTextFile, strData, strLine, arrLines
    CONST ForReading = 1

    'name of the text file
    strTextFile = "textfile.conf"

    'Create a File System Object
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    'Open the text file - strData now contains the whole file
    strData = objFSO.OpenTextFile(strTextFile,ForReading).ReadAl l

    'Split the text file into lines
    arrLines = Split(strData,vbCrLf)

    'Cleanup
    Set objFSO = Nothing

    '-----------------------------------------------


    I am familiar with almost everything on this code except for "vbCrLf" [img]/images/graemlins/smile.gif[/img]

  5. #5
    Advanced Member
    Join Date
    May 2007
    Posts
    609
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    2 Thread(s)
    Total Downloaded
    0

    Re: setting array values from notpad

    That's a built-in vbscript constant that is equal to a carriage return and line feed character... in other words, a new line. So, it's splitting the file everywhere it finds a new line.
    Dennis Belew

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 10.71%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 04:00 AM.

Copyright BetaSoft Inc.