/r/visualbasic

Photograph via snooOG

A place to discuss, ask questions and share ideas regarding the Visual Basic programming languages.

/r/VisualBasic - A place to discuss, ask questions and share ideas regarding the Visual Basic programming languages.

Please up vote anybody who helps with your submission, we want people to keep answering questions.

Tips & Guidelines

  • Please prefix your posts with the version of Visual Basic you are using. Example: [VB2010] - [VB2015], [VB6], [VBSCRIPT], [VBA]
  • Posting any code you have will help others better understand what you are trying to do and what you have tried already, even if it doesn't work properly. It also shows that you already tried to solve your problem.
  • If you ask for help, you should come back and let us know how things turned out.
  • Homework questions are tolerated, please be specific about the question as much a possible. Asking us to write it for you is not going to happen. We also reserve the right to not answer if we think you are just not trying.
  • Tell us what you have tried, to help us give better answers?

Communities

Resources

Learning Visual Basic

Related Subreddits

/r/visualbasic

9,207 Subscribers

6

NEW VISUAL BASIC USER

I am new to visual basic but very experienced in Excel (and other office apps). I am beginning to learn the power of Visual Basic in doing things I want to achieve, especially in Excel. What is the best way to learn Visual Basic? I can't see any College or Uni courses on it. What do you folks recommend. I am very maths literate (Chemistry Grad), so the complexity of the course need not be too basic (pardon the pun)!

18 Comments
2025/01/29
12:09 UTC

3

Run Time Error 52 in Exce

Hello,

A volunteer sporting organization I am a member of uses an Excel spreadsheet based “software program” to score tournaments. This software was developed around 2005 in a prior version of Excel and periodically updated as needed, but still has an .xls extension. The person who developed and maintained this software died unexpectedly, and while they did leave behind a fairly detailed document that outlines how to use the software, it doesn’t really cover the programming of it, nor what I assume is VB code and macros that drive the calculations and formatting for the results.

I have been volunteered to try see to it that we can continue to use this software, however it appears I may have an incompatibility between the versions. The user guide states “has been tested with Microsoft Excel 2000, 2003, 2010, 2013, and 2016 under Windows 2000 Professional, Windows XP, Windows 98, Windows 7, and Windows 10 on a variety of computer platforms. Keep in mind that Excel changes with different releases. Sometimes these different releases may affect how Stat Office functions. For example, some users have noticed that Window 11 will not allow Stat Office to run its code correctly.”

As it turns out my computer is running Windows 11, Excel 2408 and the program does not seem to want to run on my machine. When I attempt to activate some of the program features using functions in the Add-ins tool bar, I get a Visual Basic error that reads “Run-time error ‘52’: Bad file name or number”. It should be noted that this program utilizes an Excel file and 4 “.txt” files (these .txt files have info on the competitors, teams, tournament format, and individual match scores).

So it seems that the author of this program knew there was a potential compatibility issue with Win 11. I am not very knowledgeable about VB programming, though I do use Excel regularly and have experience with Macros, etc. Based on this error, does anyone have suggestions on how to get this to work in Win 11?

Edit: sheet was locked with unknown password, but that has been worked out, so only the Run Time Error 52 remains.

5 Comments
2025/01/28
14:39 UTC

2

Split function issues with quoted strings

Hi all,

I am trying to parse a csv file using the split function. Delimited with a comma. However, some of the strings in the file are surrounded by quotes with internal commas so the split is happening within the quoted strings. Any way around this?

14 Comments
2025/01/21
16:40 UTC

2

i want to make raycasting like wolf3d

i want a project that i can start from it in vb6 like in this video

https://youtu.be/8we2znb9c-Y?si=9pglEYSrYV69ckVO

thanks for any one can help me

0 Comments
2025/01/19
20:01 UTC

4

Word Macro Optimization

Hi everyone,

I'm very new to VB. but wrote a macro yesterday that auto inserts info into a text content control when a specific option is chosen from a dropdown, the issue is that there are 2 dropdowns, with about 50 options each, and has to be that way. there are therefore a lot of the below statements, often containing as many as 200 words in the Y field. is there a way to optimize it so that its more accessible, and faster. Ive been told to add a dictionary, but as far as i know, I can only have 1 "ThisDocument" text file, and therefore, everything would have to be on the same text file anyway. Please excuse my lack of coding wording.

Case "X"
    resultCell.Range.Text = "Y"
6 Comments
2025/01/16
07:06 UTC

2

Application created with Visual Basic and COM port communication

Hi guys,

I debated for weeks on whether or not post this here and have spent many hours trying to research a possible solution to the issue I'm having. I have a balance machine I purchased years ago and recently refitted with a new control system. It uses two data acquisition cards that are plugged into 9-pin jumpered COM ports (JCOM1 and JCOM2). The software was created with Visual Basic 6 and the company was kind enough to include all sorts of Visual Basic goodies to include Visual Basic 6 itself (yes, I plan on hanging out here to learn to eventually make my own balancing software!). One day, the software just stopped reading any data from JCOM1 and I can't figure out why for the life of me. I've performed a successful loopback tests on both COM ports. They also included Dependency Walker with the system. Do you guys have any advice on how I could troubleshoot this software?

https://preview.redd.it/cgf6krtr1ade1.jpg?width=1200&format=pjpg&auto=webp&s=c28d28f171ae517b7172e1a99b138df9b80ad53b

https://preview.redd.it/cj0p55ps1ade1.jpg?width=1200&format=pjpg&auto=webp&s=647f0d9dcc52ac4304e6e81b575322d229901106

https://preview.redd.it/80k23alv1ade1.jpg?width=1200&format=pjpg&auto=webp&s=714ab807b4cec4234bfe59bb30a2d234c18e6da5

https://preview.redd.it/0tyblg4y1ade1.jpg?width=1200&format=pjpg&auto=webp&s=cee72c95c00ac557319ee3da554def354aead163

36 Comments
2025/01/16
00:46 UTC

2

Is there a way to make the lines that are connecting if/endif to get bold when selected or when IF is clicked?

Currently only the if/endif are highlighted when you click one of them, but the line connecting them doesn't. is there a way to make the line get either bold, or highlight?

https://imgur.com/I1lEc7h

3 Comments
2025/01/15
16:13 UTC

17

Is Visual Basic still a good starting point for new developers in 2025?

I was recently talking to a friend who's just getting started in programming at Keene Systems, and we got into a debate about whether Visual Basic is still relevant for beginners. With so many people diving into languages like Python and C# these days, is it still worth starting out with Visual Basic? I know it used to be a foundational language for many, but has it held up against modern programming languages? I’d love to hear your thoughts on whether VB is still a solid option in 2025 or if its time has passed.

22 Comments
2025/01/15
09:29 UTC

1

#HELP , VB6 problem

https://preview.redd.it/rruyd2wzspce1.png?width=340&format=png&auto=webp&s=75bd6099d07f65f3e07c17ea01cf8ffc99785620

Hi everyone, I am a beginner, I am studying vb6 as a simple start.

I want to make a file replacer, as shown in the figure, replace the target file on the right with the file selected on the left,

but I don't know the path of the selected files to write the code, please help

11 Comments
2025/01/13
07:41 UTC

3

Barcode generation

I am looking for a way to turn a string into a barcode.

The Internet suggested Zxing, but following an online example of how to implement it from 2021 yielded errors I had no idea how to solve.

4 Comments
2025/01/05
02:26 UTC

3

converting pdf into a grayscale pdf

i am making a VB DotNet program that can open a pdf, then when I click i button i would have an output pdf that would convert it into a grayscale or monochrome before i print it if i want to. Is there a way to do that? I am using Adobe AxAcro but it doesnt have an option to print it directly as monochrome without displaying its print dialog.

1 Comment
2025/01/04
13:33 UTC

5

VB / SQL date problem

Hi,

I'm having a silly problem with a date field, swapping around.

In VB I am loading the current date into a DateTime variable with 30 minutes added:

Dim TokenExpire As DateTime = DateAdd("n", 30, Now)

This is then stored in a Sql Server database in a datetime column.

UPDATE TOP(1) MyTable SET Api_Token = '" & VArray("token") & "', Api_Token_Expiry = '" & TokenExpire & "' WHERE Api_Key_Name='" & ApiKeyName & "'

