Okay, so I just got Visual Basic, but I don't really know how to use it yet. I know just a few things here and there. I want to start out with just some basic things. I tried making the quadratic function, but I don't know how to assign a variable when I use the program. I'm also not too sure about how to enter the operations of the quadratic function either.

Dani AI

Generated

A short, practical guide for that builds on the helpful tips from and : the key steps are (1) get the numbers the user types (usually from TextBoxes), (2) convert those strings to numeric variables, (3) do the arithmetic (watch operator order), and (4) show the results. Below is a minimal Windows Forms example (VB.NET) you can paste into a form with TextBoxes named txtA, txtB, txtC, a Button btnSolve and a Label lblResult. It demonstrates safe parsing, handling a = 0, and negative discriminant.

' Put this in a Form with TextBoxes: txtA, txtB, txtC
' Button: btnSolve
' Label: lblResult

Private Sub btnSolve_Click(sender As Object, e As EventArgs) Handles btnSolve.Click
    Dim a As Double, b As Double, c As Double
    If Not Double.TryParse(txtA.Text, a) OrElse Not Double.TryParse(txtB.Text, b) OrElse Not Double.TryParse(txtC.Text, c) Then
        lblResult.Text = "Please enter numeric values for a, b and c."
        Return
    End If

    If Math.Abs(a) < 1E-12 Then
        If Math.Abs(b) < 1E-12 Then
            lblResult.Text = If(Math.Abs(c) < 1E-12, "Infinite solutions.", "No solution.")
        Else
            lblResult.Text = "Linear solution: x = " & (-c / b).ToString("G6")
        End If
        Return
    End If

    Dim disc As Double = b * b - 4 * a * c
    If disc < 0 Then
        lblResult.Text = "No real roots (discriminant < 0)."
        Return
    End If

    Dim s As Double = Math.Sqrt(disc)
    Dim x1 As Double = (-b + s) / (2 * a)
    Dim x2 As Double = (-b - s) / (2 * a)
    lblResult.Text = String.Format("Roots: {0:G6} and {1:G6}", x1, x2)
End Sub

Troubleshooting tips: use Double.TryParse to avoid exceptions, step through the code with the debugger to watch variable values, and test with known examples (for example a=1, b=-3, c=2 should give x=1 and x=2). If you are on much older VB (VB6), parsing and event hookup differ: use conversion functions and simple error handling instead. Experiment with the example above and tweak it — that is the fastest way to learn how variable assignment and operations work in practice.

Recommended Answers

All 5 Replies

Hello buddy

According to me VB is the most easiest programming language u'll find. For startin try referring some book or better the MSDN library. Its just untill u get the hang of it, then u'll start to make various peograms quite easily.
remember my fren experimentation is the need of programming.

Cheers

What is the MSDN library?

MSDN is on microsoft site, its like a big code referance.

By the way, if you got the VB Express I mentioned off of microsoft site, please post it in the VB.NET forum. The 4/5/6 one were in now is for older, non-free versions.

to define a variable use DIM <vaariable> as <type>. I have included a simple app to show off how this function is used. Unzip it first.

Give me your Email adress btw and ill send you an ebook about VB. Its for the older 2003 version but most of the code should work (just ignore the stuff it tells you about a: the programming environment itself and b: making websites

commented: Thanks for your help. +1

Oh, thanks. I didn't know I had a different version than this forum. I'll send you my e-mail.

Sent it. Dont know if it will help.

If you want a good tutorial i believe there are some on Microsoft Site. Google visual Basic Express and click "Learn". There are many tutorials.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.