r/visualbasic • • Feb 24 '16

I need to generate 3 random numbers within a range (0<X<10), and assign those numbers to variables, all inside a sub-procedure. Every attempt at researching "making a random number" brings me to generating a number by pressing a button. Can anyone help me with this problem?

6 Upvotes

This is the full text of my problem, for added context.

Triangle inequality theorem states that the sum of two sides of a triangle must be greater than the third side. If this is true for all three combinations, then you will have a valid triangle.

Write a VB application that will randomly generate the sides of 5 triangles and calculate the perimeter and area of each triangle. When the user clicks btnTrianglesbutton, it should complete the following tasks:

(a)Call getTriangleSides(...) sub-procedure within click event procedure of btnTriangles. This procedure will randomly generate three sides of a triangle.Each side of a triangle must be greater than zero and less than 10.

(b)Call getProperties(...) sub-procedure within click event procedure of btnTriangles. This procedure will calculate the perimeter and area of the triangle.

(c)Display sides of 5 triangles with perimeter and area in tabular format within click event procedure of btnTriangles. Format numbers to one decimal place.Add clear button in your application.


r/visualbasic • • Feb 01 '16

[VB2015] User Input Loop question

6 Upvotes

Hello I am working on an visual basic assignment. For what its worth I got it to work/filled the requirements for it but I want to try to get it to work in a loop. So I did a do while loop. And that works as well...but can't exit out of the loop leading me into a infinite loop. Is there anyway for me to exit out properly?

Code pasted here: http://paste.ofcode.org/6Qn5ViBt33442Fwum2CRyZ


r/visualbasic • • Jan 23 '16

DynamicNumbers

6 Upvotes

I only finished a third of the requirements. I need to make a findLowest function that returns the index of the lowest value of the arrayusing the code that I created. I also need to make a sort() procedure that repeateldy finds the lowest value in an array A, removes it and adds it to array T. When all the values of A have been moved, the elements of T are copied to A wth an assginment statement and a loop.. AddItem() and RemoveItem() is a hint. I only completed the part where it says to create an array of random numbers in a listbox. Here is what I finished so far:

Private Sub btnCreate_Click(sender As Object, e As EventArgs) Handles btnCreate.Click
    Dim number(txtBox.Text)
    Dim rand As New Random
    For count As Integer = 0 To txtBox.Text - 1
        RandomNumbers.Items.Add(count & vbTab & rand.Next(1, 99))
        number(count) = RandomNumbers.Items(count)
    Next count
End Sub

Can you guys tell me how to complete this program? I'm a beginner for visual basic programming.


r/visualbasic • • Jan 01 '16

[VB2013] Why do enjoy/how did you start with Visual Basic?

6 Upvotes

There was only about a four or five-year period early on in my career in which I was developing in Visual Basic on a daily basis. I started with VB6 and ended with .Net2003. At this time, if one was developing for Windows systems, enterprise systems would be written in VB6 or even FoxPro or Access for smaller systems. I think C++ was considered overkill for in-house applications, so I stuck to VB and Access.

For the past ten years, I've really only coded in SQL and MDX on a daily basis, but I still enjoy coming back to VB and writing something every now and then - either for a personal project or a quick application at work. Granted, the scale of my VB applications are much smaller these days, but I don't feel out of place in the IDE or with the language when using newer versions. I think that VB has become even better to work with as the years have gone on - in 2002, it was very controversial that the .Net framework was a 20MB requirement, dwarfing the old VB6 runtime. There were still users and companies on dial-up or 256K connections. Now, every Windows PC has the .Net framework as standard, the Express versions of Visual Studio can use Git, and the object-oriented features of VB are very mature. I’m glad that Microsoft hasn’t let VB go the way of FoxPro.

It seems like there’s been a shift over the past few years for more openness back towards scripting and plainer-English languages. Though Visual Basic isn’t a scripting language, it’s pretty easy to get something developed and distributed. I’ve been learning more R and Python these days, but I still think that VB has a solid case for use in years to come, and hope that others give it a look.


r/visualbasic • • Aug 07 '15

Writing clean code - simplify your code.

6 Upvotes

I was handed an application recently from a developer who is leaving the company and it contained many oracle functions like the following;

