Now number to ascii string

F

Freddy Coal

How convert a number for the string equivalent?

For example:

I have the number "16448", I would like take this number in a two bytes
strings, the number represent the "@@".

Thanks in advance.

Freddy Coal
 
Z

zacks

How convert a number for the string equivalent?

For example:

I have the number "16448", I would like take this number in a two bytes
strings, the number represent the "@@".

Thanks in advance.

Freddy Coal

Your example is very cryptic. But the common way to convert a
numerical variable to the string equivalent is with the .ToString
method.
 
F

Freddy Coal

No Zacks, the .tostring return me the number, and I need the chars
equivalent for that number.

Again an example:

Dim Traza_dat As Int16 = 16448
 
T

Tom Shelton

How convert a number for the string equivalent?

For example:

I have the number "16448", I would like take this number in a two bytes
strings, the number represent the "@@".

Thanks in advance.

Freddy Coal

dim i as integer = 16448
dim firstchar as integer = i >> 8
dim secondchar as integer = i and &H00ff

console.writeline (convert.tochar(firstchar))
console.writeline(convert.tochar(secondchar))

Anyway, something like that. you might have to look up the exact vb
syntax (to much c# on the brain :).
 
F

Freddy Coal

Thanks Tom, this is I need, but you know a function in VB.Net, for make this
in one step?.

Freddy Coal
 
M

Martin H.

Hello Freddy,
How convert a number for the string equivalent?

For example:

I have the number "16448", I would like take this number in a two bytes
strings, the number represent the "@@".

Do I understand you correctly that you want it as hex? Then you can use
the following function. Please check for line breaks:

Private Function NumberToHexStrings(ByVal ThisNumber As Long, ByVal
StringLength As Byte) As String()
Dim retVal() As String

If StringLength = 0 Then
ReDim retval(-1)
Else
Dim ArrSize As Integer, t As Integer
Dim tNumber As String = Hex(ThisNumber)

While tNumber.Length Mod StringLength <> 0
tNumber = "0" & tNumber
End While

ArrSize = Fix((CDec(tNumber.Length) / CDec(StringLength)) + 0.5) - 1
ReDim retVal(ArrSize)

t = ArrSize

While t > -1
retVal(t) = Strings.Right(tNumber, StringLength)
tNumber = Strings.Left(tNumber, tNumber.Length - StringLength)
t = t - 1
End While

End If

Return retVal
End Function


Use it like this:

Dim s() As String
s = NumberToHexStrings(16448, 2)


Best regards,

Martin
 
T

Tom Shelton

Thanks Tom, this is I need, but you know a function in VB.Net, for make this
in one step?.

Freddy Coal








- Show quoted text -

Not built in. You'll need to put what i did into it's own function :)
 
F

Freddy Coal

Martin, Thanks for your answer, you know how convert a string to the hex
value?.

I have a string with "FFFEC3D1", I would like obtain the number in hex, how
define that variable?.

I try with system.convert.ToInt32, but I get an unhandled exception, "Input
string was not in a correct format"

My best regards.

Freddy Coal
 
M

Mattias Sjögren

I try with system.convert.ToInt32, but I get an unhandled exception, "Input
string was not in a correct format"

Which overload did you call? Make sure you call ToInt32(String,
Integer) and specify base 16 as the second argument.


Mattias
 
M

Martin H.

Hello Freddy,
I have a string with "FFFEC3D1", I would like obtain the number in hex, how
define that variable?.

To convert a hex string into numeric formats, you need to add the hex
header "&H". If you string is "&HFFFEC3D1" it will work.

Best regards,

Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top