Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


creating hex calculator with vb or c++
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
asianking
Expert Cheater
Reputation: 0

Joined: 25 Jun 2008
Posts: 109

PostPosted: Sun Nov 13, 2011 6:51 pm    Post subject: creating hex calculator with vb or c++ Reply with quote

Do anybody know how to create a hex calculator... I just need a simple of
box1.text - box2.text = total. I want a completely hex view and not dec view. If someone can help would be much appreciated. Thanks in advance.

_________________
Back to top
View user's profile Send private message MSN Messenger
OmegaCES
Cheater
Reputation: 1

Joined: 02 Jul 2011
Posts: 44

PostPosted: Sun Nov 13, 2011 7:42 pm    Post subject: Reply with quote

Code:
tTotal = Val("&H" + box1.Text) + Val("&H" + box2.Text)
MsgBox Hex(tTotal) & "h / " & tTotal & "d"


Hope that helps you with your program.
Back to top
View user's profile Send private message
asianking
Expert Cheater
Reputation: 0

Joined: 25 Jun 2008
Posts: 109

PostPosted: Sun Nov 13, 2011 9:32 pm    Post subject: Reply with quote

work out great, but the total box doesn't display hex format...
_________________
Back to top
View user's profile Send private message MSN Messenger
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Mon Nov 14, 2011 9:35 am    Post subject: Reply with quote

do your calculations in dec and just show them on hex

to convert a dec to hex just use this:

Code:
Function DecToHex(ByVal DecNum As Double) As String 
    Dim remainder As Integer 
    Dim HexStr As String 
    HexStr = "" 
    Do While DecNum <> 0 
        remainder = DecNum Mod 16 
        If remainder <= 9 Then 
            HexStr = Chr(Asc(remainder)) & HexStr 
        Else 
            HexStr = Chr(Asc("A") + remainder - 10) & HexStr 
        End If 
        DecNum = DecNum \ 16 
    Loop 
    If HexStr = "" Then HexStr = "0" 
    DecToHex = HexStr 
End Function 


//thanks to http://www.recursosvisualbasic.com.ar for that simple code.
Back to top
View user's profile Send private message MSN Messenger
asianking
Expert Cheater
Reputation: 0

Joined: 25 Jun 2008
Posts: 109

PostPosted: Mon Nov 14, 2011 12:00 pm    Post subject: Reply with quote

Nevermind; I find this way much easier:
Code:
If TextBox1.Text <> "" And TextBox2.Text <> "" Then TextBox3.Text = Hex(Int("&H" & TextBox1.Text) + Int("&H" & TextBox2.Text))

_________________
Back to top
View user's profile Send private message MSN Messenger
OmegaCES
Cheater
Reputation: 1

Joined: 02 Jul 2011
Posts: 44

PostPosted: Mon Nov 14, 2011 1:03 pm    Post subject: Reply with quote

Code:
MsgBox Hex(tTotal) & "h / " & tTotal & "d"

The only reason the code wouldn't have shown the value in hex is because you missed off the last part which is why it was there to show you both in decimal and hex to check the answers was correct etc Razz

Its the way I code I guess.
I always declare them first then place them into the textbox.
As with strings its faster to use (less cycles).
Code:
Dim tStr as String
tStr = "blah"
tStr  = tStr  & " Blah"
text1.text = tStr


Rather than:
Code:
text1.text = text1.text
and text1.text = text1.text & " Blah"

So i've just gotten used to doing it this way with all types Razz
The coding is pretty much what I posted Razz

Code:
tTotal = Val("&H" + box1.Text) + Val("&H" + box2.Text)

then you would just do
Code:
box3.text = hex(tTotal)


@gogodr
vb has the Hex(Value) built into it.
and Val("&H" + HexNum) to convert back Smile
Back to top
View user's profile Send private message
asianking
Expert Cheater
Reputation: 0

Joined: 25 Jun 2008
Posts: 109

PostPosted: Mon Nov 14, 2011 2:46 pm    Post subject: Reply with quote

I c.... great job buddy! Finally understand why my codes aren't showing...

Thanks for the help everybody

_________________
Back to top
View user's profile Send private message MSN Messenger
OmegaCES
Cheater
Reputation: 1

Joined: 02 Jul 2011
Posts: 44

PostPosted: Mon Nov 14, 2011 4:53 pm    Post subject: This post has 1 review(s) Reply with quote

No worries, glad to be of assistance.
Back to top
View user's profile Send private message
asianking
Expert Cheater
Reputation: 0

Joined: 25 Jun 2008
Posts: 109

PostPosted: Mon Nov 14, 2011 8:17 pm    Post subject: Reply with quote

one last question; is it possible to add all types of hex in the same line and it will calculate all of them seperately? Not sure if I make any sense here, but for instant if I space it then the next number will calculate seperate or if I press Enter then the next number will be calculate seperately?

For example:

table A
1
2
2 2
3

table B
9
A
2 2
B