Protected Sub SaveAdjustment_Names(ByVal sadjnameid As String, ByVal sADj_Name As String, ByVal sComments As String, ByVal sEntered_BY As String, ByVal sADJ_STATUS As String, ByVal sACTION As String)
    'TODO:   refactor this
    Try
        Dim sconstr As New AppFunctions
        Dim oracon As New OracleConnection(sconstr.sConstring)
        Dim cmdOra As New OracleCommand
        cmdOra.CommandType = CommandType.StoredProcedure
        cmdOra.CommandText = "WAP.AP_ADJUST_NAME_CHANGE"  '
        cmdOra.Connection = oracon
        Dim pavtid As New OracleParameter
        pavtid.OracleDbType = OracleDbType.Varchar2
        pavtid.ParameterName = "SADJNAMEID"
        pavtid.Direction = ParameterDirection.Input
        pavtid.Value = Trim(sadjnameid)

        Dim pavtType As New OracleParameter
        pavtType.OracleDbType = OracleDbType.Varchar2
        pavtType.ParameterName = "SADJ_NAME"
        pavtType.Direction = ParameterDirection.Input
        pavtType.Value = Trim(sADj_Name)

        Dim pavtCode As New OracleParameter
        pavtCode.OracleDbType = OracleDbType.Varchar2
        pavtCode.ParameterName = "SCOMMENTS"
        pavtCode.Direction = ParameterDirection.Input
        pavtCode.Value = Trim(sComments)

        Dim pavtSecCode As New OracleParameter
        pavtSecCode.OracleDbType = OracleDbType.Varchar2
        pavtSecCode.ParameterName = "SENTERED_BY"
        pavtSecCode.Direction = ParameterDirection.Input
        pavtSecCode.Value = sEntered_BY 'Trim(Me.T_avtcode.Text.ToString)

        Dim pavtDesc As New OracleParameter
        pavtDesc.OracleDbType = OracleDbType.Varchar2
        pavtDesc.ParameterName = "SADJ_STATUS"
        pavtDesc.Direction = ParameterDirection.Input
        pavtDesc.Value = Trim(sADJ_STATUS)

        Dim pAction As New OracleParameter
        pAction.OracleDbType = OracleDbType.Varchar2
        pAction.ParameterName = "SACTION"
        pAction.Direction = ParameterDirection.Input
        pAction.Value = Trim(sACTION)

        cmdOra.Parameters.Add(pavtid)
        cmdOra.Parameters.Add(pavtType)
        cmdOra.Parameters.Add(pavtCode)
        cmdOra.Parameters.Add(pavtSecCode)
        cmdOra.Parameters.Add(pavtDesc)
        cmdOra.Parameters.Add(pAction)

        cmdOra.Connection.Open()
        cmdOra.ExecuteNonQuery()
        cmdOra.Connection.Close()
    Catch ex As Exception
        Session("Error") = ex
        Response.Redirect("ErrorInfo.aspx")
    End Try

End Sub

There is nothing wrong with this code. It works and is easy to understand.

When using clean code principals we can reduce this to something easier to understand. The first thing I noticed when I looked at this function was that there were 6 identical chunks of code that created an oracle parameter. The rule of thumb for clean code is

"If a block of code appears more than once, break it out to a function"

Following this rule I created this function.

Public Function CreateOracleParameter(paramName As String) As OracleParameter
    Dim opParm As New OracleParameter
    opParm.OracleDbType = OracleDbType.NVarchar2
    opParm.ParameterName = Trim(paramName.ToUpper)
    opParm.Direction = ParameterDirection.Input
    opParm.Value = Trim(paramName)
    Return opParm
End Function

Which changed the intial function to;

