Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. how to use compare function

how to use compare function

Scheduled Pinned Locked Moved Visual Basic
tutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zhiyuan16
    wrote on last edited by
    #1

    dear all how to use compare function, the following is the example code for reading input bit

    Dim iShift As Double, I As Double

    iShift = 1
    For I = 0 To 7
        Compare = Int(InputByte And iShift)
        If Compare = iShift Then   'Bit Turn OFF
            AMD\_GalilInputAxisBit(I) = 1
            AMD\_GalilInputBit(I) = 1
            'DigitalIO.Label2(I).BackColor = vbRed
        Else
            AMD\_GalilInputAxisBit(I) = 0 'Bit Turn ON
            AMD\_GalilInputBit(I) = 0
            'DigitalIO.Label2(I).BackColor = vbGreen
        End If
        iShift = iShift \* 2
    Next I
    
    D L 2 Replies Last reply
    0
    • Z zhiyuan16

      dear all how to use compare function, the following is the example code for reading input bit

      Dim iShift As Double, I As Double

      iShift = 1
      For I = 0 To 7
          Compare = Int(InputByte And iShift)
          If Compare = iShift Then   'Bit Turn OFF
              AMD\_GalilInputAxisBit(I) = 1
              AMD\_GalilInputBit(I) = 1
              'DigitalIO.Label2(I).BackColor = vbRed
          Else
              AMD\_GalilInputAxisBit(I) = 0 'Bit Turn ON
              AMD\_GalilInputBit(I) = 0
              'DigitalIO.Label2(I).BackColor = vbGreen
          End If
          iShift = iShift \* 2
      Next I
      
      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      What are you talking about? You're not using a Compare method or function at all in this code. All you're doing is comparing a numeric value to another one.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak

      1 Reply Last reply
      0
      • Z zhiyuan16

        dear all how to use compare function, the following is the example code for reading input bit

        Dim iShift As Double, I As Double

        iShift = 1
        For I = 0 To 7
            Compare = Int(InputByte And iShift)
            If Compare = iShift Then   'Bit Turn OFF
                AMD\_GalilInputAxisBit(I) = 1
                AMD\_GalilInputBit(I) = 1
                'DigitalIO.Label2(I).BackColor = vbRed
            Else
                AMD\_GalilInputAxisBit(I) = 0 'Bit Turn ON
                AMD\_GalilInputBit(I) = 0
                'DigitalIO.Label2(I).BackColor = vbGreen
            End If
            iShift = iShift \* 2
        Next I
        
        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi, seems acceptable; here are a few remarks: 1. when manipulating bits, make sure your variables are integers, so don't use double. 2. while your comparison to iShift is OK, you could as well test for zero. 3. maybe, just maybe, you have your two cases (equal and not equal) swapped. This would be my style (assuming InputByte is an integer too):

        Dim I As Integer
        Dim iShift As Integer = 1
        For I = 0 To 7
            If (InputByte And iShift)= 0 Then   'Bit Turn OFF
                AMD\_GalilInputAxisBit(I) = 0
                AMD\_GalilInputBit(I) = 0
            Else 'Bit Turn ON
                AMD\_GalilInputAxisBit(I) = 1 
                AMD\_GalilInputBit(I) = 1
            End If
            iShift = iShift + iShift
        Next I
        

        :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups