Results 1 to 9 of 9

Thread: Help with porting VBScrip to VB

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    3

    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...



    VB Code:
    1. Dim swfDir
    2. Dim swfName
    3. 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"
    4. Set ObjFSO = CreateObject("UserAccounts.CommonDialog")
    5. ObjFSO.Filter = "SWF Files|*.swf"
    6. ObjFSO.FilterIndex = 1
    7. ObjFSO.InitialDir = ".\"
    8. InitFSO = ObjFSO.ShowOpen
    9. If InitFSO = False Then
    10.     Wscript.Echo "You didn't select a file!!!"
    11.     Wscript.Quit
    12. Else
    13.     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!"
    14.     FileNameArray=Split(ObjFSO.FileName,"\")
    15.     swfName = FileNameArray(UBound(FileNameArray))
    16. End If
    17. 'Search Function
    18. sCmd = "cmd /c dir c:" & swfName & "/s /b "
    19. Set shell = createobject("wscript.shell")
    20. Set d = CreateObject("Scripting.Dictionary")
    21. Set wsx = shell.exec(sCmd)
    22. Set wsxOut = wsx.stdout
    23. Do: wscript.sleep 10
    24.   Do until wsxOut.atendofstream
    25.     d(d.count) = wsxOut.readline
    26.   Loop
    27. Loop until wsx.status <> 0 And wsxOut.atendofstream
    28. For Each filepath in d.items()
    29.    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!!!"
    30.   swfDir = filepath
    31. Set swfExe = CreateObject("Scripting.FileSystemObject")
    32. If swfExe.FileExists(filepath & "BACKUP") Then
    33.  
    34.     Wscript.Echo "The updated SWF appears to already be installed!!!" & Chr(13) & Chr(10) &  Chr(13) & Chr(10) & "No files were modified!!!"
    35.     Wscript.Quit
    36. Else
    37. Set RenameObject = CreateObject("Scripting.FileSystemObject")
    38. RenameObject.MoveFile filepath , filepath & "BACKUP"
    39. msgbox"Your original file has been backed up...",0,"Important!"
    40. 'Copy Function
    41. Set FileObject = CreateObject("Scripting.FileSystemObject")
    42. FileObject.CopyFile ObjFSO.FileName, swfDir
    43. End If
    44. Next
    45. Set origExe = CreateObject("Scripting.FileSystemObject")
    46. If origExe.FileExists(swfDir) Then
    47. 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!"
    48. Else
    49. 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!"
    50. 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!

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    UK
    Posts
    417

    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.
    When your dreams come true.
    On error resume pulling hair out.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Help with porting VBScrip to VB

    Welcome to the forums.

    Step 1: Have you set a reference to the FSO and the Windows Scripting runtimes?

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  5. #5
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    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:
    1. Dim newSC As New ScriptControl 'Make a new ScriptControl
    2. 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.
    3. newSC.AddCode (Textbox.text) ' Add the code from the file to the SC
    4. 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

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    3

    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!

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  8. #8

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    3

    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...

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width