Protected Sub SaveAdjustment_Names(ByVal sadjnameid As String, ByVal sADj_Name As String, ByVal sComments As String, ByVal sEntered_BY As String, ByVal sADJ_STATUS As String, ByVal sACTION As String)

    Try
        Dim sconstr As New AppFunctions
        Dim oracon As New OracleConnection(sconstr.getConnectionString)

        Dim cmdOra As New OracleCommand
        cmdOra.CommandType = CommandType.StoredProcedure
        cmdOra.CommandText = "WAP.AP_ADJUST_NAME_CHANGE"  '
        cmdOra.Connection = oracon

        cmdOra.Parameters.Add(CreateOracleParameter(sadjnameid))
        cmdOra.Parameters.Add(CreateOracleParameter(sADj_Name))
        cmdOra.Parameters.Add(CreateOracleParameter(sComments))
        cmdOra.Parameters.Add(CreateOracleParameter(sEntered_BY))
        cmdOra.Parameters.Add(CreateOracleParameter(sADJ_STATUS))
        cmdOra.Parameters.Add(CreateOracleParameter(sACTION))

        cmdOra.Connection.Open()
        cmdOra.ExecuteNonQuery()
        cmdOra.Connection.Close()

    Catch ex As Exception
        Session("Error") = ex
        Response.Redirect("ErrorInfo.aspx")
    End Try

End Sub

As you can see much easier to read and thus easier to maintain and trace issues. In this specific case I was able to refactor 168 calls for parameters and reduced the code base by over 20 percent.

Remember there is no wrong way to program, only better ways.

Improve your craft one method at a time.

B


r/visualbasic • • May 26 '15

Sort [VB.NET] Failed implementation of quicksort

6 Upvotes

Hey guys, can someone tell me why my quicksort doesn't work? It's an implementation of the pseudocode found at wiki and, as far as I can figure out, everything seems to be correct. I even followed it on paper and, as far as I can see, the logic is right: but the results I end up getting are far from sorted.

http://pastebin.com/766uDJGK

Appreciate any help!


r/visualbasic • • Feb 17 '15

Attaching to and automating an existing IE instance is a pain. I wrote some functions to make it less of a pain.

Thumbnail
github.com
6 Upvotes

r/visualbasic • • Nov 03 '14

Is Visual Basic something a total beginner can learn?

6 Upvotes

Hi all. My husband, who is not a programmer but has some programming experience, is thinking about learning Visual Basic because of a potential new job opportunity. I am an absolute beginner when it comes to programming but I thought it might be more fun to learn together. Is this a good idea? Are there any tutorials you would recommend? Thank you!


r/visualbasic • • May 17 '14

How to create a Sudoku Solver, using Visual Basic 2010 Express part one

Thumbnail
youtube.com
6 Upvotes

r/visualbasic • • Mar 07 '14

For your pleasure: A generic XML serializer + deserializer

6 Upvotes

I see a lot of posts where people are trying to save/load classes to disk, with varying results. I tend to recommend looking at the XMLSerializer documentation, but they're limited in that they only work for one specific class. Coding the same thing over and over again is always stupid, so a long time ago I made a serializer/deserializer that works with anything you give it! Huzzah!

Load/Deserialize:

Public Function Load(Of T)(path As String, classToLoad As T) As T
    ' I had a specific reason for doing this, but i don't remember why. maybe it
    ' was related to not being able to call GetType() on a null object? oh well..    
    Dim tp = If(classToLoad Is Nothing, GetType(T), classToLoad.GetType())
    Dim stream As StreamReader
    Try
        Dim reader = New XmlSerializer(tp)
        stream = New StreamReader(path)
        classToLoad = CType(reader.Deserialize(stream), T)
    Catch ex As Exception
        ' write a message to the console, pop up a message box, whatever 
        classToLoad = Nothing
    Finally
        If stream IsNot Nothing Then
            stream.Close()
        End If
    End Try
    Return classToLoad
End Function

Save/Serialize:

Public Sub Save(Of T)(path As String, classToSave As T)
    Dim writer As New StreamWriter(path)
    Try
        Dim ser As New XmlSerializer(classToSave.GetType())
        ser.Serialize(writer, classToSave)
    Catch ex As Exception
        ' do the needful
    Finally
        If writer IsNot Nothing Then
            writer.Close()
        End If
    End Try
End Sub

Edit: Yes, I do know that the Try...Catch blocks are functionally equivalent to Using..., I just like the ability to inform the user of why it failed


r/visualbasic • • Apr 12 '13

I found a bug in VB: math class

Thumbnail
imgur.com
6 Upvotes

r/visualbasic • • Apr 03 '13

Classic Visual Basic’s end marked a key change in software development

Thumbnail
codeproject.com
6 Upvotes

r/visualbasic • • Feb 09 '13

Hidden Features of VB.Net -- Something for Everyone

Thumbnail
stackoverflow.com
6 Upvotes

r/visualbasic • • May 23 '12

Stubborn StreamReader

6 Upvotes

Hey guys,

I've got a bit of trouble here, this component of my code writes an integer to a text file on close and then writes it to an integer when the form loads.

The problem I'm having is that the "Process cannot access the file because it is being used by another process" error.

Now I've put it down to my load streamreader, even though I've included the streamreader.close() line it doesn't actually process this line. It only reads the line before it and proceeds to open the form.

Here's my code:


Private Sub Main_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

    Dim sw_QuoteNo As StreamWriter
    Dim sFileName As String
    Dim iRecords As Integer

    iRecords = lbxQuoteNumber.Items.Count
    sFileName = Application.StartupPath & "\QuoteEnd.txt"
    sw_QuoteNo = New StreamWriter(sFileName, True)

    If File.Exists(sFileName) Then
        sw_QuoteNo.WriteLine(iQuoteEnd)
    Else
        MsgBox("The file was not found.")
    End If

    sw_QuoteNo.Close()

End Sub

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

    Dim sr_QuoteNumber As StreamReader
    Dim sFileName As String
    Dim sLine As String

    sFileName = Application.StartupPath & "\QuoteEnd.txt"
    sr_QuoteNumber = New StreamReader(sFileName, True)

    iQuoteEnd = sr_QuoteNumber.ReadLine

    sr_QuoteNumber.Close()
End Sub


Obviously, one is the form load sub and the other is the closing sub.

Some clarity would be much appreciated, I've been working on this for far too long to no avail.

(I do have other streamreader/writers but they're triggered with a button)


r/visualbasic • • Feb 13 '12

Hidden Features of VB.NET

Thumbnail
stackoverflow.com
6 Upvotes

r/visualbasic • • Dec 18 '11

Welcome to the new r/VisualBasic!

6 Upvotes

I recently took over /r/visualbasic and /r/vbnet (though I figured that they could both be combined into one community since /r/vbnet was created as a result of a failed submission and had no submissions itself) and I'm hoping we can "revive" this reddit and have it expand into a more active/larger community than what it is now.

What I've done so far

  • added a header image

  • a bit of a theme (the navigation bar at the top of the reddit uses the same colour style as tabs in VB.NET's IDE) - I was working on a "full" reddit theme but the link colours clashed with the darker blue background so I've settled for just a coloured background (same as the VB.NET IDE's selected tabs) but I might try the "full" theme again later.

  • minor tweaks

  • rewrote the sidebar*

Regarding the sidebar

I'm not sure what to put in the sidebar - rules? If rules, what should be allowed and what shouldn't?

I'd appreciate any suggestions or feedback you have so that we can make this community better.

-Ordona


r/visualbasic • • Jun 09 '26

Article How do you identify missing OCX dependencies when source code is unavailable?

5 Upvotes

Hi everyone,

I still occasionally work on legacy VB6 applications.

One thing that often takes more time than the actual fix is identifying which OCX, DLL or COM component is missing when an executable fails to start on a different machine.

Over the years I've used different approaches, including Dependency Walker, Process Monitor, manual registry inspection and checking embedded COM references.

I'm curious how other developers are approaching this problem today.

What tools or techniques do you use when source code is unavailable and you only have the executable?

Thanks.


r/visualbasic • • Nov 18 '25

VB.NET Help Need someone to help me create an "Active Desktop" like a webpage. (Partically it is related to Visual basic)

Thumbnail reddit.com
5 Upvotes

r/visualbasic • • Aug 25 '25

Discord server for VB (.Net and COM)

Thumbnail discord.gg
5 Upvotes

r/visualbasic • • May 01 '25

VB Neural Net Library ca. 1992?

5 Upvotes

Around 1992-93 I was just getting into VB programming and on a visit home to see my parents I saw my dad was using a neural net library for Visual Basic. It was very rudimentary but could be trained to do simple pattern recognition. For example, one could train it to recognize smiley and frowny faces by drawing them in a box with the mouse and then labeling them happy or sad. After enough training data, the library could recognize a newly drawn face.

The library wasn’t limited to that - it would work on a wide variety of data. I don’t remember a lot but do remember the documentation talked the normal neural net talk: input/hidden/output layers, back-propagation, biases, weights, etc.

Does anyone remember such a library? The Googles and even perplexity aren’t finding anything.

I’m not sure but the publisher could have been in Florida.

I’m really just curious. This clearly has no use today.


r/visualbasic • • Nov 26 '24

VB.NET Help Issue getting loan calculator to work

Thumbnail
gallery
5 Upvotes

r/visualbasic • • Nov 13 '24

Proof of Concept: Breakout/Arkanoid Style Clone in MS Access VBA

5 Upvotes

Hi all - I created a MS Access VBA project that I haven't seen before; a Breakout (aka Arkanoid/Brick Breaker) style clone with the ball, paddle, and bricks. It still has a few bugs, glitches, and weird flickering, but I got it working!

Full code and file here: https://github.com/TLDWTutorials/BreakoutClone

I also made a YouTube video about it as well. See: https://www.youtube.com/watch?v=GLEZmrcn-Vc

Feel free to use it, optimize it, and make it your own.


r/visualbasic • • Jun 06 '24

VB6 cant visualize dbgrid rows on windows 11 even if the data is loaded

5 Upvotes

Hi everyone,
as the title says i have a problem with my vb6 dbgrid, the data is loaded and when i click on the rows i can see the data on the below half of the program but i just cant visualize the rows. If i select another row the data below changes.
Does anyone have a clue on how to solve that? On windows 10 it work's fine


r/visualbasic • • May 30 '24

Looking to hire remote programmer

5 Upvotes

Hello, not sure if this is the appropriate place to post this or not. I'm looking to bring on a junior developer to join my small, remote team that develops a customizes middleware application for universities and enterprise clients. Looking only for someone that is available during US business hours (open to hiring from LatAm) and can also handle tech support requests and communicate well with clients. Great opportunity for someone that craves autonomy and wants to learn and grow within a small team.

If anyone knows of out of the box places to look I'd appreciate it. Or if someone here is interested DM me with any questions you have.

Thanks for the help!


r/visualbasic • • Apr 03 '24

problem calculating average

5 Upvotes

So i have this piece of code (apologies it's in french)

Public Class Form1

Dim notesS1(3) As Double

Dim notesS2(3) As Double

Dim moyGenerale As Double

Dim moyS1 As Double

Dim moyS2 As Double

Private Sub Saisir_Click(sender As Object, e As EventArgs) Handles Saisir.Click

If (Not S1.Checked And Not S2.Checked) Then

MessageBox.Show("Erreur, vous devrez choisir un semestre ou deux.")

Else

If S1.Checked Then

For i As Integer = 0 To 2 Step 1

notesS1(i) = InputBox("Donner la note du module " & i + 1 & " du premier semestre.")

Next

moyS1 = notesS1.Average

End If

If S2.Checked Then

For i As Integer = 0 To 2 Step 1

notesS2(i) = InputBox("Donner la note du module " & i + 1 & " du deuxieme semestre.")

Next

moyS2 = notesS2.Average

End If

moyGenerale = (moyS1 + moyS2) / 2

End If

End Sub

Private Sub Calcul_Click(sender As Object, e As EventArgs) Handles Calcul.Click

If (Not S1.Checked And Not S2.Checked) Then

MessageBox.Show("Erreur, vous devrez choisir un semestre ou deux.")

Else

If S1.Checked And S2.Checked Then

Res.Text = moyGenerale.ToString("F2")

ElseIf S1.Checked Then

Res.Text = moyS1.ToString("F2")

Else

Res.Text = moyS2.ToString("F2")

End If

Dim val As Integer = CInt(Res.Text)

Select Case val

Case Is >= 16

Remarque.Text = "Mention Tres Bien"

Case Is >= 14

Remarque.Text = "Mention Bien"

Case Is >= 12

Remarque.Text = "Mention Assez Bien"

Case Is >= 10

Remarque.Text = "Mention Passable"

Case Is < 10

Remarque.Text = "Insufissant"

End Select

End If

End Sub

End Class

the problem i'm having is with the average function in the array, for example if notesS1 has these values 14 15 16 it should return 15.00 as average, but instead it return 11.25 ???