Avatar billede thesurfer Nybegynder
24. april 2009 - 21:10 Der er 5 kommentarer og
1 løsning

VBS fil, gem i ANSI format

Hej folkens.


Jeg har brug for at få en VBS fil til at gemme tekst i ANSI format.


Lige nu gemmer den filen i UTF-8, hvilet AWStats ikke accepterer.


Min kode ser sådan ud:

            Const ForWriting = 2

            Dim fso, file

            Set fso = CreateObject("scripting.filesystemobject")

            Set file = fso.CreateTextFile(strFilename, ForWriting, TRUE)
            file.write(template)
            file.close
            Set file  = Nothing

            Set fso = Nothing


Help! :-)
Avatar billede arne_v Ekspert
24. april 2009 - 21:54 #1
Hvor kommer template fra ?

Jeg gaetter paa at det er hvor det gaar galt !
Avatar billede thesurfer Nybegynder
25. april 2009 - 17:38 #2
template er en variabel der indeholder data (tekst) fra en fil, som skal bruges som skabelon.

template fyldes med data sådan her:

        Set file = fso.OpenTextFile(strConfigurationTemplate, ForReading)
        template = file.ReadAll
        file.close
        Set file  = Nothing

template indeholder nogle variabler som erstattes og senere hen skrives til en ny fil (dvs, ikke samme fil som før).


Du mener altså at kildefilen skal være gemt i ANSI, hvorefter dataene (teksten) så er i ANSI format (dvs, indeholder korrekt linebreaks), og vil derfor blive gemt i ANSI format?
Avatar billede thesurfer Nybegynder
25. april 2009 - 17:42 #3
Ovenstående konklusion kom jeg til, efter at have søgt på Google og fundet følgende:

"If you get some syntax errors and use a Unix like OS, check if your file is a Unix like text file (This means each line end with a LF char and not a CR+LF char)."

Jeg var en anden syntax fejl (husker ikke lige fejlen, men vil finde den frem) end denne:

---
http://awstats.sourceforge.net/docs/awstats_faq.html

FAQ-SET150 : INTERNAL ERROR 500 IN MY BROWSER
FAQ-SET200 : ERROR "... COULDN'T CREATE/SPAWN CHILD PROCESS..."
PROBLEM:
AWStats seems to run fine at the command prompt but when ran as a CGI from a browser, I get an "Internal Error 500".
I also also might have the following message in my Apache error log file (or in browser with Apache 2.0+):
...couldn't create/spawn child process: c:/mywebroot/cgi-bin/awstats.pl
SOLUTION:
First, try to run awstats.pl from command line to see if file is correct. If you get some syntax errors and use a Unix like OS, check if your file is a Unix like text file (This means each line end with a LF char and not a CR+LF char).
If awstats.pl file runs correctly from command line, this is probably because your web server is not able to known how to run perl scripts. This problem can occur with Apache web servers with no internal Perl interpreter (mod_perl not active). To solve this, you must tell Apache where is your external Perl interpreter.
For this, you have 2 solutions:
1) Add the following directive in your Apache httpd.conf config (or remove the # to uncomment it if line is already available)ScriptInterpreterSource registry

Then restart Apache. This will tell Apache to look into the registry to find the program associated to .pl extension.
2) Other solution (not necessary if first solution works): Change the first line of awstats.pl file with the full path of your Perl interpreter.
Example with Windows OS and ActivePerl Perl interpreter (installed in C:\Program Files\ActiveState\ActivePerl), you must change the first line of awstats.pl file with:#!c:/program files/activestate/activeperl/bin/perl

---
Avatar billede thesurfer Nybegynder
25. april 2009 - 18:30 #4
Jeg har lavet tests med følgende formater:

ANSI
Unicode
Unicode big endian
UTF-8

Den eneste der virkede var ANSI.

De andre 3 resulterede i denne fejl for hver eneste linie i filen:

Warning: Syntax error line LINIENUMMER in file 'FILEN'. Config line is ignored


Jeg har også prøve med LR og CRLF. Det ser ud til at være et ANSI/Unicode problem, og ikke LR/CRLF problem..



Hvordan gemmer jeg en fil i ANSI format?
Avatar billede thesurfer Nybegynder
25. april 2009 - 18:53 #5
En mulig løsning:

Convert unicode to ANSI (forumtråd):
http://www.mombu.com/microsoft/scripting-vb-script/t-convert-unicode-to-ansi-366676.html



Ellers skal jeg muligvis bruge ADODB.Stream hvor jeg kan sætte CharSet..


Stream Object Properties, Methods, and Events:
http://msdn.microsoft.com/en-us/library/ms677486.aspx

OBJECT:  Stream
http://www.devguru.com/technologies/ado/quickref/stream.html
Avatar billede thesurfer Nybegynder
25. april 2009 - 19:57 #6
Det blev til nedenstående kode.. jeg håber at det er OK at jeg snupper points..



' object.OpenTextFile  (filename [, iomode[    , create[, format]]])
' object.CreateTextFile (filename [, overwrite [, unicode        ]])

' iomode:
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

' create
Const CreateFalse = False
Const CreateTrue  = True

' format
Const OpenAsAscii  =  0 ' Opens the file as ASCII
Const OpenAsUnicode = -1 ' Opens the file as Unicode
Const OpenAsDefault = -2 'Use default system setting

' unicode
Const SaveAsAscii  = False
Const SaveAsUnicode = True

' overwrite
Const MayOverwriteFalse = False
Const MayOverwriteTrue  = True




Set file = fso.OpenTextFile(strConfigurationTemplate, ForReading)
template = file.ReadAll
file.close
Set file  = Nothing




Set file = fso.CreateTextFile(strFilename, MayOverwriteTrue, SaveAsAscii)
file.write(template)
file.close
Set file  = Nothing
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester



IT-JOB

Udviklings- og Forenklingsstyrelsen

Projektledere til nyetableret PMO-kontor

Cognizant Technology Solutions Denmark ApS

Test Architect - Projects

SporingsGruppen ApS

Frontend-udvikler