Help with porting VBScrip to VB
Hi fella's!
I'm having a really hard time porting a VBScript I put together to VisualBasic...
The Script/Program will run from a directory on a CD, in the same directory there will be an updated SWF file to an existing
program I have created in Flash... I need the VB program to be generic, thats why all the variables are present...
This is a rundown of the operation...
Open file located in the same directory as AutoUpdater, store filename as a variable named swfName...
swfExist = swfName
Search local HDD's for swfExist...
If existing swfExist does not exist, End with Message "Original file not installed!", Quit...
If existing swfExist Exists, store absoulte path of swfExist in variable swfPath...
rename swfPath/swfExist.swf to swfPath/swfExist.bak...
copy swfName to swfPath...
End Program
The VBScript works pretty damn well, but now I want to convert it into an Exe and add a form page to make it all look nice...
http://www.thekryopit.karoo.net/img/form.jpg
VB Code:
Dim swfDir
Dim swfName
msgbox" This program will automatically update vital program files." & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "At the next screen, please select the Updated SWF file!",0,"SWF Updater"
Set ObjFSO = CreateObject("UserAccounts.CommonDialog")
ObjFSO.Filter = "SWF Files|*.swf"
ObjFSO.FilterIndex = 1
ObjFSO.InitialDir = ".\"
InitFSO = ObjFSO.ShowOpen
If InitFSO = False Then
Wscript.Echo "You didn't select a file!!!"
Wscript.Quit
Else
msgbox"We will now begin a search for the original file..." & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "This may take a few moments... Please Wait!" & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "If you recieve a McAfee warning, Select..." & Chr(13) & Chr(10) & "'Allow entire script this time'" & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "...To continue with the program!",0,"Ready To Search!"
FileNameArray=Split(ObjFSO.FileName,"\")
swfName = FileNameArray(UBound(FileNameArray))
End If
'Search Function
sCmd = "cmd /c dir c:" & swfName & "/s /b "
Set shell = createobject("wscript.shell")
Set d = CreateObject("Scripting.Dictionary")
Set wsx = shell.exec(sCmd)
Set wsxOut = wsx.stdout
Do: wscript.sleep 10
Do until wsxOut.atendofstream
d(d.count) = wsxOut.readline
Loop
Loop until wsx.status <> 0 And wsxOut.atendofstream
For Each filepath in d.items()
msgbox"swffile found in: " & Chr(13) & Chr(10) & Chr(13) & Chr(10) & filepath & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "We will now apply the Updated SWF!!!",0,"File Found!!!"
swfDir = filepath
Set swfExe = CreateObject("Scripting.FileSystemObject")
If swfExe.FileExists(filepath & "BACKUP") Then
Wscript.Echo "The updated SWF appears to already be installed!!!" & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "No files were modified!!!"
Wscript.Quit
Else
Set RenameObject = CreateObject("Scripting.FileSystemObject")
RenameObject.MoveFile filepath , filepath & "BACKUP"
msgbox"Your original file has been backed up...",0,"Important!"
'Copy Function
Set FileObject = CreateObject("Scripting.FileSystemObject")
FileObject.CopyFile ObjFSO.FileName, swfDir
End If
Next
Set origExe = CreateObject("Scripting.FileSystemObject")
If origExe.FileExists(swfDir) Then
msgbox"All Done!!! " & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "You can now play the swf without the CD in the drawer!!!" & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "
[email protected]",0,"All Done!"
Else
msgbox"You don't appear to have Kryopit installed!" & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "Please install Kryopit and then run this program again!!!",0,"File Error!"
End If
Could someone with a bit of time on their hands port this over for me? I'm such a n00b it's unbelievable!
Thanks guys!
Re: Help with porting VBScrip to VB
if I get any spare time I may have a look for you. tho is it really that inportant to just convert it all. if all you want is a nise GUI for it. ?
I mean you chould easy write this as a hta file. HTML Application were you chould click on the file and then have it open a nise graphic little form. using HTML. should be fairy easy.
well just an idea.
Re: Help with porting VBScrip to VB
Welcome to the forums. :wave:
Step 1: Have you set a reference to the FSO and the Windows Scripting runtimes?
Re: Help with porting VBScrip to VB
Hack - no references are needed if he is using CreateObject()...
Kryo - can you explain step by step what your script does? I started converting it to VB, but it is very clumsy - if you explain how it works then we can help you write a much neater version from scratch.
Re: Help with porting VBScrip to VB
Hi
One easy way you can run the code is to create a textbox on a form and use the following code to run the VBScript. Firstly you need to add the "Microsoft Script Control 1.0" component. This was originally used to read of a file the code and run it but it should work from a textbox. Actual page
VB Code:
Dim newSC As New ScriptControl 'Make a new ScriptControl
newSC.Language = "VBScript" ' Set the SC language to Visual Basic. Note that other languages such as JScript are also valid - check the help file associated with this command.
newSC.AddCode (Textbox.text) ' Add the code from the file to the SC
newSC.ExecuteStatement ("Code") 'Run the code. Note it runs the statement "TestWindow" which is the name of the sub in the text file!
Code thanks to friendsofwatto
Re: Help with porting VBScrip to VB
Quote:
Originally Posted by penagate
Hack - no references are needed if he is using CreateObject()...
Kryo - can you explain step by step what your script does? I started converting it to VB, but it is very clumsy - if you explain how it works then we can help you write a much neater version from scratch.
Thanks man!
Well, basically, the VB.vbs file is stored in a folder on a CD with a frequently updated SWF file...
The script opens and the Open dialog is displayed...
User selects the SWF file...
The SWF filename is stored in a variable with the path removed...
It then goes on to search for the filename on C: drive (All HDD's would be nice...)
If the file is found, the script stores the absoulte path in a variable then renames the file to whatever.bak, and then copies the new file from the cd to the path in the variable...
It has a few message boxes here and there also, but they are annoying...
What I would like is something like the image in my last post, with the top text box echo'ing the opened file, and the bottom one to display "Searching..." whilst it is looking for the file, then to echo the absolute path...
After that the user clicks on the Update File button and it to then rename the file and copy the new file to that directory...
I'm not sure if thats any clearer than before?! I'm crap at trying to explain myself :S
As I said, I'm a complete n00b at programming, the best I can handle is Flash Actionscript... So if you could add comments to the script, so I can actually see if I can get my foot in the door with VB... I would be more than greatful!
Re: Help with porting VBScrip to VB
Are you using VB6 or VB.NET? The icon of the form in the image you posted looks suspiciously like the .NET icon.
Re: Help with porting VBScrip to VB
It's VB 2005 Express Edition... In the 'About Page' it mentions .Net... if that helps...
It was pre-installed on my box when I bought it, so I don't have much info on it...
Re: Help with porting VBScrip to VB
Quote:
Originally Posted by Kryo
It's VB 2005 Express Edition... In the 'About Page' it mentions .Net... if that helps...
It was pre-installed on my box when I bought it, so I don't have much info on it...
Then, you aren't using VB, you are using VB.NET and there is one galaxy of difference. Moved to Visual Basic .NET