Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion Bug in 'With...End With'
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Tony Proctor  
View profile  
 More options May 16 2003, 11:04 am
Newsgroups: microsoft.public.vb.bugs
From: "Tony Proctor" <tony_proctor@aimtechnology_NOSPAM.com>
Date: Fri, 16 May 2003 11:03:40 +0100
Local: Fri, May 16 2003 11:03 am
Subject: Bug in 'With...End With'
I've been trying to track down a problem in my code, and it looks like a VB
bug in the 'With' block. I was wondering if anyone had seen anything like
this before. Basically, assignments inside a particular 'With' block do
absolutely nothing: no values modified anywhere and certainly no error
messages. More details comments are in my sample code below.

For reasons too involved to explain, my UDT array (vDetails) is referenced
via a variant. The problem seems to be related to the use of the vDetails
variant because if the code used the UDT array (tDetails) directly (which I
can't do in the real situation) then it works.

If anyone feels like trying to compile this dummy example, the Types have to
be in a public class. An easy way to do this is to put the *.bas and the
*.cls in the same ActiveX EXE project, set the 'Startup object' to 'Sub
Main', and just run the resulting EXE as per normal.

                    Tony

Private tDetails() As Details
Private vDetails As Variant

Sub Main()
Dim iEntry As Integer, iMsg As Integer
    ' Set up some dummy data
    ReDim tDetails(5)
    ReDim tDetails(1).tMsgStore(5)
    vDetails = tDetails
    iEntry = 1
    iMsg = 1

    ' This doesn't actually modify vDetails(1).tMsgStore(1).bNew, and it
    ' doesn't complain either
    With vDetails(iEntry).tMsgStore(iMsg)
        .bNew = True
    End With

    MsgBox vDetails(iEntry).tMsgStore(iMsg).bNew    'Reports 'False'

    ' This correctly modifies vDetails(1).tMsgStore(1).bNew
    With vDetails(iEntry)
        .tMsgStore(iMsg).bNew = True
    End With

    MsgBox vDetails(iEntry).tMsgStore(iMsg).bNew    'Reports 'True' now

    ' This now goes back to the original construct, but in "read mode"
rather than "assign mode"
    With vDetails(iEntry).tMsgStore(iMsg)
        MsgBox .bNew                                                'Now
reports 'True'
    End With
End Sub

where the Types might be defined in a *public* class as follows:

Public Type MsgDetails
    bNew As Boolean
End Type

Public Type Details
    sName As String
    tMsgStore() As MsgDetails
End Type


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google