subtracting base16

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cryoburned
    New Member
    • Sep 2007
    • 23

    #16
    ok your idea to get the value of the string.. sort of works...

    [code=vb]
    Private Sub Form_Load()
    hexfinal = "&H0000FFFF "
    End Sub

    Private Sub L2_Click()
    If l2on = False Then
    L2.ForeColor = &HFFFFFF
    l2on = True
    hexfinal = Hex(Val(hexfina l) - &HFFFF0100)
    Text1.Text = "0000" & hexfinal
    Text2.Text = "0010" & hexfinal
    ElseIf l2on = True Then
    L2.ForeColor = &H808080
    l2on = False
    hexfinal = Hex(Val(hexfina l) + Val("&H00000100 "))
    Text1.Text = hexfinal
    Text2.Text = hexfinal
    End If
    End Sub
    [/code]

    that was my last attemp..

    the subtraction works.. i get FEFF like i wanted..

    put the addition.. always results as the number 100 and not FFFF

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #17
      I'd like to try out your code, but I need you to fill in a couple of gaps. I assume Text1 and Text2 are textboxes, and hexfinal is obviously a string. But what are L2 and l2on?

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #18
        I think I should point out, though, that the result of VAL("FEFF") is zero, while VAL("&HFEFF") is -257 (or if you could get VB to treat it as unsigned, 65,279).

        Comment

        • cryoburned
          New Member
          • Sep 2007
          • 23

          #19
          Originally posted by Killer42
          I'd like to try out your code, but I need you to fill in a couple of gaps. I assume Text1 and Text2 are textboxes, and hexfinal is obviously a string. But what are L2 and l2on?
          L2 is a button, l2on is boolean

          Comment

          • cryoburned
            New Member
            • Sep 2007
            • 23

            #20
            Originally posted by Killer42
            I think I should point out, though, that the result of VAL("FEFF") is zero, while VAL("&HFEFF") is -257 (or if you could get VB to treat it as unsigned, 65,279).
            that did it.

            Code:
            Private Sub Form_Load()
            hexfinal = "0000FFFF"
            End Sub
            Private Sub L2_Click()
            If l2on = False Then
            L2.ForeColor = &HFFFFFF
            l2on = True
            hexfinal = Hex(Val("&H" & hexfinal) - &HFFFF0100)
            Text1.Text = "0000" & hexfinal
            Text2.Text = "0010" & hexfinal
            ElseIf l2on = True Then
            L2.ForeColor = &H808080
            l2on = False
            hexfinal = Hex(Val(("&H" & hexfinal) + &H100))
            Text1.Text = "0000" & hexfinal
            Text2.Text = "0010" & hexfinal
            End If
            End Sub
            works great now

            Comment

            • cryoburned
              New Member
              • Sep 2007
              • 23

              #21
              Originally posted by cryoburned
              hexfinal = Hex(Val(("&H" & hexfinal) + &H8000))
              I believe you have too many parentheses. I think this should be...

              Old version:
              hexfinal = Hex(Val(("&H" & hexfinal) + &H8000))
              New version:
              hexfinal = Hex(Val("&H" & hexfinal) + &H8000)

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #22
                Sorry, my goof. I think I must have hit the Edit button instead of Reply. Damn! :(

                Comment

                • cryoburned
                  New Member
                  • Sep 2007
                  • 23

                  #23
                  Originally posted by Killer42
                  Sorry, my goof. I think I must have hit the Edit button instead of Reply. Damn! :(
                  lo its cool.. but im still have the problem with 8000.. it goes to 7FFF in subtraction, but jumps to FFFFFFFF is addition.

                  Comment

                  • Killer42
                    Recognized Expert Expert
                    • Oct 2006
                    • 8429

                    #24
                    Originally posted by cryoburned
                    lo its cool.. but im still have the problem with 8000.. it goes to 7FFF in subtraction, but jumps to FFFFFFFF is addition.
                    Can you show us the exact code again? I think I zapped your last version when I did the accidental edit.

                    Comment

                    • QVeen72
                      Recognized Expert Top Contributor
                      • Oct 2006
                      • 1445

                      #25
                      Originally posted by cryoburned
                      lo its cool.. but im still have the problem with 8000.. it goes to 7FFF in subtraction, but jumps to FFFFFFFF is addition.
                      Hi,

                      Late into this thread,
                      Actually &H8000 is equivalent to 32768
                      but if you use Val function or CDec Function, they Start Showing Negative Value.
                      Val("&H8000") = -32768
                      Val("&H8001") = -32767 And so on.
                      You can also use CLng, but again to a certain Limit ..

                      Better Idea will be to use CDbl Function..

                      CDbl("&H8000") = 32768
                      CDbl("&H8001") = 32769


                      Regards
                      Veena

                      Comment

                      • cryoburned
                        New Member
                        • Sep 2007
                        • 23

                        #26
                        Originally posted by QVeen72
                        Hi,

                        Late into this thread,
                        Actually &H8000 is equivalent to 32768
                        but if u use Val function or CDec Function, they Start Showing Negative Value.
                        Val("&H8000") = -32768
                        Val("&H8001") = -32767 And So On..
                        u can also use CLng, but again to a certain Limit ..

                        Better Idea will be to use CDbl Function..

                        CDbl("&H8000") = 32768
                        CDbl("&H8001") = 32769


                        Regards
                        Veena
                        that doesn't make a difference for this project.. but i got it.. i dont know why i had this problem but... now

                        [code=vb]
                        hexfinal = Hex(Val((("&H" & hexfinal) + &H8000) - &HFFFF0000))
                        [/code]

                        gets me FFFF like i wanted..

                        Comment

                        • Killer42
                          Recognized Expert Expert
                          • Oct 2006
                          • 8429

                          #27
                          Originally posted by cryoburned
                          hexfinal = Hex(Val((("&H" & hexfinal) + &H8000) - &HFFFF0000))
                          Hm... still seems as though you have too many parentheses there. But I guess if it works, it works. :)

                          Congratulations !

                          Comment

                          • Killer42
                            Recognized Expert Expert
                            • Oct 2006
                            • 8429

                            #28
                            Originally posted by QVeen72
                            ... Better Idea will be to use CDbl Function ...
                            Thanks Veena, that's useful to know. I had no idea CDbl would produce a different result.

                            Comment

                            Working...