0

Really basic question.

I have a single form and want to create an object (I think) and assign a value to it.

Dim Devs as Object

    For i = 0 To 3
        If (Devices And 2 ^ i) Then
            Devs(i) = True ' breaks here
        Else
            Devs(i) = False 'or here (depends on the if obviously)
        End If
    Next i

With this I get an error: Object variable or With block variable not set

I thought I could just make an Array or Object and assign a value, but I guess I'm wrong.

What is the proper way to do this?

2 Answers 2

3

Looks like you want an array of Booleans

Dim Devs(0 To 3) As Boolean

Your current code has an Object variable that is not pointing to any object.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Works :) It indeed did not have trailing brackets
2

Your Devs variable seems to be an array of type Boolean. Correct?

Dim Devs(0 To 3) As Boolean()

or

Dim Devs() As Boolean()

Furthermore, what is the purpose of 2 ^ i ? Do you intend to validate its value in order to enter the first code bracket.

Dim myCondition As Integer
myCondition = 2

If (Devices = True And 2 ^ i = myCondition)
  ...

4 Comments

I really have no idea what the 2 ^ i does. I have to say, I had some spare time so I took my Velleman k8055 boards out of the closet. The example code had that in it. It works, and you know what they say. If it aint broken, don't try to fix it ;)
haha cool! well, then if you ever feel the urge to improve on your code, I would remove "2 ^ i" since it does nothing but perform an extra operation. Also, it doesnt hurt to improve on variable names. "Devices" could be renamed "AreDevices"/"HasDevices" for better readability of your code.
2 ^ i is raising 2 to the power i. The Devices variable must be a bitfield. The If checks whether the "ith bit" is set or unset, by performing a binary And operation.
yes i know MarkJ, my question was more "why is it there, have you forgot to validate its value?". but thankyou for taking the time to clarify.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.