Jump to content
Sign in to follow this  
torels

VBS conversion... Don't know why I always get a problem!

Recommended Posts

torels

Hi there

I have this part of VBS code:

Function CreateNewFile(sPathName)
im fso, fp  
Const ForWriting  = 2   
On Error Resume Next    
Set fso = CreateObject("Scripting.FileSystemObject")    
Set fp = fso.OpenTextFile( sPathName, ForWriting, True )                    
fp.Write Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, 0)          
fp.Close ''Chiude il file, altrimenti non si può usare.      
Set fso = Nothing   
End Function

and this is the autoit Part:

Func _NewFile($filename)
    Dim $fso, $fp
    Const $ForWriting = 2
        $fso = ObjCreate("Scripting.FileSystemObject")  
        $fp = $fso.OpenTextFile($filename, 2, True)  ;create file
        $string = Chr(80) & Chr(75) & Chr(5) & Chr(6) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0)
        $fp.Write($string) ;Write the file (header)
        $fp.close
EndFunc

but It's not working... the $string value is different from the Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, 0) in VBS

does seomebody know why ?

thanks in advance

:)

Edited by torels

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Share this post


Link to post
Share on other sites
torels

nobody ?

:)


Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Share this post


Link to post
Share on other sites
Airwolf

Try this:

Func _NewFile($filename)
    $fp = FileOpen($filename, 2)  ;open file and erase previous contents
    $string = Chr(80) & Chr(75) & Chr(5) & Chr(6) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0)
    FileWrite($fp, $string) ;Write the file (header)
    FileClose($fp)
EndFunc

If this doesn't accomplish what you are looking for, then please post the error you are receiving with your current method. I don't see any reason to continue using the VBS objects when you've already got built-in functions to replace them in AutoIt. :)

Edited by Airwolf

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt

Share this post


Link to post
Share on other sites
weaponx

The String function in VBS takes two parameters, the first one is count and the second is a literal character.

http://www.w3schools.com/VBscript/func_string.asp

You shouldn't be using Chr(0), only "0" or 0.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×