r/visualbasic • • Jan 10 '23

VB6 Help Grasshopper/Rhino VB script to Excel (VBA)

8 Upvotes

Hello all, I have a rather unusual request for help. I am making a dome style tent with two poles, and trying to figure out the shape the bent pole makes has led me to this forum post https://www.physicsforums.com/threads/bending-of-a-long-thin-elastic-rod-or-wire-finding-shape-height.735200/ which has a text file with some VB script for a plugin to a 3D design program. The author says it should be ‘relatively straightforward’ to port the code to Excel (VBA). If anyone is able to do that, please reply or PM me - I’d be willing to compensate someone’s time. Thank you!


r/visualbasic • • Jan 09 '23

VB.NET Help Can't seem to capture command line output?!

8 Upvotes

I am trying to write a utility that takes user input, passes it to a command line application, and then captures the output of that application. The output will contain a session key that I would use for additional commands to the CLI.

However, I can't get any output and I am not sure why. Code is below:

-----

' Declare variables for the file path and arguments

Dim filePath As String = "<path>\app.exe"

Dim arguments As String = "\args"

' Create a new Process object

Dim process As New Process()

' Set the file path and arguments for the process

process.StartInfo.FileName = filePath

process.StartInfo.Arguments = arguments

process.StartInfo.CreateNoWindow = True

process.StartInfo.UseShellExecute = False

process.StartInfo.RedirectStandardOutput = True

' Start the process

MsgBox("command is: " & process.StartInfo.FileName & " " & process.StartInfo.Arguments, vbOKOnly)

process.Start()

' Wait for the process to finish

process.WaitForExit()

Dim sOutput As String

Using oStreamReader As System.IO.StreamReader = process.StandardOutput

sOutput = oStreamReader.ReadToEnd()

End Using

Console.WriteLine(sOutput)

MsgBox("sOutput", vbOKOnly)


r/visualbasic • • Jan 03 '23

An example using the Yield statement

8 Upvotes

Just came across the Yield statement and thought it looked pretty cool. So, to understand it, i came up with the following example:

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim Text As String = "This is a test string."

        Visible = False

        Debug.WriteLine($"Get_Vowels(): There are {Get_Vowels(Text).Count} vowels.")
        Debug.WriteLine($"Get_Vowels2(): There are {Get_Vowels2(Text).Count} vowels.")
        Close()
    End Sub

    Public Shared Function Get_Vowels(Text As String) As List(Of Char)
        Dim Vowels As New HashSet(Of Char)({"a", "e", "i", "o", "u"})
        Get_Vowels = New List(Of Char)

        For Each Letter As Char In Text.ToCharArray
            If Vowels.Contains(Letter) Then Get_Vowels.Add(Letter)
        Next
    End Function

    Public Shared Iterator Function Get_Vowels2(Text As String) As IEnumerable(Of Char)
        Dim Vowels As New HashSet(Of Char)({"a", "e", "i", "o", "u"})

        For Each Letter As Char In Text.ToCharArray
            If Vowels.Contains(Letter) Then Yield Letter
        Next
    End Function

End Class

r/visualbasic • • Oct 22 '22

VB.NET Help Windows Forms

8 Upvotes

So I'm making a game in visual basic windows forms, I need a way for the player to click a button to see the rules and then it loads up a HTML file with all of the rules on. Is that possible? Thanks

EDIT: It's probably worth noting that it's not an actual website, it's just something saved on my laptop that I've created


r/visualbasic • • Oct 09 '22

How do you fix and avoid Automation Errors?

8 Upvotes

I have some code I made to help a friend out. There are two subs that have the same error. They work on my computer, but they eventually started giving him the Automation Error. I read a few websites that said a few different things. I was curious about how VBA handles garbage collection, so I looked it up. The website basically said, "You only have to Set vars to Nothing if they are circular references". Then a site talking specifically about Automation error said to Set it to Nothing. I may be wrong but even if that was what caused it, how does one stop that error from coming up once it starts?

The website had other things that might cause this, but Excel running out of memory is probably the most likely one.

Sub highlightDuplicates()
    
    '! Important.  Before this can be used, go to tools>references and select "mscorelib.dll"
    '! Important.  Before this can be used, go to tools>references and select "Microsoft Scripting Runtime"

    Dim concatData As dictionary
    Set concatData = New dictionary 'Corresponding data to history
    
    cRow = Selection.Row
    
    Dim anchor As Range
    Set anchor = Range("A" & cRow) 'the current TRNS cell
    
    Call Assert(anchor.Value2 = "TRNS", "Must start on the first TRNS cell")
    
    While anchor.Value2 <> vbNullString
        'loop through A column until end of column'
        If anchor.Value2 = "TRNS" Then
            ' Find TRNS cell

            ' go to all offsets and concat the values
            ' add total result to key of concatData
            
            ' Most importantly, breathe!
            ' I hate the repeated code.  Breathe and accept your flaws.
            ' remember all the changing info is inside Offset parentheses.
            ' and don't succumb to the weight of life's problems
            
            outString = WorksheetFunction.TextJoin( _
                "-->", False, _
                Range("A" & cRow).Offset(0, 3).Text, _
                Range("A" & cRow).Offset(1, 3).Text, _
                Range("A" & cRow).Offset(0, 4).Text, _
                Range("A" & cRow).Offset(1, 4).Text, _
                Range("A" & cRow).Offset(0, 5).Text, _
                Range("A" & cRow).Offset(0, 7).Text, _
                Range("A" & cRow).Offset(1, 7).Text, _
                Range("A" & cRow).Offset(0, 8).Text, _
                Range("A" & cRow).Offset(0, 9).Text _
            )

            If Not concatData.Exists(outString) Then
                'Make this a hashmap with the key an array of all duplicate cells
                ' this iteration it will only contain this anchor
                Set concatData(outString) = New ArrayList
                concatData(outString).Add anchor
            Else
                concatData(outString).Add anchor
                For i = 0 To concatData(outString).Count - 1
                    'loop through all duplicates and change fill
                    concatData(outString)(i).Resize(3, 13).Interior.ColorIndex = 6
                    'concatData(outString)(i).Interior.ColorIndex = 6
                    Debug.Print (concatData(outString)(i).Address)
                    Debug.Print (outString)
                Next
            End If
            
        End If
        cRow = cRow + 1
        Set anchor = Range("A" & cRow)
    Wend
    
End Sub

The error is at "Set concatData(outString) = New ArrayList" in the first block of the If statement.

Also, I'm fairly new to VBA, so I'm up for criticism if there are any optimizations you can see.

code notes: Assert is a function I made to throw a MsgBox and stop the code if the condition isn't met.


r/visualbasic • • Jul 19 '22

Stuck on a problem with MS Access table when running an SQL query in VB6. "The Specified field could refer to more than one table listed in the FROM clause of your SQL statement."

8 Upvotes

I'm not very familiar with VB6 but I am troubleshooting something that is supposed to create a report in Christal reports and get this message evetime I try to run it. it doesn't crash just creates an error window with:

"Failed to retrieve data from the database. The Specified field 'EmpID' could refer to more than one table listed in the FROM clause of your SQL statement."

This is the code that I'm using.

frmReportViewer.sReport = "PayrollEmployee.rpt"

frmReportViewer.sFilter = "SELECT Payroll.*, Employees.* FROM Payroll INNER JOIN Employees ON " & _

"Payroll.EmpID=Employees.EmpID " & sSQL & " ORDER BY Payroll.EmpName, Payroll.FromDate"

frmReportViewer.sFilterText = sText

frmReportViewer.Caption = "RCL Software - Payroll Report - By Employee"

When I leave the employee number field blank the report runs and creates a report with the grid and layout that was designed but its blank. When an employee number is put in the field the report is not generated and creates the error dialog window.

