Click here to Skip to main content
15,901,505 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Window is slow to instantiate - only on some machines Pin
Christian Graus3-Apr-09 23:20
protectorChristian Graus3-Apr-09 23:20 
AnswerRe: Window is slow to instantiate - only on some machines Pin
Luc Pattyn3-Apr-09 14:51
sitebuilderLuc Pattyn3-Apr-09 14:51 
GeneralRe: Window is slow to instantiate - only on some machines Pin
dBrong3-Apr-09 15:15
dBrong3-Apr-09 15:15 
GeneralRe: Window is slow to instantiate - only on some machines Pin
Luc Pattyn3-Apr-09 15:49
sitebuilderLuc Pattyn3-Apr-09 15:49 
QuestionHex and Ascii issue converting back and forth from text and ascii Pin
Cory Kimble3-Apr-09 4:37
Cory Kimble3-Apr-09 4:37 
AnswerRe: Hex and Ascii issue converting back and forth from text and ascii Pin
Luc Pattyn3-Apr-09 5:05
sitebuilderLuc Pattyn3-Apr-09 5:05 
GeneralRe: Hex and Ascii issue converting back and forth from text and ascii Pin
Cory Kimble3-Apr-09 5:55
Cory Kimble3-Apr-09 5:55 
GeneralRe: Hex and Ascii issue converting back and forth from text and ascii Pin
Luc Pattyn3-Apr-09 6:48
sitebuilderLuc Pattyn3-Apr-09 6:48 
Hi,

AFAIK this is completely wrong.

1. it does not work at all for more than one character since Strings.Asc(string) only looks at the first character of the string.

2. the conversion for a single character does not work (well, it does convert, but in a nonsensical way)
The simple example where original text is "f", it is an ASCII character with numeric value 102 in decimal, which is 66 in hex.
Indeed the outcome of Strings.Asc(TextBox1.Text) is the number 102

ERROR1: you erroneously store that in the string variable named "hex" which now holds "102"

ERROR2: then you parse, i.e. decode, it as if it were a hex number, hence the result is the number 258 since 1*256+0*16+2*1 equals 258.

ERROR3: you again erroneously store that in the string variable named "hex" which now holds "258"
and finally you do a lot of moving around to get some zeroes and spaces

What you probably want is something along these lines:

Sub rfid2()
    Dim maxChars As Integer = 12
    Dim Text As String = "ABC123   f"
    Console.WriteLine("Encoding """ & Text & """ in " & maxChars & " hex chars")

    Dim length As Integer = Text.Length
    Dim result As String = ""
    Dim i As Integer

    For i = 1 To maxChars - length
        result = "00 " & result
    Next

    For i = 0 To length - 1
        Dim chr As Integer = Strings.Asc(text.Substring(i, 1))
        result = result & chr.ToString("X2") & " "
    Next
    Console.WriteLine("result=" + result)
End Sub


This generates "00 00 41 42 43 31 32 33 20 20 20 66 " where each of the characters is clearly visible in hex.


Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


GeneralRe: Hex and Ascii issue converting back and forth from text and ascii Pin
Cory Kimble3-Apr-09 9:33
Cory Kimble3-Apr-09 9:33 
GeneralRe: Hex and Ascii issue converting back and forth from text and ascii Pin
Luc Pattyn3-Apr-09 10:05
sitebuilderLuc Pattyn3-Apr-09 10:05 
GeneralRe: Hex and Ascii issue converting back and forth from text and ascii Pin
Cory Kimble3-Apr-09 10:55
Cory Kimble3-Apr-09 10:55 
QuestionSaveFileDialog with Serialport Pin
Quin Nee3-Apr-09 1:39
Quin Nee3-Apr-09 1:39 
AnswerRe: SaveFileDialog with Serialport Pin
Luc Pattyn3-Apr-09 3:27
sitebuilderLuc Pattyn3-Apr-09 3:27 
Questionproblem in overwriting the previous setup Pin
Pankaj Garg3-Apr-09 0:47
Pankaj Garg3-Apr-09 0:47 
AnswerRe: problem in overwriting the previous setup Pin
Tom Deketelaere3-Apr-09 1:47
professionalTom Deketelaere3-Apr-09 1:47 
QuestionCan only delete numbers in access database Pin
hendrikbez2-Apr-09 22:05
hendrikbez2-Apr-09 22:05 
AnswerRe: Can only delete numbers in access database Pin
Jay Royall2-Apr-09 22:20
Jay Royall2-Apr-09 22:20 
GeneralRe: Can only delete numbers in access database Pin
hendrikbez2-Apr-09 22:29
hendrikbez2-Apr-09 22:29 
GeneralRe: Can only delete numbers in access database Pin
Jay Royall2-Apr-09 22:47
Jay Royall2-Apr-09 22:47 
GeneralRe: Can only delete numbers in access database Pin
JC.KaNNaN3-Apr-09 20:57
JC.KaNNaN3-Apr-09 20:57 
AnswerRe: Can only delete numbers in access database Pin
Tom Deketelaere2-Apr-09 22:49
professionalTom Deketelaere2-Apr-09 22:49 
QuestionData transfer in SAP through VB Pin
yog21122-Apr-09 19:25
yog21122-Apr-09 19:25 
AnswerRe: Data transfer in SAP through VB Pin
Tom Deketelaere2-Apr-09 21:53
professionalTom Deketelaere2-Apr-09 21:53 
GeneralRe: Data transfer in SAP through VB Pin
Jon_Boy3-Apr-09 2:25
Jon_Boy3-Apr-09 2:25 
QuestionMultiple timers accessing single class Pin
Doug.Aliff2-Apr-09 16:10
Doug.Aliff2-Apr-09 16:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.