Blind cat hits dead mouse 2: even a computer cannot bend around too much

Source: Internet
Author: User

Technorati label:VBA,Variable Declaration

 

Today, I made another call.

I declare an annatree dynamic array. The annatree class has a member variable of the Treeview class. I want to add a node under a tree in this dynamic array and assign a value to the tag of this node.

  1. Dim objohtersameatree () as annatree
  2. Set objohternode = objohtersameatree (I). Tree. nodes. Add (relative: = m_tree.selecteditem.key, relationship: = tvwchild, text: = objnewnode. text, image: = 2)
  3. Objothernode. Tag = ""

As shown in the preceding figure, when F8 is reached the last line, an error is reported, "the object or with block variable is not set ". In fact, the monitoring window shows that objothernode is normal, and its tag can also be seen. However, once objothernode. Tag is directly monitored, "the object or with block variable is not set ". Later I changed it to this, but it was right:

  1. Dim objohtersameatree () as annatree
  2. Dim treothersame as mscomctllib. Treeview
  3. Set treothersame = objohtersameatree (I). Tree
  4. Set objothernode = treothersame. nodes. Add (relative: = m_tree.selecteditem.key, relationship: = tvwchild, text: = objnewnode. text, image: = 2)
  5. Objothernode. Tag = ""

Just put the tree in the array out, and then click it. I was thinking, it is estimated that VB also has its own bug. This kind of logic-compliant but not-conforming super usage like me, it is estimated that their testers could not think of testing, so, I had to swallow this bitter fruit myself ...... Similarly, I also met one time. See the following:

  1. Strparentkey = m_tree.nodes.item (objnode. Key). Parent. Key

When this line is run, the object or with block variable is not assigned a value.

  1. Set objrelatednode = m_tree.nodes.item (objnode. Key)
  2. Strparentkey = objrelatednode. Parent. Key

It is passed. It may be that a reference that is too long has caused compilation ambiguity.

 

Summary:A reference that is too long can be turned around with an intermediate variable. Otherwise, VBA may not be able to understand it ......

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.