Announcement

Collapse
No announcement yet.

Double Assignment? or Coding Shortcut?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Double Assignment? or Coding Shortcut?

    I am not sure how to even ask the question, but I think a statement like below is a coding shortcut?
    Code:
    CheckStatus = (szText = "Y")
    Would it be a shortcut for
    Code:
    IF szText = "Y" Then
         CheckStatus = %TRUE
    ELSE
        CheckStatus = %FALSE
    END IF
    ????????????????????

    I have no clue, and no idea what to search for to even hazard a guess except my guess above.
    To me it makes sense, but I may be WAYYYY OFFFffff?????
    Engineer's Motto: If it aint broke take it apart and fix it

    "If at 1st you don't succeed... call it version 1.0"

    "Half of Programming is coding"....."The other 90% is DEBUGGING"

    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

  • #2
    It's virtually identical, except that
    Code:
    CheckStatus = (szText = "Y")
    evaluates to -1 if true, whereas the IF..THEN evaluates to 1 if you're using win32api.inc.

    Comment


    • #3
      Coding boolean variables that way using BASIC has been common for at least twenty years.
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Also Cliff, for efficiency you may want to consider either option below. Both are over twice as fast as the code above.
        Code:
         CheckStatus = (ASC(szText) = 89)
        
        'or...
        
         IF ASC(szText) = 89 THEN
            CheckStatus = %TRUE
         ELSE
            CheckStatus = %FALSE
         END IF

        Comment


        • #5
          You can do all sorts of things with boolean values, Cliff.

          For i = 0 to -(Mode = 1)

          Looks daft out of context but with 'Mode = 1' I was interested in both File(0) and File(1) otherwise just File(0).

          We could have f(x) = y - 3*(x > 2)

          where we add 3 if x>2.

          and so on .....

          Comment


          • #6
            Originally posted by Michael Mattias View Post
            Coding boolean variables that way using BASIC has been common for at least twenty years.
            Keep going. I suspect it's as old as BASIC. There were certainly plenty of BASICs about in the 1970s, notably (at least numerically) on WANG and DEC machines.

            Comment


            • #7
              My goodness, people really DO use those demos...
              http://www.powerbasic.com/support/pb...ad.php?t=24485
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8

                I just KNEWWWWW that MCM would recognize a blotch of his own code

                I was looking at your Demo that I unfortunately found after writing some of my own routines for a listview, but what interested me was how yours had checkboxes in fields other than the 1st column

                I should have been thinking but the concept of Boolean Assignment did not even occur to me.

                I am now considering recoding my routines incorporating from your demo of multiple checkboxes, to see if my drag and drop routines work better in that context.

                By the way....NICELY documented and commented code in that example....it allows me to figure out just what the heck the thing is doing (unlike the example I based from elsewhere, that took me forever to figure out what the variables meant)
                Engineer's Motto: If it aint broke take it apart and fix it

                "If at 1st you don't succeed... call it version 1.0"

                "Half of Programming is coding"....."The other 90% is DEBUGGING"

                "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                Comment


                • #9
                  You can do ONE checkbox per listview row and have it appear in any column without drawing it yourself. Just add add style LVS_EX_CHECKBOXES using the Listview_SetExtendedListviewStyle macro.

                  It will be in column (subitem) zero, but you can move that using the ListView_SetColumnOrderArray macro/function.

                  FWIW, handling the stateimagemasks with checkboxes can get funky. I think I have some macros I use, let me look...

                  Well, nothing that clean, but this code does a TOGGLE
                  Code:
                  %LV_CHECKBOX_SELECTED        = 8192&
                  %LV_CHECKBOX_NOT_SELECTED    = 4096&
                  ....
                  ....
                                     StateMask       = %LVIS_STATEIMAGEMASK   ' only set bits 12-15
                                     hWndLV          = GetDlgItem (hWndTab(%SUB_TAB_CLAIMLIST),%ID_LISTVIEW_CLAIMS)
                                     StateMask       = %LVIS_SELECTED OR %LVIS_STATEIMAGEMASK    ' get selected and marked status
                                     FOR I = 0 TO @pOSVP.RFI.nClaim -1
                                        J    = SendMessage(HwndLV, %LVM_GETITEMSTATE, I, StateMask)
                                        IF ISTRUE (J AND %LVIS_SELECTED) THEN  ' this is the selected item
                                           ' get the item data from the listview, in which the lparam is pClaim
                                           IF ISTRUE ((J AND %LV_CHECKBOX_SELECTED) = %LV_CHECKBOX_SELECTED) THEN
                                              StateVal           = %LV_CHECKBOX_NOT_SELECTED
                                              CheckStatus        = %MF_UNCHECKED
                                           ELSEIF ISTRUE ((J AND %LV_CHECKBOX_NOT_SELECTED) = %LV_CHECKBOX_NOT_SELECTED) THEN
                                              StateVal           = %LV_CHECKBOX_SELECTED
                                              CheckStatus        = %MF_CHECKED
                                           END IF
                                           ListView_SetItemState hWndLv, I, StateVal, %LVIS_STATEIMAGEMASK
                                           ' redraw this item in the list view
                                           SendMessage hWndLV, %LVM_REDRAWITEMS, I, I
                                           ' update and redraw the checkmark on the menu to match
                                        '   CheckMenuItem GetSubMenu(g_hMenuViewer, %MENUVIEWER_REPORTS_INDEX),_
                                        '            %IDM_REPORT_TOGGLE_MARKED, %MF_BYCOMMAND OR CheckStatus
                                        '   DrawMenuBar g_hWndFrame
                                           EXIT FOR
                                        END IF   ' if this is the currently selected claim on the claimlist screen
                                                 ' (meaning its also the selected claim on all the other 'claim'
                                                 ' screens of the on-line viewer)
                                     NEXT I
                                    '



                  MCM
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    :doh:

                    That code is a little old. Don't use it unless you are on Windows 95 with Common Controls EARLIER than v 4.70

                    ListView_SetCheckState and Listview_GetCheckState are much easier to understand and use.

                    But if you are running C/C less than 4.70.....it's the only way to do it.
                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      ONE checkbox per listview row and have it appear in any column without drawing it yourself. Just add add style LVS_EX_CHECKBOXES using the Listview_SetExtendedListviewStyle macro.
                      Thats what I was starting to get, but did not know only 1 checkbox per row.

                      That and my own tests are showing that owner-drawn seems to be the only way to go (and probably why other examples are using arrays and then "Fake" rearrangement of checkboxes)

                      ListView_SetColumnOrderArray
                      Yep missed that one too...since I did not want sorting (Because this is truely "Application-Specific" category

                      The one lil bugger I am getting myself into with my lil wrapper is the concept of
                      Code:
                      Listview_SetItemText ListViewHandle, CheckBoxRow, CheckBoxCell, TextInCell
                      which in turn calls the callback to redraw, and I find myself in a continuous loop, (No biggie, I just have to take a step back and look at the procedural process of what happens when)
                      Engineer's Motto: If it aint broke take it apart and fix it

                      "If at 1st you don't succeed... call it version 1.0"

                      "Half of Programming is coding"....."The other 90% is DEBUGGING"

                      "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                      Comment


                      • #12
                        The one lil bugger I am getting myself into with my lil wrapper is the concept of
                        Listview_SetItemText...
                        Conceptually that's no different from SetWindowText or CONTROL SET TEXT.

                        Windows realizes the text has changed and therefore the control must be redrawn; so it calls the appropriate window procedure with that notification.

                        It's just that the listview control gives the owner window more opportunities to draw the control than it gets with a non-owner-drawn text control.

                        If you used style SS_OWNERDRAW for a regular text (LABEL) control, you'd get WM_DRAWITEM notification the same as you get WM_NOTIFY/NM_CUSTOMDRAW. The listview (and I believe all the Common Controls) give you WM_NOTIFY/NM_CUSTOMDRAW even if you don't use an owner-draw style.

                        Come to think of it, I don't think there is a generic "owner draw" style (WS_* or CCS_*) for the Common Controls, so there really is no choice but to always give you a "draw me" notification.
                        Michael Mattias
                        Tal Systems (retired)
                        Port Washington WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment

                        Working...
                        X