Write Ascii Characters

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Write Ascii Characters

Post by kpassaur » Tue Mar 31, 2009 11:45 am

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%

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Mar 31, 2009 12:37 pm

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%

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Convert to ASCII

Post by kpassaur » Tue Mar 31, 2009 12:46 pm

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

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Final Solution writing an ascii line to text file

Post by kpassaur » Tue Mar 31, 2009 1:09 pm

//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%

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Mar 31, 2009 4:40 pm

Keith,

I don't know but this might be useful. Did you ever see my ASCII chart script?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts