Results 1 to 18 of 18

Thread: True = False?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2013
    Posts
    25

    True = False?

    I am simply trying to set the .Visible property of a textbox on a form. Can someone please explain the bizarre behavior below? (I set it to True then print it where it prints False.)

    Code:
                With f.txtML(c)
                    .Text = rs.Fields(c).defaultValue
                    .Left = 2040
                    .Top = (c * 300) + 120
                    .Visible = True
                    MsgBox .Visible
                End With


    What I find more bizarre is that the textbox is visible on the form but I need to fill it based on its .Visible property which is apparently False regardless of what I set it to (or whether it is actually or not).
    Attached Images Attached Images  

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: True = False?

    It would really help if you could attach a test project that exhibits that weird behavior. You might even discover the cause in the process of doing so.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

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

    Re: True = False?

    Are you sure that the textbox is visible on the form at the time the code is executed? For example during form load it would not be visible even though the property is set to visible and you would be able to see it once the form completes loading

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Oct 2013
    Posts
    25

    Re: True = False?

    Quote Originally Posted by Bonnie West View Post
    It would really help if you could attach a test project that exhibits that weird behavior. You might even discover the cause in the process of doing so.
    It's a small part of a project which displays info form an access db on a series of forms. Because there is no way to set the multiline prop of a textbox at runtime, the form is populated at runtime with identical sets of textboxes, one single/one multiline. When the field is Memo, the multiline textbox is made visible and the single is hidden. When the record s read, the .visible property is supposed to determine which textbox the value goes into. The project is not small or simple and I am not a liberty to share the db. If I absolutely had o, I guess I could "dummy up" a db and pull out the relevant code. But I don' see how it an explain how I can set something to True and immediately print it and have the value be False.

  5. #5
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: True = False?

    Start a new project and, then, to the form, add a textbox, leaving it's visible property set to true

    Paste this into the form's code and run the project:

    Code:
    Option Explicit
    
    Private Sub Form_Load()
       Debug.Print Text1.Visible
    End Sub
    This is what people are trying to tell you above...
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Oct 2013
    Posts
    25

    Re: True = False?

    Quote Originally Posted by DataMiser View Post
    Are you sure that the textbox is visible on the form at the time the code is executed? For example during form load it would not be visible even though the property is set to visible and you would be able to see it once the form completes loading
    If you read my response to Bonnie West, you get an idea of the project. The loop that creates the form reads the field properties in the desired table and places identical single and multiline textboxes throughout the form (all defaulted to visible=False). If the fieldtype is Memo (and the ridiculous hyperlink attribute is false), the multiline is made visible, otherwise the single is. As the db is read, the fieldtype determines whether the value goes in the single or multi. Then f.Show presents a form with the correct textboxes as multiline (with scrollbars) but the values of those are empty because using "if multi.visible put value there, otherwise put it in single" logic fails because of this bizarre behavior exhibited in the code snippet. I have kludges available (putting all values in both boxes and having to do the stupid more-complicated fieldtype logic when going to the db [because the geniuses at MS decided a hyperlink field shouldn't have its own type but should be a memo with a special attribute]). In addition to requiring a ridiculous amount of extra typing (which is hard for me because I have very limited of my hands [typing these 2 responses is exceeding an hour]), it just makes no sense and I want reliable logic in my code.

  7. #7
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: True = False?

    Why not Dim a Boolean variable that is set to True when the fieldtype is Memo and False otherwise? That way, you won't have to rely on the TextBox's Visible property.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Oct 2013
    Posts
    25

    Re: True = False?

    Quote Originally Posted by ColinE66 View Post
    Start a new project and, then, to the form, add a textbox, leaving it's visible property set to true
    .
    .
    .
    This is what people are trying to tell you above...
    If you read my reply to Bonnie West, you will see that I need to control this property a runtime. I don't see how your logic can explain why I can set it to True and have it immediately print false anymore than if I assigned x=-1 and debug.print x printed 0 (the exact underlying process).

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Oct 2013
    Posts
    25

    Re: True = False?

    Quote Originally Posted by Bonnie West View Post
    Why not Dim a Boolean variable that is set to True when the fieldtype is Memo and False otherwise? That way, you won't have to rely on the TextBox's Visible property.
    I appreciate the suggestion but it's just another possible kludge and does not explain the behavior.

  10. #10
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: True = False?

    Shirley you can knock up a small project that mimics your problem, and attach it for us to investigate ?

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Oct 2013
    Posts
    25

    Re: True = False?

    Quote Originally Posted by Bobbles View Post
    Shirley you can knock up a small project that mimics your problem, and attach it for us to investigate ?
    Don't call me Shirley. ;-) As stated, typing isn't easy for me. I need this working now so it's kludge time. On the off chance I ever am able to whip up a test project and post it, I will leave the question open. Maybe someone will stumble by with a "simple" answer in the mean time. For now, thanks all and good night.

  12. #12
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: True = False?

    The attachment attempts to reproduce what I suspect you have going on.

    Basically your mistake is in thinking of the properties of controls as simple variables. Many of them are not, and setting them a value causes one or more messages to be sent to change some aspect of the control's state to change. By the same token querying them sends messages to retrieve state information.

    If the control or its container is not in a position to accept and process these messages the control wrapper (what you think of as a control in VB) can only return the last known value for the state attribute queried.

    When a Form is loaded but hidden its child controls can't process messages, so depending on the message they either get queued for later processing or discarded.

    If you want to track this without showing the Form first I suggest you use another place to store your state like a Boolean array, or alternatively perhaps an Extender property such as the Tag.


    As far as your rant about the funky Access pseudo-type "Hyperlink" goes there are a number of them. Keep in mind that Access is just a parasite on the Jet database engine (or the newer "private label" version called the ACE engine). Jet (and I'm pretty sure ACE as well) implements no such data type as Hyperlink.

    Access phonies this up by using a field of Jet's Memo type with an extended property set on it. This property seems to have the key "Jet OLEDB:Hyperlink" and is normally set = True. Then Access just slams a string in there using a funky format on the order of:

    displaytext#webaddress#sub-address#screen tip

    This is not a type implemented by any DBMS I know of (though I would not be surprised if VFP has something similar). So the fact that it isn't in Jet as an actual data type is no surprise at all.

    Remember, Microsoft's Office Team lives in a Bizarro World of its own where cars have two wheels in the front and one in the rear and are steered using a tiller instead of a steering wheel, instead of wires in the walls to carry power their homes have hydraulic tubing, and people still regularly travel by dirigible and side-wheel steamboats. This explains how weird crap like the Ribbon in Office 2007 and beyond "makes sense."
    Attached Files Attached Files

  13. #13
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: True = False?

    Quote Originally Posted by jmkvbf View Post
    If you read my reply to Bonnie West, you will see that I need to control this property a runtime. I don't see how your logic can explain why I can set it to True and have it immediately print false anymore than if I assigned x=-1 and debug.print x printed 0 (the exact underlying process).
    It was just meant as an example of when 'Visible' isn't 'Visible'. To more precisely illustrate an example of your problem we only need one more line of code:

    Code:
    Option Explicit
    
    Private Sub Form_Load()
       Text1.Visible = True 'New Line!
       Debug.Print Text1.Visible
    End Sub
    The point being that if the control's container is not yet visible then the control itself also isn't. Not saying this is your problem but that it was worth checking. DataMiser was saying the same thing...
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  14. #14
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: True = False?

    Colin and Data are correct. A control will not return visible = true if the parent container is not visible (shown). Attached is a quick sample that demonstrates this.
    Attached Files Attached Files

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Oct 2013
    Posts
    25

    Re: True = False?

    Quote Originally Posted by dilettante View Post
    The attachment attempts to reproduce what I suspect you have going on.

    Basically your mistake is in thinking of the properties of controls as simple variables. Many of them are not, and setting them a value causes one or more messages to be sent to change some aspect of the control's state to change. By the same token querying them sends messages to retrieve state information.

    If the control or its container is not in a position to accept and process these messages the control wrapper (what you think of as a control in VB) can only return the last known value for the state attribute queried.

    .
    .
    .
    Apologies to Colin. Had I just tried your example (or interpreted properly what Data was saying about "visibility") I might have been able to deduce what dilettante explained (but may have missed the nice concurrent rant about MS Access ;-) ). Bonnie's hint about a parallel boolean array corresponds with your suggestion. Understanding this new little morsel made the kindly-provided code unnecessary and made me search my itty-bitty memory and come to the conclusion that this was probably the first time I'd filled in an "invisible" form because I think it's the first time I'd wanted to put multiline textboxes on a dynamically configured form and so didn't know destinations and types at design time. I've now learned my something new for today so I'm done.

    Thanks again to all and further apologies to those I seemed short with. Late nights and exaggerated little frustrations don't bring out the best in me.

    Hopefully your help with my demonstrated ignorance saves someone else some embarrassment.
    Last edited by jmkvbf; Feb 7th, 2015 at 02:50 PM.

  16. #16
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: True = False?

    I don't consider it a "dumb question" because until somebody runs into this scenario they would probably have the same expectation that you did.

  17. #17
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: True = False?

    Btw, checking WS_VISIBLE on a child control is more reliable when the container is hidden or not shown yet.

    cheers,
    </wqw>

  18. #18
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    Re: True = False?

    Ah, you'll get used to dilettante's 'rants'. Actually very humorous most of the time, and usually spot-on observations as well. I once suggested he write a book!

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