-1

could anyone show me the right way?

Private Function F(ByVal x As Integer) As Integer

    Static UnsignedAdd As Object
    Static xb(3) As Byte

    Call CopyMem(xb(0), x, 4)

    If (m_RunningCompiled) Then
        Return (CShort((m_sBox(0, xb(3)) + m_sBox(1, xb(2))) _ 
                  Xor m_sBox(2, xb(1))) + m_sBox(3, xb(0)))
    Else
        Return UnsignedAdd(UnsignedAdd(m_sBox(0, xb(3)), 
                  m_sBox(1, xb(2))) Xor m_sBox(2, xb(1)), m_sBox(3, xb(0)))
    End If

End Function

the return of

UnsignedAdd(UnsignedAdd(m_sBox(0, xb(3)), 
        m_sBox(1, xb(2))) Xor m_sBox(2, xb(1)), m_sBox(3, xb(0)))

is not set and vb.net always show me Object variable or With block variable not set. whats wrong with that code?

Ňɏssa Pøngjǣrdenlarp
  • 37,255
  • 11
  • 50
  • 147
user3760033
  • 23
  • 1
  • 6
  • 1
    hold your mouse over those variables when it happens one of them will be `Nothing` and thats the culprit. See http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it – Ňɏssa Pøngjǣrdenlarp Jun 23 '14 at 23:37

1 Answers1

0

UnsignedAdd is a local variable but there's nowhere in there that you are assigning a value to it so it will never have a value.

That's some rather dodgy code too. Surely you know what type UnsignedAdd will be so you should be able to declare it as that type. I can't really see a justification for Static variables either.

jmcilhinney
  • 40,280
  • 5
  • 23
  • 39