Hello.
I am new at forum. I am trying to write a program which will adding to hexadecimal numbers. I have a word EN and i will find CRC code of it as 93. E is 45 and N is 4E. And then i would like to finf 93 for CRC code of EN. I wrote a program which finds 45 and 4E but i cant add them.

Hexadecimal numbers are strings. You don't want to do any mathematical operation with strings. Instead, add the values you used to get the hexadecimal numbers. The sum is decimal 147, which is hexadecimal 93.

Ok. But how i can do this? For example i have a word MOVE 1. When I write this into text box as a MOVE 1 i want to find hexadecimal 88 into an other textbox.

I wrote a program to do this but now i have an other problem. When addition of numbers reach 256, program isnt working and giving error.

Private Sub Command8_Click()
Data = Text4.Text
Counter = 1
Sonuc = 0
KarakterSayisi = Len(Data)
Do While Counter < KarakterSayisi + 1
Karakter = Mid(Data, Counter, 1)
Donusturucu = Asc(Karakter)
a = Donusturucu
b = Sonuc
c = a + b
Sonuc = Donusturucu + Sonuc
Counter = Counter + 1
Loop
Sonuc = Hex(c)
Text5.Text = Sonuc
End Sub

Still not clear what you're trying to do.
Add 2 numbers & show hex result:
Dim Hx As String
Hx = Hex\$(Num1 + Num2)
The reverse:
Dim Total As Long
Total = Val("&H" & Hx)

Originally Posted by Korhan793
When addition of numbers reach 256, program isnt working and giving error.
When you get en error and want help with it you need to tell us what the error is and what line it is happening at.

First off, you should use Option Explicit and declare all of your variables.
What is Option Explicit, and why should I use it?

Command8, Text4 and Text5 are meaningless names.
Use the Properties Window (F4) to change the names to something more meaningful.
Code:
```Private Sub Command8_Click()
Dim strData As String
Dim lngCounter As Long
Dim lngCharCode As Long
Dim lngSum As Long

strData = Text4.Text
' For each character in the string...
For lngCounter = 1 To Len(strData)
' Get the character code
lngCharCode = Asc(Mid\$(strData, lngCounter, 1))
' Add this to the sum. The "And &HFF&" keeps the sum under 256
lngSum = (lngSum + lngCharCode) And &HFF&
Next lngCounter
Text5.Text = Hex(lngSum)
End Sub```
Instead of using the bitwise And operation, you could subtract 256 from the sum whenever it is greater than 255.

I solved my problem thanks a lot.

#### Posting Permissions

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

Featured