Later I retrieve this date into another DateTime variable so I can do a compare to see if the stored date / time has passed.

Dim ExperationDate As DateTime = VDT.Rows(0).Item("Api_Token_Expiry")

However the comparison is not working and if I print both TokenExpire and ExperationDate, I can see that the days and months have flipped around.

01/03/2025 14:16:18
03/01/2025 14:08:14

Where am I going wrong?

4 Comments
2025/01/03
14:30 UTC

5

2003 VB.NET Book

I just recently bought a book to learn Visual Basic.Net. The book is Learning Visual Basic.NET from O'Reilly. I found out that the book is from 2003... Can I still learn from it and just supplement the updated parts of VB.NET or should I just get a new book.

9 Comments
2024/12/31
05:55 UTC

2

Logic / UI separation

Hi all!
Noob question... I'm writing a toy app just for learning VB6-Excel interaction, outside VBA. I have a very simple form atm with a label and a button, and a module that encapsulates everything non ui-related.
The app opens an excel file and prints the next cell in the label at every click.
The form when loaded calls a sub in a module that dims an excel app object, a workbook, a worksheet and a range.
The button when clicked updates the label with
lbl.caption = utilities.get_next_cell()
that is both a getter for the cell value, and shifts the cell down.
The form when closed calls a module sub that closes both the file and the app and frees the objects.
Is it this the right way? Should I call a sub in a module at every btn_click, form_load and so on, and write code in the event handlers only if the code modifies something in the UI, or is it "clean" enough to put a bit of logic in some UI-related subs? For example, I found an example where the application, workbook and so on are allocated directly in Form_Load without using a module.
But, if I was to rewrite the UI in, say, tk one day, I could compile the subs in the module in a DLL (it's a toy program, but to speak in general) and reuse the "logic" part cleanly, cause it's decoupled, right? Or is it just overthinking and it's ok not to care too much about it? Thanks, and merry Christmas with a bit of delay XD

3 Comments
2024/12/28
17:09 UTC

3

how can i download visual basic 2010 ?

1 Comment
2024/12/24
21:15 UTC

2

Anyone here do small gigs?

I need a bit of code to customize a spreadsheet to send certain emails to individuals listed within. Do any of you experts take on small jobs or can you send me to a good source? I didn’t feel as comfortable with fiverr or similar.

7 Comments
2024/12/19
11:40 UTC

2

advice needed...

Hi everybody!
I'm studying to be able to land, one day, a programming job, but I'm also getting ready for the summer, where I live jobs revolve around tourism and I'll try to get a part time job in an hotel like every year. Excel is a nice skill to have, but unfortunately I don't have many chances to use it in my day-to-day life. VBA is seen as an "expert" thing here and so even nicer to add to the resume, and even if I kinda like the language (played a bit with VB6 as a teenager) and it "clicks" with me (more so than C despite having used it for much longer), I'm afraid I'll forget it if I don't use it during the winter (I study system programming in winter months, my true passion!). I know a lot of people frown upon vb.net as a language for .net learners and tend to suggest c#, but I opened up VS community, tried a VB console app and wow, the syntax seems sooo similar... and it's a lot more likely I'll use .net for some interesting project than excel/vba... and here is the question... would it be ok for me to study vb.net after learning vba, in order to both learn something about .net and, even more important, not forget vba before the next year? Ty all!!

6 Comments
2024/12/17
18:43 UTC

4

I messed up. Rookie mistake

So after many hours trying to make this userform, all learning as I go and lots of chatGPT/Co-pilot/Claude "Messing up" I realized I am the one who has been messing up. I've been coding excluseivly in the userform, none in the actual document. Now totally unsure what can stay and what should go into the document. As of now (before moving anything) everything works so far except what I've spent the most time trying to accomplish.
Send help If anyone would care to help me figure out how to move the correct stuff and maintain the function, I would greatly appreciate it... https://pastebin.com/0ggiHX3L

0 Comments
2024/12/17
06:10 UTC

2

Eval in VB.NET? (Forms)

Hi! I was making a small "CLI"-like project and need help to make the eval command, in this case it would be an evaluate command:

Here's my code (the eval function don't work):

