Results 1 to 9 of 9

Thread: Problems with varibles

  1. #1
    New Member
    Join Date
    Sep 12
    Posts
    3

    Problems with varibles

    hi guys

    I have this problem:

    MsgBox(&H33 Xor &H34) will show the correct answer = "7"

    but i ned to use varibles in stead so made this

    EAX = 34
    ECX = 33
    MsgBox(ECX Xor EAX)

    but this shows the wrong answer "3"

    How can i fix it? (i know it show "3" because it thinks it is decimal but as the first code shows i need it to xor in hex)

    could someone plz help me?

  2. #2
    .Net Member dday9's Avatar
    Join Date
    Mar 11
    Location
    South Louisiana
    Posts
    2,171

    Re: Problems with varibles

    I've never seen the Xor operator before, however after looking at the documentation it looks as though it is a boolean value. So I think that the first thing you should do is turn option strict and option explicit on and that would work out a few conversion errors for you.

  3. #3
    New Member
    Join Date
    Sep 12
    Posts
    3

    Re: Problems with varibles

    i'm not sure i understand you solution because

    this works as it should ---> MsgBox(&H33 Xor &H34) will show the correct answer = "7"

    i just need a way to tell the program that the values in EAX and ECX should be treatet as hexvalue so

    Msgbox(eax xor ecx) also gives "7"

  4. #4
    Hyperactive Member DavesChillaxin's Avatar
    Join Date
    Mar 11
    Location
    WNY
    Posts
    419

    Re: Problems with varibles

    Just declare some constants.

    C#
    Code:
    const Int64 EAX = 0x034;
    const Int64 ECX = 0x033;
    
    MessageBox.Show((EAX ^ ECX).ToString());
    VB.net
    Code:
    Const EXC As Int64 = &H34
    Const ECX As Int64 = &H33
    
    MessageBox.Show((EAX XOr ECX).ToString())
    Both these examples will result in 7 as you're requiring.
    Please rate if my post was helpful!
    Per favore e grazie!




    Code Bank:
    Advanced Algebra Class *Update | True Gradient Label Control *Dev | A Smarter TextBox *Update | Register Global HotKey *Update
    Media Library Beta *Dev | Mouse Tracker (Available in VB.net and C#.net) *New | On-Screen Numpad (VB.net) *New

  5. #5
    New Member
    Join Date
    Sep 12
    Posts
    3

    Re: Problems with varibles

    wel i can't do that here are the whole code:

    teller = 6

    For k = 2 To teller
    Delecx = Asc(Mid(Serial_after_check, EDX, 1))
    ECX = Delecx.ToString("X2")
    EBX = (EBX Xor ECX) <------here is the problem as you can see i can't declare it
    EDX = EDX + 1
    EAX = EAX - 1

    Next k

    in the first run of the loop EBX is 33 and ECX is 34 it should be 7 and stored in EBX but, i gives 3

  6. #6
    Fanatic Member SJWhiteley's Avatar
    Join Date
    Feb 09
    Location
    South of the Mason-Dixon Line
    Posts
    885

    Re: Problems with varibles

    Do you understand the difference between a number and a string? Do you understand the difference between decimal and hexadecimal, and how they relate to numbers and strings?

    You cannot perform an XOR function on a string. XOR is a bitwise operator, and requires a numeric value. In your example, the variable ECX is a string. Show your declarations, and work from there.
    "Ok, my response to that is pending a Google search" - Bucky Katt.

  7. #7
    .Net Member dday9's Avatar
    Join Date
    Mar 11
    Location
    South Louisiana
    Posts
    2,171

    Re: Problems with varibles

    Do you understand the difference between a number and a string?
    That's why I suggested to the OP to turn option strict and explicit on. I haven't tested it, but I'm sure that if it was on, it would've thrown an error.

  8. #8
    Fanatic Member SJWhiteley's Avatar
    Join Date
    Feb 09
    Location
    South of the Mason-Dixon Line
    Posts
    885

    Re: Problems with varibles

    Quote Originally Posted by dday9 View Post
    That's why I suggested to the OP to turn option strict and explicit on. I haven't tested it, but I'm sure that if it was on, it would've thrown an error.
    You are absolutely correct, of course. This should be the first order of the day
    "Ok, my response to that is pending a Google search" - Bucky Katt.

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 02
    Posts
    21,636

    Re: Problems with varibles

    Personally I think knowledge of the difference between a HEX (base 16) value and a DECIMAL (base 10) value needs to be understood... the OP is using 33 when he needs to use &H33 ... they are NOT the same values... Not even close.

    &H33 xor &H34 does not produce the same value as 33 xor 34 ... so... if you're extracting HEX values from a string they need to be treated as their HEX values and not as their DECIMAL values... OR... you need to take the hex values and translate them to their decimal values, then xor the two decimal values.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
    *Proof positive that searching the forums does work: View Thread *
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *
    * Use Offensive Programming, not Defensive Programming. * On Error Resume Next is error ignoring, not error handling(tm).
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •