Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BitMask

Status
Not open for further replies.

jl280328

Programmer
Jun 15, 2006
97
US
I am reading in an Integer from a file and I have to compare it to a hex bitmask to see if which values need to be checked. How would I go about comparing a hex value (i.e. 0x0001) To a numerical value such as 48? I tried this:
Code:
Property BitMask As Byte

but kept getting an error b/c it said I needed a Get or Let or Set?
 
You can't just declare a property like that. You need Property Let and Property Get accessors to set/retrieve the value of the private data member of a class.

As for hex, the VB syntax is &H0001 corresponding to your example.
 
I am trying this right now:
Code:
Private mByte As Byte

Public Property Get CountAttached() As Byte
    CountAttached = mByte.CountAttached
End Property

but am getting an error that says Invalid attribute in sub or function and it highlites the Private word on the first line there
 
[red]Byte[/red] is a basic data type ... not an object as in VB.Net so it doesn't have properties.

mByte.CountAttached is probably invalid and should be just mByte
 
I have it setup like this now:

Code:
Public Property Get CountPPY() As Byte
        CountPPY = mPPY
End Property

If CountPPY() = &H1 Then
        'do something here
End If

The if statement is in its own procedure of course, but the CountPPY() in the if statement is coming back as 17 how do I get it to return the hex value comparable to the &H1?
 
Did you want it to get a hex representation of the byte, or the byte itself? To change the value of CountPPY, you would have to change the value of mPPY. Every call you make to CountPPY causes your app to check the value of mPPY.

Also, if I am looking at your code correctly, you shouldn't need to include the brackets:
Code:
if (CountPPY = &H1) then
  'do something
end if
or
Code:
if (Me.CountPPY = &H1) then
  'do something
end if
 
You might want to use the VB Add-in, "Class Builder Utility." It will help you produce fool-proof classes, properties, etc. and save you a lot of typing. For example, here's some output you might get by creating a class "clsTest" with a property CountPPY.
Code:
Option Explicit

'local variable(s) to hold property value(s)
Private mvarCountPPY As Byte 'local copy
Public Property Let CountPPY(ByVal vData As Byte)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.CountPPY = 5
    mvarCountPPY = vData
End Property


Public Property Get CountPPY() As Byte
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.CountPPY
    CountPPY = mvarCountPPY
End Property
Then, plop a button and a label on a form to use it, and get what you expect.
Code:
Private Sub cmdTest_Click()
    Dim objTest As clsTest
    
    Set objTest = New clsTest
    objTest.CountPPY = &H11 '<<< play with this value to see what happens
    Label1.Caption = objTest.CountPPY
    Set objTest = Nothing
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top