0

Currently working with this string that has embedded ASCII control charters.

[)><RS>06<GS>17V0B100<GS>1PRID-001-A1<GS>S99999<RS><EOT>

Below filters out the record separators correctly

i = InputBox("Test") 'i = [)><RS>06<GS>17V0B100<GS>1PRID-001-A1<GS>S99999<RS><EOT>
i = Split(i, Chr(30)) 
'i(1) = 0617V0B1001PRID-001-A1S99999

But group separators do not. Why does the below not split?

i = InputBox("Test") 'i = [)><RS>06<GS>17V0B100<GS>1PRID-001-A1<GS>S99999<RS><EOT>
i = Split(i, Chr(29)) 
'i(0) = [)>0617V0B1001PRID-001-A1S99999
Quint
  • 530
  • 2
  • 8
  • 23

2 Answers2

0

Ignoring the inputbox, this works fine:

Dim s As String, arr

s = "[)><RS>06<GS>17V0B100<GS>1PRID-001-A1<GS>S99999<RS><EOT>"

s = Replace(s, "<RS>", Chr(30))
s = Replace(s, "<GS>", Chr(29))

Debug.Print s                         '[)>0617V0B1001PRID-001-A1S99999<EOT>

Debug.Print Split(s, Chr(30))(1)      '0617V0B1001PRID-001-A1S99999

Debug.Print Split(s, Chr(29))(0)      '[)>06
Debug.Print Split(s, Chr(29))(1)      '17V0B100
Tim Williams
  • 154,628
  • 8
  • 97
  • 125
  • While inputting the above string with embedded control characters into a textbox, inputbox, ect. I am unable to split it using chr(29) as the delimiter but chr(30) works fine. Chr(29) seems to be getting filtered out. – Quint Feb 13 '20 at 07:01
  • Related maybe: https://stackoverflow.com/questions/48296955/ascii-control-character-html-input-text and https://social.msdn.microsoft.com/Forums/windows/en-US/2d255ecc-9d6c-4df1-8e66-83c01c5802c9/ascii-control-characters-in-a-textbox?forum=winforms – Tim Williams Feb 13 '20 at 07:09
  • this is super helpful thank you. Its strange to me that character 29 and 30 don't print the same. – Quint Feb 13 '20 at 07:21
0

Thanks to Tim for leading me to the correct answer. Below worked for converting key events to text.

Private Sub Text0_KeyPress(KeyAscii As Integer)
Dim i As Integer
i = Me.Text0.SelStart
Select Case KeyAscii
    Case 4
        Me.Text0.Text = Me.Text0.Text + "<EOT>"
        Me.Text0.SelStart = i + 5
    Case 29
        Me.Text0.Text = Me.Text0.Text + "<GS>"
        Me.Text0.SelStart = i + 4
    Case 30
        Me.Text0.Text = Me.Text0.Text + "<RS>"
        Me.Text0.SelStart = i + 4
End Select
End Sub
Quint
  • 530
  • 2
  • 8
  • 23