Imports System.Windows.Forms

Public Class Form1

    Dim computerName As String = Environment.MachineName

    Public Function SimpleEval(expression As String) As Object
        Dim result As Object
        Try
            ' Allow simple arithmetic operations and variable assignments
            result = DirectCast(Evaluate(expression), Object)
        Catch ex As Exception
            result = "Error: " & ex.Message
        End Try
        Return result
    End Function

    Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
        If e.KeyCode = Keys.Enter Then
            Dim userInput As String = TextBox1.Text

            SimpleEval(userInput)
            Label1.Text = "> [" & computerName & "]:" & userInput
            'TextBox1.Text = ""  ' Clear the textbox
        End If
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        TextBox1.Focus()
    End Sub
End Class
6 Comments
2024/12/16
19:46 UTC

3

Insert new paragraph in body

I've been back and forth with Co-Pilot and ChatGPT, but both kept suggesting this InsertParagraphAfter line. I'm not sure how to make it work since it seems like that's the most suggested either way. Anyways below is what I ahve. I want to add a line below a content control if possible on a button press. I want to make it a function so that I can use it elsewhere as there are multiple lines I want to add occasionally.

I'm extremely new to coding in general, and I know there are probably a lot of ways to accomplish this templare and software project. Would love any help

Edit, because I forgot the important part. Currently getting error 424 due to the line

If wordApp Is Nothing Then.

This project is being done in Word. And I'm using word 2016

Current iteration:

Private Sub btnAdditionalWork_Click()

Dim wordApp As Word.Application

Dim doc As Word.Document

' Get Word application

Set wordApp = Application

' Get active document

Set doc = wordApp.ActiveDocument

' Add a new paragraph at the end of the document

doc.Paragraphs.Add(doc.Range.End).Range.text = "New list item"

' If the previous paragraph was a list item, apply the same list format

If doc.Paragraphs(doc.Paragraphs.count - 1).Range.ListFormat.ListType <> wdListNoNumbering Then

doc.Paragraphs(doc.Paragraphs.count).Range.ListFormat.ApplyListTemplate _

listTemplate:=doc.Paragraphs(doc.Paragraphs.count - 1).Range.ListFormat.listTemplate

End If

End Sub

Current error: Type mismatch

doc.Paragraphs.Add(doc.Range.End).Range.text = "New list item"

15 Comments
2024/12/16
02:24 UTC

3

Playing two audio clips at the same time?

So I have been working on a school project and I am having trouble figuring out how to play two different sounds at the same time, since the project I am working on is meant to be a game and it'd be very weird for a game to not have sound. Obviously I know that Visual Basic isn't meant for games but I figured there'd still be a way to play two or more sounds at once.

6 Comments
2024/12/14
04:30 UTC

2

Form change button not finding certain forms

Hi, I'm creating an HMI on VS 2019 and trying to use a form change button to get to different pages within the HMI. When I go to choose which form to open with said button some of the forms don't show up in the drop down of options. Any ideas why?

2 Comments
2024/12/13
15:58 UTC

6

Future-Proofing Business-Critical VB6 Applications: Need Guidance

Hello everyone,

My predecessor developed numerous programs in Visual Basic Classic 6.0, including business-critical applications and interfaces. Now that he has left the company, we are faced with the challenge of how to proceed with these applications. Microsoft officially ended support for VB6 in 2008, and we are concerned that the programs might stop working with future updates.

An upgrade from Windows 10 to 11 or even 12 has been planned for some time, and tests with Windows 11 are already underway at our parent company. Therefore, the question arises whether there is an estimate of how long the programs will continue to run smoothly, including database connections. How urgently should we look into external reprogramming?

Thank you in advance for your support and advice!

11 Comments
2024/12/09
10:52 UTC

3

Array help

I’m supposed to make an array for a soccer team and their scores that auto arranges from the teams with the most wins to least.

Then have a button that shows the scores (I know the button tool but the coding of the function is fuzzy).

However I have zero idea how to make the array, I’ve looked on Google and it’s all gibberish or I’m told to use a tool that I don’t have (for context I’m using 2022 version) let alone the coding associated.

