Silo1337
02-05-2008, 04:43 PM
This has to do with gaming but not the gaming that you all are probably thinking about, if this is the wrong section please move it accordingly. I am currently trying to make a program for people who play games on the PSP and it's supposed to help make "code making" easier. One step I am trying to do is convert ascii to hex, I can convert it correctly, however it's not quite coming out the way I want it to. Here's my code snippet, note that nothing is named accordingly because I typed it up in a different project after looking at some tutorials online.
Dim x As Integer
Dim tempstring As String
Dim tempPos As Integer
Dim tempAsc As String
Text2.Text = ""
tempPos = Len(Text1.Text)
For x = 1 To tempPos
tempstring = Mid(Text1.Text, x, 1)
tempstring = Hex(Asc(tempstring))
Text2.Text = Text2.Text & tempstring & " "
Next x
If you enter "Text1" into the textbox and convert it, it will convert it successfully to:
54 65 78 74 31
However I would like the outcome to be:
74 78 65 54
00 00 00 31
How could I do this?
Also, I am wondering if it's possible to add a certain value to multiple lines in a richtextbox (or regular textbox)
For example, the richtextbox might hold:
1
2
3
4
I would like to add + 3 to each line and have the outcome be:
4
5
6
7
Anyway I can do this? Thanks for any help! :D
the master
02-06-2008, 02:10 AM
Ok, here goes. For your hex conversion i would suggest a loop with step 4 and a sub loop that loops backwards. This should give you your hex values in the format you want. You would have to put an if statement in though to insert "00" if you are past the end of the string.
A standard textbox can have more than 1 line of text if you set .multiline to true.
For adding the numbers i think split(), a loop and join() should do the trick.
dim lines() as string
dim x as integer
lines()=split(text1.text,vbnewline) 'Split it into an array of lines
for x = 0 to ubound(lines()) 'Loop through each line
lines(x)=val(lines(x))+3 'Add 3
next
text1.text=join(lines(),vbnewline)
Silo1337
02-06-2008, 11:45 AM
Ah, you gave me some insight on how to do both options I was working toward. Your coding for the addition worked excellent and now all I have to do is work on the conversion of hex to decimal and then adding a certain amount. I should be able to get it off of the code you have given me as I already have the conversion on another form written correctly.
I am working on the loop for the conversion of ascii to hex. I appreciate your help! :)
I have this sort of figured out and have studied the code you have supplied me with in and out, however I cannot seem to get it to convert the hex to decimal correctly, here's what is happening:
I am trying to make it increase by + 94946164987683 after it is converted to a decimal, I can successfully add something along the lines of 20559864 and get the right outcome, however I cannot seem to get something like 2055a534 to convert correctly. Here is my code (and yours lol)
Private Sub Command1_Click()
Dim lines() As String
Dim x As Integer
lines() = Split(Text1.Text, vbNewLine) 'Split it into an array of lines
For x = 0 To UBound(lines()) 'Loop through each line
strHexValue = "" & Val(lines(x))
lines(x) = Val(lines(x)) + 94946164987683# 'Add Value for encryption
Text1.Text = "" & Val("&H" + strHexValue)
Next
Text1.Text = Join(lines(), vbNewLine)
End Sub
the master
02-06-2008, 06:02 PM
Im not sure why you are adding such a big number. Im not even sure if VB can cope with that. You put "a" in one of the numbers. Is that a typo?
A few comments about this line of code
Text1.Text = "" & Val("&H" + strHexValue)
There is no need to add a blank string to the begining. This will give you the same result
Text1.Text = Val("&H" + strHexValue)
Im not sure about "&H" either. I think that it just something used in VB to set a value in hex. The problem you have is that you have put it in a string so when VB tries to get the val() of it, it will always return 0 because "&" is not a number
Tip: Use [ VB ] [ /VB ] tags when posting VB code
Silo1337
02-06-2008, 07:15 PM
Let me start off by saying sorry about not posting the code in tags, I wasn't sure how I was supposed to do it. The size of the number doesn't matter but VB can handle the current number I have without overflowing, it could have been 923497 for all it matters. It's supposed to be a light encryption type program.
Here's the code that I have that works very well when "encrypting" and I'll give you a sleight example:
strhexvalue = "" & txtencrypt.Text
txtoutcome.Text = "" & Val("&H" + strhexvalue)
txtoutcome.Text = txtoutcome.Text + 94946164987683
If I were to enter "56896c" (Yes, the C, since we're using hexadecimal) and "encrypted" it, it would output the value of: 94946170658959.
How I got that was by converting "56896c" to a decimal and then adding the large number (94946164987683) to it.
I want to be able to undergo the same process but with multiple lines... Which is the reason why I was asking how to add values to multiple lines in the text box.
the master
02-07-2008, 08:01 AM
Im still a bit lost as to how your code works but to add something to each row see the code i posted in post #2. It splits the contents of text1.text into an array of lines. It then loops through each line and adds a number to it then finally joins all the lines back together and puts them back in text1.text.
If you want to do this for the rows of 4 values then you can split it into seperate lines as in post #2 then in the loop split each line into the 4 values. Use split() again but with a space as a deliminator and loop through the array of values in that line (0-3)
Silo1337
02-07-2008, 10:22 AM
I am using a different encryption method now that is a lot more stronger than the one I posted. I searched xtremevb for some topics on encryption and came up with one that suits my needs. My only problem is I can only encrypt so many lines of text which I am sure I can fix on my own. I appreciate your assistance!
Edit: I have successfully done exactly what I wanted. Thank you so much for your help!