Macro to convert to ANSI

Help with writing and playing macros

Macro to convert to ANSI

Postby chris_g » Thu Nov 09, 2006 8:19 pm

I am trying to create a macro that converts files to ANSI/ASCII from UniCode. Unfortunately, sometimes the files are already in ANSI/ASCII format and the convert from Unicode to ASCII command ruins the file.

Is there a way to test the format of the file so I can decide what conversion to use? :?
User avatar
chris_g
Newbie
 
Posts: 2
Joined: Thu Nov 09, 2006 12:00 am

Re: Macro to convert to ANSI

Postby chris_g » Thu Nov 09, 2006 9:57 pm

I think I came up with something. 8) The unicode files I am trying to convert have the following 2 bytes in the header "ÿþ" or "FF FE". So I am looking for those bytes in hex mode and converting if they exist. But I am getting an error on my macro (see below). :cry:

InsertMode
ColumnModeOff
UnixReOff
HexOn
Find "FF FE"
IfFound
UnicodeToASCII
EndIf
Save
CloseFile
User avatar
chris_g
Newbie
 
Posts: 2
Joined: Thu Nov 09, 2006 12:00 am

Re: Macro to convert to ANSI

Postby Bego » Fri Nov 10, 2006 6:53 am

What is the error ?
If you have an unsaved "new file", save will just quit in an IO-error.
The makro "works" with previous saved files, either I can't say if unicode-transform works.
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: Macro to convert to ANSI

Postby Mofi » Fri Nov 10, 2006 3:27 pm

The conversion to ASCII should not be done in hex edit mode.

InsertMode
ColumnModeOff
HexOn
Top
Find "FF FE"
IfFound
HexOff
UnicodeToASCII
IfNameIs ""
SaveAs ""
Else
Save
EndIf
EndIf
CloseFile
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4042
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Macros