Results 1 to 7 of 7

Thread: add + 1 in dictionary(FSO object)

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    add + 1 in dictionary(FSO object)

    i loop a text file with the simple freefile.
    during the loop i get from each line with mid statement a part of string and assign to MyVar.
    Myvar is string dimensioned.
    In this case myVar is the name of a City
    now i need to assign on a City +1 value in a dictinary in loop...

    example for pseudo code:

    City="roma"
    Not exists, in Dictionay record, for first occurrence Roma+1
    next line from txt
    City="Roma"
    Roma alredy exist with 1 value
    Roma,1+1
    ecc...
    In effect i need to count each occurence based the City to the end of txt

    Then, now i need to loop each items in dictionary....

    sory for my bad english
    Last edited by luca90; May 19th, 2017 at 02:49 PM.

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: add + 1 in dictionary

    Dictionary allows for lookup by key so no need to loop through all entries.
    If you were going to loop then a list would work fine.

    That said I don't really see a question there so not sure what you are trying to ask.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    Re: add + 1 in dictionary

    Quote Originally Posted by DataMiser View Post
    Dictionary allows for lookup by key so no need to loop through all entries.
    If you were going to loop then a list would work fine.

    That said I don't really see a question there so not sure what you are trying to ask.
    other idea to count the occurence of City during the loop in txt file?

    Simple txt:
    ....
    Roma
    Firenze
    Firenze
    Roma
    Roma
    Firenze
    Firenze
    Roma
    Firenze
    Firenze
    Firenze
    ...
    to the end of file, i need

    Roma,4
    Firenze, 8
    ecc
    Last edited by luca90; May 19th, 2017 at 02:58 PM.

  4. #4
    Member Dragokas's Avatar
    Join Date
    Aug 2015
    Location
    Ukraine
    Posts
    740

    Re: add + 1 in dictionary(FSO object)

    Code:
    oDict.CompareMode = vbTextCompare
    
    ...
    
    If oDict.Exists(City) Then
        oDict(City) = oDict(City) + 1
    Else
        oDict.add City, 1
    End If
    Malware analyst, VirusNet developer, HiJackThis+ author || my CodeBank works

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    Re: add + 1 in dictionary(FSO object)

    Quote Originally Posted by Dragokas View Post
    Code:
    oDict.CompareMode = vbTextCompare
    
    ...
    
    If oDict.Exists(City) Then
        oDict(City) = oDict(City) + 1
    Else
        oDict.add City, 1
    End If
    WORK FINE!

    but how to loop the items in filled items of dictionary, to the and of txt?

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: add + 1 in dictionary(FSO object)

    but how to loop the items in filled items of dictionary,
    no need, that is the point to using a dictionary, just put that code snippet into your loop to read the lines of file
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7
    Member Dragokas's Avatar
    Join Date
    Aug 2015
    Location
    Ukraine
    Posts
    740

    Re: add + 1 in dictionary(FSO object)

    As far as I understand, OP is using Dictionary just for summarizing data to get final log.

    Code:
    Dim key
    
    ...
    
    for each key in oDict
        debug.? key, oDict(key)
    next
    Malware analyst, VirusNet developer, HiJackThis+ author || my CodeBank works

Posting Permissions

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



Click Here to Expand Forum to Full Width