Results 1 to 9 of 9

Thread: Problems with varibles

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2012
    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
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,375

    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.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2012
    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 2011
    Location
    WNY
    Posts
    451

    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

    Thread Starter
    New Member
    Join Date
    Sep 2012
    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
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    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.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

  7. #7
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,375

    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.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  8. #8
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    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.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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 don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * 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??? *

Posting Permissions

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



Click Here to Expand Forum to Full Width