Any help is greatly appreciated.


r/visualbasic • • May 02 '22

VB.NET Help having troubles figuring this out (I'll put the related code in the comments)

8 Upvotes

r/visualbasic • • Dec 28 '21

how do i merge a visual basic forms project into a single file

8 Upvotes

Hello, when i build a forms project, the executable file comes with multiple files:

Thanks in advance


r/visualbasic • • Sep 07 '21

Resources for Visual Basic 3 for Windows 3.1

8 Upvotes

I was wondering if anyone had any good resources for the DOS era of Visual Basic. I’ve been working my way through the guide that comes with the program, as well as digging through the sample projects, but was wondering if anyone had any great gems that might help me with getting an advanced understanding of the language. Not certain how much it changed when it became .net, or how useful modern resources are. I’ve never used any Visual Basic before, but I am a programmer (c# for unity mostly). Thanks for any help!


r/visualbasic • • Jun 20 '21

Why do I see so much VB6 stuff here?

8 Upvotes

I use VB.Net in a professional environment and have done for years. I have been working in VB since (I think) 1998. My understanding was that VB6 was dead, like LONG dead. We spent millions ripping out old VB6 applications years ago and yet on this sub reddit which I joined a few weeks back I am seeing loads of posts related to VB6, but also people learning VB6. Is it still alive and well in some corner of the world or have I stumbled upon a sub culture that I was unaware of? I haven't met any programmers in my line of work that use VB6 still so I am at a loss, or maybe I am sheltered in a section of the community and missing out on something cool. Any help in understanding what I am seeing is appreciated.

Stay safe and happy coding.


r/visualbasic • • Feb 25 '21

Is VB still used?

8 Upvotes

I'm doing vb in my programming course, I am already familiar with java, so vb does not seem that difficult, just wondering if it is still used, or if it is outdated. Thanks


r/visualbasic • • Feb 11 '21

I can't figure out why I am getting runtime 13 error (type mismatch) when I put a range in my code instead of a single cell.

Thumbnail
gallery
8 Upvotes

r/visualbasic • • Feb 02 '21

VB.NET Help [VB2016] Vb.Net and MS Access error. I'm new to reddit so im unsure how to type this, sorry!. I'm trying to learn to paste the codes here. Been at it for a week and gotta submit this tomorrow. This is the only error

Thumbnail
gallery
8 Upvotes

r/visualbasic • • Jan 20 '21

Tips & Tricks Just discovered Partial Class

8 Upvotes

So, i just discovered Partial Class. Well, actually, Partial is a modifier and not just for Class. But i happened to be excited to use it for Class right now.

Then again, i didn't actually discover it just now. I've seen it before, perhaps many times. It just never clicked, or for whatever reason, i never saw too much value in it. Now i do.

Some time ago, someone taught me one of his own practices: If the code doesn't fit on one screen, split it into another function. He was using C++, and 20 years ago, that really helped with reading code.

I never picked up that practice exactly, but the idea still rings true. Long routines are hard to read and often should be split. I often split things by function, and have many subs and functions with just a line or two, where the purpose of splitting it was just to give it a descriptive name and be kind to the next person (probably me) who looks at the code.

But this idea extends further. Often i'll have Form1.vb itself as some long winding file impossible to navigate without knowing the process. Yeah, there are the dropdowns on top of the editor that i never use, but they do not help with conceptualizing what goes together. That's what Modules and Classes are for.

Modules are okay but have no shared context. So, i need a class. But creating another class means it has its own context. If i want logging to continue in the other class (because it's really just an extension of the current class) i need to pass it a reference to the log, or any other object it wants to use. That's might be okay, except it breaks some of the ideas of encapsulation, can lead to other issues, and it needs to be instantiated, which seems silly for the task at hand.

A second look made me realize that i did not need another class in this case. I just wanted a second file for the purpose of organization. Enter Partial Class. I just changed Class <new class> to Partial Class Form1 (note to self that i'll probably ignore: that really does need a better name) and poof, i'm done. (Well, actually, i also needed to remove the sub new and the variables to hold the passed objects.)

I'm so much happier now. I got organization down so people can understand the logical sectioning of the code and yet kept it as one class, for there is no reason for it to be otherwise. The only downside is that looking at a routine name will not tell you which file it is in. Well, unless you know what it does.


r/visualbasic • • Sep 02 '20

Error while writing VB in excel

8 Upvotes

I am new to Visual basic and trying to write a vba formula to use as a conditional formatting in excel. This is the snipit that is giving me fits.

Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _

"=AND(G2<>"NR", ISBLANK(H2),ISBLANK(I2))"

Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority

The above is throwing an syntax error. The "NR" portion is highlighted. When I paste that same AND() formula into a cell it seems to work just fine. What am I doing wrong?


r/visualbasic • • Jul 14 '20

VB6 Help What textbook would you recommend to someone learning VB?

8 Upvotes

I'm looking for textbooks on visual basic, thank you in advance!

EDIT: I mean VBA


r/visualbasic • • May 20 '20

Urgent saving data into access issue

8 Upvotes

r/visualbasic • • May 06 '20

VB.NET Help Former angular dev now working with Visual Basic/c#. Looking for some resources on VB.

8 Upvotes

Hey everyone,

As title says all of my development has been angular clients with C# api’s and sql for data. In my new job all the other devs use VB.net and c# web pages. Some stuff is familiar on the c# side, but vb.net is wayyyy different from what I’ve seen lol. Anyone know of any good resources for a overview of vb.net?


r/visualbasic • • Apr 07 '20

VB programmer interested in writing web software. Where to start?

8 Upvotes

I am VB programmer with just enough skill to make the small apps needed. I write simple Windows Form Apps in VB.NET / VS 2019, after having switched from VB6.0 only about 2 years ago.

I am now interested in writing some simple apps for the web (i.e. run on a server and accessible to an end user via a web). I am under the impression that this can be done with VB using ASP.NET or something. Is this true? Despite some googling, I am very confused on where to begin.

Can somebody give me a brief explanation or point me in the right direction for where to start coding VB for a webapp? Or would I be better off starting with a new language / platform?


r/visualbasic • • Nov 12 '19

Any way to exclude title (Class1 - 1) when printing labels?

Post image
8 Upvotes

r/visualbasic • • Mar 20 '17

A* Pathfinding in VB. I sure wish somebody would have shown me how to do this 20 years ago.

Thumbnail
youtube.com
8 Upvotes

r/visualbasic • • Mar 10 '17

A Few Personal Questions for Visual Basic Programmers

8 Upvotes

Hey,

I am learning to use Visual Basic 2015 in a college course right now, and I've been tasked with asking programmers who work with Visual Basic (any version) a few short questions about what they do in their profession and how they solve problems. So if you wouldn't mind answering a few of the questions below, I'd be greatly appreciative.

What is your job description?

What do you like about your job?

What don't you like about your job?

What kind of problems do you have to find solutions for most often?

How do you solve problems?

What led you to learn and use Visual Basic?

Are you at all concerned about the longevity and viability of the Visual Basic language? If so, why?

Thanks in advance for reading and responding!


r/visualbasic • • Oct 13 '16

Practice coding with fun programming challenges

Thumbnail
codingame.com
8 Upvotes

r/visualbasic • • Feb 24 '16

Microsoft Visual Basic Honored as AIAS Technical Impact Award Recipient

8 Upvotes

Watch here: https://youtu.be/5FYR7t4oktg?t=2h4m44s

Scott Ferguson: "On February 18, 2016 I had the great honor and privilege of accepting the D.I.C.E. Awards Technical Impact Award presented to Microsoft Visual Basic."


r/visualbasic • • Jul 12 '15

StringBuilder vs String Performance

Thumbnail
itandtechstuff.com
8 Upvotes