total table
A
C
4 4
F

_________________
Back to top
View user's profile Send private message MSN Messenger
OmegaCES
Cheater
Reputation: 1

Joined: 02 Jul 2011
Posts: 44

PostPosted: Tue Nov 15, 2011 9:53 am    Post subject: Reply with quote

Code:
Private Sub Command_Click()
On Error GoTo Errer
Dim Lines1() As String, Lines2() As String
Dim tRow1() As String, tRow2() As String
Dim i As Integer, j As Integer
Dim tString As String

Lines1() = Split(Text1.Text, vbCrLf)
Lines2() = Split(Text2.Text, vbCrLf)

tString = ""

For i = 0 To UBound(Lines1)
tRow1() = Split(Lines1(i))
tRow2() = Split(Lines2(i))
    For j = 0 To UBound(tRow1)
        If j = UBound(tRow1) Then
            tString = tString & Hex((Val("&H" + tRow1(j)) + Val("&H" + tRow2(j)))) & vbCrLf
        Else
            tString = tString & Hex((Val("&H" + tRow1(j)) + Val("&H" + tRow2(j)))) & " "
        End If
    Next j
Next
Text3.Text = tString
Exit Sub
Errer:
  If Err.Number = 9 Then
    MsgBox "Invalid Format", vbCritical
  Else
    MsgBox Err.Number & ": " & Err.Description, vbCritical
  End If
End Sub

Added small error code for you.
Sloppiest code I've even written but I'm late for a meeting.
Will try to remember to log back in tonight.

Make 3 text boxes, text1, text2 and text3"
Put the code into a command button

text1:
Quote:
1
2
2 2
3


text2:
Quote:
9
A
2 2
B


click button and text3 gives output
Quote:
A
C
4 4
E

Your output was wrong for last one Wink
Hehe, hope that helped, I'll try to clean it up later as itll use alot more cpu cycles than needed but its a start for you to work on.
I wrote it in VB 6, are you using VB 6 or VB.net 2010.
It may differ, I have both so could convert it if it doesn't work.

I'll wait for your response before I relook into the code unless I can find time.. RL wayyy to busy sorry.
Back to top
View user's profile Send private message
asianking
Expert Cheater
Reputation: 0

Joined: 25 Jun 2008
Posts: 109

PostPosted: Tue Nov 15, 2011 1:22 pm    Post subject: Reply with quote

is it possible to shorten the codes down to 1 or 2 line only?

The main codes that I'm seeking for is treat space and or enter as separate calculation.

_________________
Back to top
View user's profile Send private message MSN Messenger
OmegaCES
Cheater
Reputation: 1

Joined: 02 Jul 2011
Posts: 44

PostPosted: Tue Nov 15, 2011 1:45 pm    Post subject: Reply with quote

Not for what you want, unless you create a function for it.
You could do it with just.

1
2
3
+
A
B
C

but because you wanted spaces between you have to split both the lines from textbox and then the space.

Or you could do 1 1 2 a 3 b
And same again for textbox 2, but then it would require you to split both and calc them and then readd to the text both in the format you wanted.

What would the code length matter vb compiles small exe's and if its only a calc it wouldn't be called alot so wouldn't make performance issues, like I said it could be shrunk down a bit but for what you asked for not that much at all.

It now depends what you want and what you need it laid out like that for Razz
Back to top
View user's profile Send private message
asianking
Expert Cheater
Reputation: 0

Joined: 25 Jun 2008
Posts: 109

PostPosted: Tue Nov 15, 2011 5:48 pm    Post subject: Reply with quote

yeah i guess, I tried; for some reason it wouldn't take it. Mention something cannot convert; double invalid.

btw, I'm using vb 2010 exp.

_________________
Back to top
View user's profile Send private message MSN Messenger
OmegaCES
Cheater
Reputation: 1

Joined: 02 Jul 2011
Posts: 44

PostPosted: Tue Nov 15, 2011 7:04 pm    Post subject: Reply with quote

It wouldn't take the code I posted?
If you wish to PM details of your project, if you wish to keep it to yourself and say what your code is doing when I get home I'll try to whip you up a simple bit of code for you to work on.

The codes I posted are for vb6, but are similar just have to tweak them a little, if you have access to the MSDN database you should be able to find the correct updates.

Also the project converter is pretty good.
Either explains here or in a PM and i'll do my best to give you smaller code, but because of what you've asked for so far it requires more code. Yet I wouldn't see what the problem would be with a few more lines, if it was running in a timer then it'd be a problem but because its only when its pressed it shouldn't matter Smile

When I finish work tomorrow I'll loadup VB2010 and try to help you if you ask Smile
Good luck with the project and let me know Smile
Back to top
View user's profile Send private message
asianking
Expert Cheater
Reputation: 0

Joined: 25 Jun 2008
Posts: 109

PostPosted: Wed Nov 16, 2011 3:08 pm    Post subject: Reply with quote


_________________
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites