# Solved: Need/want to convert .VBS to VB .NET



## themusikid (Dec 12, 2008)

Hey guys... hopefully you can help me on this one... I was messing around with some vb scripts and found a useful "Run" script. I would very much like to be able to convert it to vb.net so I can edit it and make it look a little nicer. Can you help me? Here is the script I am looking to convert:

doRun()
Function doRun()
Set oShell = CreateObject("WScript.Shell")

Dim sString
sString = InputBox("Run:")

If sString = "" Then

Else
oShell.Run(sString)
doRun()
End If
End Function


----------



## snoopygb (Jun 29, 2010)

I believe you want to shell out to an application or such and if so then the following code would accomplish this.


Private Sub DoRun()
Dim cxProgramLocation As String
cxProgramLocation = InputBox("Run:", "application to run", String.Empty)

If Not cxProgramLocation.Equals(String.Empty) Then
Shell(cxProgramLocation)
End If
End Sub

if you also wanted this function to loop then just put the extra dorun in

Private Sub DoRun()
Dim cxProgramLocation As String
cxProgramLocation = InputBox("Run:", "application to run", String.Empty)

If Not cxProgramLocation.Equals(String.Empty) Then
Shell(cxProgramLocation)
DoRun()
End If
End Sub


you would probably want to put some error logic in to help incase the filename you type in is not correct.


----------



## themusikid (Dec 12, 2008)

snoopygb said:


> Private Sub DoRun()
> Dim cxProgramLocation As String
> cxProgramLocation = InputBox("Run:", "application to run", String.Empty)
> 
> ...


Thank you for the reply, but as I am new to visual basic 2008 express... I don't really know what to do after I paste the code you gave me into the form, because when I go to debug the script, the text box does not come up. I realize this probably makes me sound like a complete newb, but if you copy the code that I put up and save it as a .vbs, you get a little "Run" box. When I try to do this in VB 2008, nothing appears in the box. I am doing something wrong and probably obvious to you but I'm not really sure what. Any ideas?


----------



## snoopygb (Jun 29, 2010)

No worries.. Visual studio is a bit more than just a scripting language it creates applications (exe) these applications have many different functions if you want an application to just run the script below then you will need to either put a button on the form or add it to form_load.

Follow these steps and it should help


File/New Projet
Create a New windows application called Run Application
This should create a new form called form1.vb
Right mouse properties update the name field with a sensible name ie: uxMainform (ux stands for "user experience") - good practice and really helps when you have more than one form in your application.
Double click that form and this should take you to uxMainform_Load
the code for the form should look like this
Public Class uxMainform

Private Sub uxMainform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cxProgramLocation As String
cxProgramLocation = InputBox("Run:", "application to run", String.Empty)

If Not cxProgramLocation.Equals(String.Empty) Then
Shell(cxProgramLocation)
End If
End Sub
End Class

if you want to have this run once and then shut the application down then put Me.Close() just before the End Sub

when you run the form this should automatically put up an input box. Hope this explains a little more and answers your question if not let me know and I will try and explain futher


----------



## themusikid (Dec 12, 2008)

snoopygb said:


> When you run the form, an input box should automatically come up. Hope this explains a little more and answers your question. If not, let me know and I will try to explain further.


Thank you again for the reply, but while this does bring up the "Run" box just like the .vbs file, the only reason I am doing all of this is so I can edit the actual graphical interface _of_ the "Run" box. Such as adding an icon or a picture or editing the thumbnail or other things, I don't just want to be able to run the "Run" box, but to change it as well. I have attached three screen shots of what I am talking about, the Code page, the Design page, and the "Run" box application. I want to be able to change the "Run" box from within the design page. Is this possible? Forgive my ignorance on this subject. I know the very simple basics of BASIC.


----------



## DoubleHelix (Dec 10, 2004)

You're going to have to learn a lot more about Visual Studio .NET if you want to create a program with multiple custom forms. If all you need is a simple input box, stick to scripting languages.


----------



## snoopygb (Jun 29, 2010)

This looks like you don't want to just create a run script but an application. Start with a blank form put a text box on it and a button from the toolbox if you double click the button it will take you to the code editor then in Button1_click paste the following code

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not TextBox1.Equals(String.Empty) Then
Shell(TextBox1.Text)
End If
End Sub 

then you can do what you like on the form. 

If this is your first venture into visual basic then can i suggest you have a quick search online if you search for something like visual basic tutorial microsoft also do some good free online training tutorials this is the best way to start off so that you understand what you are doing. Visual Studio is a massive language and you really need to understand the basics.


----------



## themusikid (Dec 12, 2008)

DoubleHelix said:


> stick to scripting languages.


 Thanks guys... I completely got everything figured out (BTW... only needed ONE form). Yes I did want an application, I knew that from the start, sorry I didn't make that a little clearer. What I did was a process.start(txtRun) with an error trap that led to shell(txtRun) and got it perfectly. Then I made the window and all of the buttons (OK, Cancel, Browse) looking nice and working perfectly. I now have an exact clone of the Windows "Run". Thanks guys (especially you DoubleHelix, your words of wisdom are inspiring). No but really snoopy you are awesome. I understood most of what I was doing throughout my little project though. I can pick things up fairly quickly, I'm a fifteen year-old, I know everything remember? Don't think that means I won't ask you first when I need help though.


----------

