Is it possible to write Ascii Characters to a text file.
Some applications that I deal with read multipage text into a database and they need certain strings to be in the text. Such as Ascii 12 to identify a new page. The import tool reads the text to this field, imports it into a field in the database and then reads the text until the next code loads the page of text and continues.
I have read the help file on the command Ascii, but how to I do something like
Let>value=Ascii>12,14
Writeln>c:\temp\test.txt,result,%value%
Write Ascii Characters
Moderators: Dorian (MJT support), JRL
Here's one way.
Code: Select all
VBSTART
VBEND
//Set the ASCII chars to a variable
VBEval>CHR(12),ASC_Char_12
VBEval>CHR(14),ASC_Char_14
//Set the string to a variable leaving out the comma from the OP
Let>value=%ASC_Char_12%%ASC_Char_14%
//Turn off writing a carriage return+linefeed
Let>WLN_NOCRLF=1
//Write the string to a file
Writeln>c:\temp\test.txt,result,%value%
Convert to ASCII
Thanks JRL
Your way will be very easy for what I want to do. I was working with this and since it works I will post it.
VBSTART
Function StringToAscii(str)
Dim result, x
StringToAscii = ""
If Len(str)=0 Then Exit Function
If Len(str)=1 Then
result = Asc(Mid(str, 1, 1))
StringToAscii = Left("000", 3-Len(CStr(result))) & CStr(result)
Exit Function
End If
result = ""
For x=1 To Len(str)
result = result & StringToAscii(Mid(str, x, 1))
Next
StringToAscii = result
End Function
Function AsciiToString(str)
Dim result, x
AsciiToString = ""
If Len(str)AsciiToString("104101108108111032119111114108100"),newstring
MDL>newstring
VBEval>StringToAscii("%newstring%"),newstring
MDL>newstring
Your way will be very easy for what I want to do. I was working with this and since it works I will post it.
VBSTART
Function StringToAscii(str)
Dim result, x
StringToAscii = ""
If Len(str)=0 Then Exit Function
If Len(str)=1 Then
result = Asc(Mid(str, 1, 1))
StringToAscii = Left("000", 3-Len(CStr(result))) & CStr(result)
Exit Function
End If
result = ""
For x=1 To Len(str)
result = result & StringToAscii(Mid(str, x, 1))
Next
StringToAscii = result
End Function
Function AsciiToString(str)
Dim result, x
AsciiToString = ""
If Len(str)AsciiToString("104101108108111032119111114108100"),newstring
MDL>newstring
VBEval>StringToAscii("%newstring%"),newstring
MDL>newstring
Final Solution writing an ascii line to text file
//This will write Thank on one line and You on the next
// the string contains the ascii characters separated by a semi colon
VBstart
VBend
Let>str=
Let>string=84;104;97;110;107;13;10;89;111;117
Separate>string,;,sarray
If>sarray_count=0,End
let>c=0
Label>
Repeat>c
Let>c=c+1
Let>ai=sarray_%c%
Let>wv=chr(%ai%)
VBEval>%wv%,val
If>c=1
Let>str=%val%
Else
Let>str=%str%%val%
Endif
Until>c,sarray_count
Label>End
Writeln>c:\temp\test.txt,result,%str%
// the string contains the ascii characters separated by a semi colon
VBstart
VBend
Let>str=
Let>string=84;104;97;110;107;13;10;89;111;117
Separate>string,;,sarray
If>sarray_count=0,End
let>c=0
Label>
Repeat>c
Let>c=c+1
Let>ai=sarray_%c%
Let>wv=chr(%ai%)
VBEval>%wv%,val
If>c=1
Let>str=%val%
Else
Let>str=%str%%val%
Endif
Until>c,sarray_count
Label>End
Writeln>c:\temp\test.txt,result,%str%