Bean Dip
Bean Dip

Reputation: 63

How can you make a MS-DOS program in VB 8.0?

Can you make a MS-DOS program with Mirosoft Visual Basic 2008 Express Edition? I wanted to make one that doesn't have windows that pop out of Command Prompt, DOSBOX, or whatever is being used. I tried to create a message box, but it won't be like in MS-DOS! I don't know much on VB, but I need to make things all stay on DOSBOX. Here is the template that won't stay in the CLI:

Imports System.Windows.Forms

    Public Class Dialog1

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As        System.EventArgs) Handles OK_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub Dialog1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

I would really appreciate it if I could get a template, or just some type of code.

Upvotes: 2

Views: 2929

Answers (5)

Abel
Abel

Reputation: 57189

I know this is an old question, and perhaps by this time the MS-DOS box the OP talks about is now in a museum, but if your language of choice is Visual Basic, then I suggest you try either PowerBasic (still available, commercial, can compile into 16 bit code) or QBasic (which is already available on your DOS box anyway.

In the case of PowerBasic, recent versions compile into 32 bit. But I'm sure you can ask them for an older version. The upside is that you can use a single code base for 16 bit and 32 bit. It's been a while that I used it, but if I remember correctly it could create dialog windows for the console view (i.e., not popping up as a message box, but within the MS-DOS console).

In the case of QBasic, it's a rather limited environment and it is interpreted, though its compiled commercial companion QuickBasic can now be freely downloaded from several sites. Also it seems that new versions exist that can compile into 32 bit and 64 bit, which means you can keep (kind of) the same code base.

I'm sure there are other options around, but these may be the simplest if you have some experience with Visual Basic already.

As an aside, as others have already pointed out, Windows Forms cannot be used or compiled into 16 bit MS-DOS.

Upvotes: 1

Sivodaya Tech
Sivodaya Tech

Reputation: 128

For this add three textboxes

1) txterror (get error from the command prompt or DOS)

2) txtresult (get result from the command prompt or DOS)

3) txtcommand (write DOS command to execute)

Write below code inside the form load

' Set start information.
    Dim start_info As New ProcessStartInfo("cmd")
    start_info.UseShellExecute = False
    start_info.CreateNoWindow = True
    start_info.RedirectStandardOutput = True
    start_info.RedirectStandardError = True
    start_info.RedirectStandardInput = True

    ' Make the process and set its start information.
    Dim proc As New Process()
    proc.StartInfo = start_info

    ' Start the process.
    proc.Start()

    ' Attach to stdout and stderr.
    Dim std_out As StreamReader = proc.StandardOutput()
    Dim SW As System.IO.StreamWriter = proc.StandardInput
    Dim std_err As StreamReader = proc.StandardError()
    SW.WriteLine(txtcommand.Text)
    SW.WriteLine("exit")
    ' Display the results.
    txtresult.Text = std_out.ReadToEnd()

    ' Clean up.
    std_out.Close()
    std_err.Close()
    proc.Close()

Write below code inside the textbox keydown event (ie txtcommand_KeyDown)

If e.KeyCode = Keys.Enter Then
        txterror.Text = ""
        ' Set start information.
        Dim start_info As New ProcessStartInfo("cmd")
        start_info.UseShellExecute = False
        start_info.CreateNoWindow = True
        start_info.RedirectStandardOutput = True
        start_info.RedirectStandardError = True
        start_info.RedirectStandardInput = True

        ' Make the process and set its start information.
        Dim proc As New Process()
        proc.StartInfo = start_info

        ' Start the process.
        proc.Start()

        ' Attach to stdout and stderr.
        Dim std_out As StreamReader = proc.StandardOutput
        Dim SW As System.IO.StreamWriter = proc.StandardInput
        Dim std_err As StreamReader = proc.StandardError()
        SW.WriteLine(txtcommand.Text)
        SW.WriteLine("exit")

        ' Display the results.
        txtresult.Text = std_out.ReadToEnd()
        txterror.Text = std_err.ReadToEnd()

        std_err.Dispose()
        SW.Close()
        ' Clean up.
        std_out.Close()
        std_err.Close()
        proc.Close()
    End If

Upvotes: -1

evilspoons
evilspoons

Reputation: 406

Do you mean a console window on a modern computer running Windows XP/Vista/7 (i.e. a black box with characters that looks like a DOS command prompt) or actual DOS i.e. a computer running MS-DOS 5.22 or something like that?

If you mean the former - a console window - all you have to do is create your project in Visual Basic as a console application. (Select immediately after you press New Project.) The first line in your code suggests it is a Windows Forms application, which is designed to create dialogues and windows and such.

Look on Google/Youtube for "visual basic console application" and you should be well on your way.

Upvotes: 1

Blindy
Blindy

Reputation: 67487

No Microsoft compiler made in the last 15 years (or more...) will target a 16-bit system (which is what DOS is). The last VB version that compiled for DOS was VB 1.0, but good luck finding that anymore.

You could look into DJGPP if you don't mind going down the C++ route. There's also Pascal and assembler compilers that can compile for DOS.

Feel free to rethink your path :)

Upvotes: 2

SLaks
SLaks

Reputation: 888177

You can make a VB.Net application that stay within a console window.

All you need to do is not call any functions (such as MessageBox) that don't stay within the console window.

Like all other .Net applications, it will require Windows and the correct version of the .Net Framework to run.

Upvotes: 1

Related Questions