I am stuck at this...
I have a crypto module to encrypt and decrypt some data...
The encrypt works fine and I get the encrypted data and encrypted key as an array and the save it as a single line string, seperating the values with commas.
My problem is that even Dimming the Array as Byte, when I load and seperate the values to the array, they are "read" as string and not as byte..
how can i Change the data type without changing the values?????
Example:
String="122,10,4,23,65,9,76,88" 'each individual value is a BYTE
Key()=StrPlit(String,",") ' EVEN if i declare this as a Byte array, it gets treated as strings...
StrSplit returns an array of strings.
You will need to use something like:
B4X:
Sub Globals
dim str(0) as String
dim key(0) as byte
End Sub
...
str() = StrSplit(...)
dim key(ArrayLen(str()) as Byte
For i = 0 to ArrayLen(str()) - 1
key(i) = str(i)
Next
Thanks EREL, I've already tried that but in a diferent way, so didn't work..
Your's does work like a charm...
Now I have a new problem...
I'm passing two strings that need to be converted to bytes, using your code..
The first on works good, and I trimmed it a bit...
The second one is giving me some troubles...
Here's my code:
B4X:
CodeStr()=StrSplit(CodeString,",")
n=ArrayLen(codestr())
Dim Decode(n) As Byte
Msgbox(ArrayLen(Decode()))'This returns 0
' For i = 0 To ArrayLen(Decode())-1
' Decode(i) = DecodeStr(i)
' Msgbox(Decodestr(i))
' Next
I commented the line to troubleshoot...
My problem is that Decode is comming out empty.....Why????
CodeStr()=StrSplit(CodeString,",")
For x=0 to ArrayLen(CodeStr())-1
MsgBox(CodeStr(x))
Next
All the values that I KNOW exist in the string are correctly shown..
Furthermore if I add:
n=ArrayLen(CodeStr())
MsgBox(n)
I get "16" that is the correct value, but that can be either bigger or smaller, depending on user input...
Now the program just crashes the IDE...
I'm trully Puzzled...
EDIT:
Further narowing...
B4X:
DecodeStr()=StrSplit(CodeString,",")
Dim Decode(ArrayLen(DecodeStr())) As Byte
For a = 0 To ArrayLen(DecodeStr())-1
' Decode(a) = DecodeStr(a)
Msgbox(Decodestr(a))
Next
Shows the correct values for the "DecodeStr" wich is a string array, but if I un-comment the "Decode(a)=DecodeStr(a)" line the IDE CRASHES...
Define "Crash", any error meassage? That fragment works for me as long as the values in DecodeStr are between 0 and 255 otherwise I get an error message that the value was too small or too large for an unsigned byte.
Again you are RIGHT!!!!!
Thanks Andrew....
Sometimes coming up with names that make sense is a bit tricky....
I was so puzzled about the situation that I didn't even remember to look at the vars names and lok for conflicts....