• Not Answered

Debugging VB Script for a graphic

Dim number
Dim activeBits
number = InputBox("Enter 16-bit number:")
activeBits = ""

For i = 15 To 0 Step -1
    If (number And (2 ^ i)) <> 0 Then
        activeBits = activeBits & "bit" & (15 - i) & ","
    End If
Next i

If Len(activeBits) > 0 Then
    activeBits = Left(activeBits, Len(activeBits) - 2)
    MsgBox "Active bits are: " & activeBits
Else
    MsgBox "No bits are set in this number."
End If

I wrote this code to see which bits are set from a 16-bit number i.e. the Boolean fan input output value. The user enters the value and it is meant to display the list of set bits, if any. I am not sure why it won't compile. Is there something obvious that I am overlooking or not spotting? Any help is appreciated.

Best regards,

Wilson

6 Replies

  • You have never defined i...Add Dim i as Integer.

    The other Dims don't have a type so with will be Variants and you may have to do some converting of datatypes in your logic. Take Number for example, you will get a string from Input box. Best to define your variables and convert them to types needed for your logic.
  • In reply to Matt Stoner:

    I would also suggest you change this line:
    activeBits = Left(activeBits, Len(activeBits) - 2)

    to

    activeBits = Left(activeBits, Len(activeBits) - 1)

    Removing 2 characters cuts into the last numbered bit.
  • In reply to Matt Stoner:

    Thank you, Matt. That rattled my brain for ages!
  • In reply to Matt Forbis:

    Yes I was wondering why I could not see the last bit. Thank you, Matt
  • I'm also looking for a solution to reading DeltaV module parameters using the VB script. I know there is a frsWriteValue function but can't see to find one for just reading a value... Even though that's all the graphics do is read value...
  • In reply to Wilson Halligan:

    frsReadValue. If you open the help documements while in the vba editor, choose the iFix Automation help. Anything starting with frs is more than likely specifically created for DeltaV, but this will have examples and details about the different functions that are available.