Italian Aiuto da vb6 a b4a

diresc

Member
Licensed User
Longtime User
non esco fuori mi hanno suggerito dal forum
di usare byteconverter ,provandolo continua a darmi errori
e non ho il risultato giusto.

la stringa da convertire è 01555500FEF103 ECC...
prendo due valori alla volta
es.."55" diventa "85" e poi chr del valore "U"




Public Function hex2ascii(ByVal hextext As String) As String

For y = 1 To Len(hextext)
num = Mid(hextext, y, 2)
Value = Value & Chr(Val("&h" & num))
y = y + 1
Next y

hex2ascii = Value
End Function

grazie mille
 

AlpVir

Well-Known Member
Licensed User
Longtime User
Sbaglio o B4A, a differenza del Vb6, non prevede l'utilizzo del nome della variabile nell'istruzione "next" ?
Prova con "next" e non con "next y"
 

diresc

Member
Licensed User
Longtime User
penso che così funzioni

'CONTENUTO = "0155550000000063FEF103"
CONTENUTO = TESTO
BARRAY = CONVERT.HexToBytes(CONTENUTO)
CONTENUTO1 = CONVERT.StringFromBytes(BARRAY, "ASCII")
COMPILATO.Text=CONTENUTO1

-adesso ho problemi a ricevere dopo che ho inviato attraverso il socket
il comando


con questo codice:
Dim tw As TextWriter
Dim tr As TextReader
Dim InputStream1 As InputStream
Dim OutputStream1 As OutputStream
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''

tr.Initialize(Socket1.InputStream)
tw.Initialize(Socket1.OutputStream)
tw.WriteLine(COMPILATO.Text)
tw.Flush

Dim line As String
line = tr.ReadLine '''error pause in Debug
Do While line <> Null
Log(line)
line = tr.ReadLine
Loop
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''
error:java.net.socketexception:bad file number ??????

paths configuration
C:\Programmi\Java\jdk1.6.0_26\bin\javac.exe
C:\Programmi\Android\android-sdk\platforms\android-8\android.jar
Basic4Android :version 1.70

poteti aiutarmi
Grazie
 

Augusto

Member
Licensed User
Longtime User
Hai dichiarato le variabili "Value e num" come stringa ?
Pero' sono Newbie e non so di default come vengono considerate da b4a le variabili non definite...

Altro particolare... non potevi usare nel FOR un step 2 al posto di fare un y=y+1 poi ?
For y = 1 To Len(hextext) Step 2

non esco fuori mi hanno suggerito dal forum
di usare byteconverter ,provandolo continua a darmi errori
e non ho il risultato giusto.

la stringa da convertire è 01555500FEF103 ECC...
prendo due valori alla volta
es.."55" diventa "85" e poi chr del valore "U"




Public Function hex2ascii(ByVal hextext As String) As String

For y = 1 To Len(hextext)
num = Mid(hextext, y, 2)
Value = Value & Chr(Val("&h" & num))
y = y + 1
Next y

hex2ascii = Value
End Function

grazie mille
 
Last edited:
Top