SPONSORS:






User Tag List

Page 1 of 2 12 LastLast
Results 1 to 10 of 17
  1. #1
    Junior Member
    Join Date
    Oct 2002
    Posts
    27
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to get the number of items from a file

    I am developing data driven testcases where I need to know how many items in a file so that I can use it in a for loop to enter each item on the form.

    After I read value from the file Here is the code I wrote.


    for (i=1; i <=7;i++) //I NEED TO KNOW THE TOTAL NUMBER OF ITEM FROM A FILE, Like TotalCount
    sValue = GetField(sLine, ",", i)
    frame.SetActive ()
    MainWin.SelectAccount.Pick ()
    SetAccountNumber(sValue)

    Any better solution. PLease reply. THanks

    ------------------

  2. #2
    Senior Member
    Join Date
    Oct 2001
    Location
    NC, United States
    Posts
    148
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How to get the number of items from a file

    if each line is an item you could read from file till end of file and append resulting strings to a list and count items in list.

    ------------------
    -gram
    -gram

  3. #3
    Senior Member
    Join Date
    Jul 1999
    Location
    Bellingham, WA USA
    Posts
    1,323
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How to get the number of items from a file

    You could do a:

    while FileReadLine(hFilename, sLine)

    and as long as there are more line, do:

    ListAppend(lsMyList, sLine)

    then once the list is complete do:

    iTotalCount = ListCount(lsMyList)



    ------------------

  4. #4
    Junior Member
    Join Date
    Oct 2002
    Posts
    27
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How to get the number of items from a file

    File is structured as following:
    [NUM]
    1234,5678,9111,1111,1111

    This way I can not read by Line. Please show me how to code it so that I could read each value and find out number of item in the file.

    Thanks


    ------------------

  5. #5
    Member
    Join Date
    Sep 2002
    Location
    Foster City, CA, USA
    Posts
    55
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How to get the number of items from a file

    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>

    [NUM]
    1234,5678,9111,1111,1111
    <HR></BLOCKQUOTE>

    Try this easy method, GetField(), which returns a string but you could use Val() to convert it back to an integer. Use FileReadLine as suggested above, when it gets finds [NUM], tell it to read the next line, gran the line as a text string sLine, and proceed to do the GetField() as follows:

    Val(GetField(sLine, ",", 1) //will return the value 1234
    Val(GetField(sLine, ",", 2) //will return the value 5678
    Val(GetField(sLine, ",", 3) //will return the value 9111

    Proceed until you get all the values, then you could add them together in a new variable and use that as you please.

  6. #6
    Member
    Join Date
    Sep 2002
    Location
    Foster City, CA, USA
    Posts
    55
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How to get the number of items from a file

    Also, if you really don't know the number of times, you could do a seach for the number of commas. First, get the length of the line using Len(sString) so you know how many characters there are, then you could loop through this number, for each loop verfiy the character at the position using (I think, can't remember exactly) SubStr() or StrPos(), if it's a comma, increment a variable counter. After the loop ends, then you have your the total number of commas, which tells you how many numbers you have (# of commas + 1. And then you can loop thru in my above reply to add up all the values.

  7. #7
    Senior Member
    Join Date
    Oct 2001
    Location
    NC, United States
    Posts
    148
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How to get the number of items from a file

    .....i'll let you handle the coding....suggestions as to the logic is....

    1. read each line from file - it is stored in a string
    2. strings can be treated as arrays - there is another thread on this - go thru each char until comma, collect chars to form string and append string to a list, continue till end of line
    3. list count the list created thus
    ....do until end of file and get the total count

    ------------------
    -gram
    -gram

  8. #8
    Junior Member
    Join Date
    Oct 2002
    Posts
    27
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How to get the number of items from a file

    KCHAN, I was trying to code the way you suggested but seems like in a for loop it only finds the first comma if I use StrPos () method.

    Here is the code:Please let me know what I am doing wrong


    string sReport,sSubStr
    integer sStrPos
    integer iLength=Len(sReport)
    for (i =1; i&lt;=iLength; i++)
    sStrPos=StrPos(",",sReport)
    sSubStr=SubStr(sReport,sStrPos)
    print(sStrPos) //It just prints 5
    print(sSubStr) //it prints ,5678,9111,1111,1111
    print(sReport) //It prints 1234,5678,9111,1111,1111

    How can I make it to print 5,10,15,20 (repeatedly)because the file contains 4 commas at position 5 and 10,15,20 and file contains the following
    [NUM]
    1234,5678,9111,1111,1111



    ------------------

  9. #9
    Senior Member
    Join Date
    Jul 1999
    Location
    Bellingham, WA USA
    Posts
    1,323
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How to get the number of items from a file

    Well, I guess since you are looking for a count, you could do something like this:

    So, if your comma count is 5, you know you have six items. To get the actual value of the items you will want to use the GetField() method mentioned above.

    ------------------

  10. #10
    Senior Member
    Join Date
    Jun 2000
    Location
    Sunyyvale CA USA
    Posts
    422
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How to get the number of items from a file

    another way to do this, look for first comma "," and increase the count and delete the portion from the original string and search for another comma and increase the count till you find commas then you can use getfield to read as now u know how many fields are available.

    You can use Stuff to replace with none and StrPos and Len functions to delete the string after you gor comma char. Hope this helps.

    ------------------
    Sree
    Sree

 

 
Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin 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 09:17 AM.

Copyright BetaSoft Inc.