Any help would be appreciated.

8 Comments
2024/12/05
02:07 UTC

3

You guys seem like experts, Can you help?

While working on a project I've come across a need for a large number of storage to be taken up by meaningless files, so i created a little vb.net project to do that. However I've come to a bottleneck and it's not as efficient as I need it to be (Currently 1GB in 20s), do you guys have any idea on how to improve it. Visual basic express 2010.

https://preview.redd.it/qn74hmetvs4e1.png?width=1087&format=png&auto=webp&s=5f7d55079d6224d2906b79dea54d46d26c37a836

1 Comment
2024/12/04
09:29 UTC

24

Using VB.NET gets you insulted by Microsoft

I was recently searching for something and found a great article on something related. While reading the comments I found some guy berating, insulting a belittling the article author for using VB.NET. While i currently use c#, i learned .NET using VB, and still like VB. And while I hate Java (from experience using it years ago), I can't imagine myself insulting someone who chooses to use Java. So I was pretty surprised and upset when I saw the comments from that guy, and even more upset when I learned he's a Senior at Microsoft for the past 8 years or so. As a fan of most Microsoft products and focused almost exclusively on the .NET framework and ecosystem, this hit me in a really sour spot. I personally feel developers are usually of a fact driven mindset, and are part of rather small communities in which many are contributors to. I feel these contributors should be thanked for giving without asking in return, and not bullied online. I just wanted to share my thoughts and what prompted my thoughts (see video below). And while my title may be a little misleading, employees of the major companies/players in our industry should be held to a slightly higher standard, in my opinion.

https://reddit.com/link/1h3ryg1/video/egxrtqnx454e1/player

20 Comments
2024/12/01
01:34 UTC

1

Please help im new to vb

How can i make vb run form 3 first instead of form 1 cant i just rename it or something

2 Comments
2024/11/28
05:36 UTC

20

My VB.NET 2D MMORPG Is Finally Complete!

Key To Heaven is my VB.Net passion project, a 2D MMORPG that I’ve been working on for almost 20 years. After years of dedication, I’m thrilled to announce that the game is finally complete and ready to launch!

Mark your calendars: on November 29th at 20:00 CET, the game will officially leave Early Access on Steam. Everyone will start fresh at level 1, embarking on this journey together. For me, this marks the beginning of some peace of mind, allowing me to shift my focus to smaller patches.

What’s it made in?

The game is built entirely in VB.NET.

  • The client runs on .NET 4.0 for compatibility with lower-end systems.
  • The server uses .NET 5.0. While I could upgrade to .NET 8, the current setup perfectly suits the project’s needs.

For graphics, I’ve relied on SFML, which has been a great fit for creating the retro aesthetic I envisioned.

Server Architecture

The server system is designed with flexibility in mind:

  • Each Realm can connect multiple servers, so, for example, I can host a server in both the US and EU, both syncing with the same database and master server.
  • This setup lets players seamlessly switch between servers to play with friends across regions, utilizing the same account & characters.
  • Players can even host their own Realms with custom servers and databases. These private Realms are independent of the official servers, so accounts created there won’t work on the main servers.

For custom Realms, players get all the tools they need to tweak game content—like adding new maps, items, monsters, and more. Plus, these custom servers will still show up in the game client’s server list for others to discover.

https://reddit.com/link/1h1betq/video/6444s8dhnh3e1/player

Why play it?

If you love retro-style indie games, Key To Heaven might be right up your alley. It has all the classic MMORPG staples: Randomized gear, crafting, raft, Questing, Raids...

But it also brings some fresh ideas to the table, like:

  • A built-in Battle Royale mode, where you can queue anytime for fast-paced, 2D combat with swords, bows, and spells. Ever tried that in a retro MMORPG?
  • Matchmaking for PvP, where you can safely face off against other players and climb the MMR leaderboard.

And there’s much more hidden beneath the surface, plenty to explore and discover as you play.

Website: https://key2heaven.com/

Download: https://store.steampowered.com/app/1347630/Key_To_Heaven/

Discord: https://discord.gg/TmHHJkG

9 Comments
2024/11/27
18:37 UTC

Back To Top