Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Amyfb is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    64

    Inconsistent results in the Immediate window

    I'm working thru exercises in a book on access2019 programming. This bit of intro code to collections is not cooperating. I don't know enough to tell if it is correct or flawed.
    EDIT to say that the "set" statement is what seems wrong. I replaced it with Dim collection myTestCollection as New Collection and all works fine.

    grumble at the book editor.

    i'll leave this rest here in case it helps anyone else.

    I'm instructed to type this into the immediate window to begin.

    #set myTestCollection = New Collection
    #myTestCollection.Add"first member"
    #myTestCollection.Add"secondmemeber"
    #myTestCollection.Add"thirdmember"


    #?myTestCollection.Count

    first time - .Count results were 0
    i erased and reentered it all again several times, and finally, I don't know what was different but got the expected count of 3.

    Then I tried calling the one item and got the correct results.
    myTestCollection.item(1)

    then i tried the remove code
    and when i recounted to verifty , the result was 1.

    so i erased it all and typed it in again, and got 0 results on the Count.

    i erase and type again and now i get a count of 4.

    in this endless cycle of erase and retype I get inconsistent results every time.

    here's the latest - why did the count go to four after the first Remove 1 line?

    #set myTestCollection = New Collection
    #myTestCollection.Add "first"
    #myTestCollection.Add "section"
    #myTestCollection.Add "third"
    #?myTestCollection.Item(1)
    #first
    #myTestCollection.Remove 1
    #?myTestCollection.Count
    #4
    #For Each m in myTestCollection : myTestCollection.Remove 1 : Next
    #?myTestCollection.Count
    #0

    I've scrutinized code for typos, and fixed them when found. I can't find any more.

    All ideas welcome.

    thanks
    Amy

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    I've just typed in the same and this is the immediate window result
    Code:
    set myTestCollection = New Collection
    myTestCollection.Add "first"
    myTestCollection.Add "section"
    myTestCollection.Add "third"
    ? myTestCollection.Item(1)
    first
    myTestCollection.Remove 1
    ? myTestCollection.Count
     2
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,407
    After you type it in and syntax is correct, put cursor at first line and hit enter for each line to execute it. Things should work as expected.

  4. #4
    Amyfb is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    64
    Quote Originally Posted by Minty View Post
    I've just typed in the same and this is the immediate window result
    Code:
    set myTestCollection = New Collection
    myTestCollection.Add "first"
    myTestCollection.Add "section"
    myTestCollection.Add "third"
    ? myTestCollection.Item(1)
    first
    myTestCollection.Remove 1
    ? myTestCollection.Count
     2
    I don't understand why the Set command won't work for me.
    I typed the exact same thing but got goofy results.

    If you saw my edit, I had to use Dim collection As before I could get the right results.

    Is there something you can tell me about the difference or similarity between the two different approaches?

    thanks

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    What is the purpose of the # as leading character??

    This worked for me

    set myTestCollection = New Collection
    myTestCollection.Add"first member"
    myTestCollection.Add"secondmemeber"
    myTestCollection.Add"thirdmember"
    ?myTestCollection.Count
    3
    ?myTestCollection.item(1)
    first member
    myTestCollection.Remove 1
    ?mytestcollection.count
    2


    Note your For loop will remove all items in the collection - hence Count 0

    Another tutorial/article.

  6. #6
    Amyfb is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    64
    Quote Originally Posted by davegri View Post
    After you type it in and syntax is correct, put cursor at first line and hit enter for each line to execute it. Things should work as expected.
    ???
    well that's an unexpected instruction. But I tried it, typed in the code again, then did what you described, and it all works just fine.

    now how is anyone supposed to know that hitting enter at the end of a typed line isn't actually executing the line command?
    sheesh!

    did I just get lucky with the other uses of the immediate window?
    or is this one of those "depends" conditions?

    thanks for the input!

  7. #7
    Amyfb is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    64
    Quote Originally Posted by orange View Post
    What is the purpose of the # as leading character??

    ....
    Some moderator's post asks for code snips to have the hashtag. I guess i did it incorrectly.

    sorry.

  8. #8
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    Some moderator's post asks for code snips to have the hashtag. I guess i did it incorrectly.
    that was likely a reference to the toolbar button. As I type here, it is immediately above the bold red letter.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,407
    Quote Originally Posted by Amyfb View Post
    ???
    well that's an unexpected instruction. But I tried it, typed in the code again, then did what you described, and it all works just fine.

    now how is anyone supposed to know that hitting enter at the end of a typed line isn't actually executing the line command?
    sheesh!

    did I just get lucky with the other uses of the immediate window?
    or is this one of those "depends" conditions?

    thanks for the input!

    Hitting enter while on a line does execute it. For the code to work properly, each line must be executed in order, top to bottom.
    Probably in the failed attempts, your editing of the lines resulted in lines being executed out of order.

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    The hash tag they are referring to is this one
    Click image for larger version. 

Name:	hashtag.PNG 
Views:	16 
Size:	60.0 KB 
ID:	46080

  11. #11
    Amyfb is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    64
    Quote Originally Posted by orange View Post
    The hash tag they are referring to is this one
    Click image for larger version. 

Name:	hashtag.PNG 
Views:	16 
Size:	60.0 KB 
ID:	46080
    oh my, is my face red, or what!

    thanks for steering this newbie in the right direction.

  12. #12
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    now how is anyone supposed to know that hitting enter at the end of a typed line isn't actually executing the line command?
    It comes with the territory and years of experience (and mistakes/corrections....)

  13. #13
    Amyfb is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    64
    Quote Originally Posted by orange View Post
    It comes with the territory and years of experience (and mistakes/corrections....)

    let me understand - am I to go back to all my module and class codes where I have edited it and hit the enter button on the edited lines to be sure it executes?
    or is this just an immediate window thing.

  14. #14
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,407
    Quote Originally Posted by Amyfb View Post
    let me understand - am I to go back to all my module and class codes where I have edited it and hit the enter button on the edited lines to be sure it executes?
    or is this just an immediate window thing.
    No fear, it's just the immediate window requirement.

  15. #15
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Update Queries with Inconsistent Results
    By Netopia in forum Modules
    Replies: 5
    Last Post: 07-10-2018, 02:26 PM
  2. Inconsistent results with a simle query
    By slickdog in forum Queries
    Replies: 4
    Last Post: 10-07-2015, 06:01 AM
  3. Replies: 3
    Last Post: 07-30-2015, 03:59 AM
  4. Inconsistent results.. please help!
    By vikghai in forum Access
    Replies: 6
    Last Post: 02-09-2014, 05:37 PM
  5. Replies: 1
    Last Post: 09-01-2012, 06:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums