/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,145 Subscribers

1

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.

1 Comment
2024/12/05
02:07 UTC

2

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

17 Comments
2024/12/01
01:34 UTC

0

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

1 Comment
2024/11/28
05:36 UTC

19

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

3

VB.NET api-wrapper for llm-inference chatllm.cpp

Hi. I used Llama 405b to make vb.net api wrapper for llm-inference chatllm.cpp: JohnClaw/chatllm.vb: VB.NET api wrapper for llm-inference chatllm.cpp

0 Comments
2024/11/26
16:56 UTC

2

Newbie trying to save data to a table...

Hello! I have an assignment for class where I need to be able to edit a table in a dataset that is open using the

Datagridview. When I execute the code I wrote nothing happens except the dialogue box pops up confirming a save has happened. Any ideas on how to actually get it to save? here's my code:

Private Sub SaveToolStripButton_Click(sender As Object, e As EventArgs) Handles SaveToolStripButton.Click

        Try
            Me.Validate()
            Me.MeatPartyBindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.MeatDataSet)
            MessageBox.Show("Changes saved successfully!", "Meat Info", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Meat info", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try

    End Sub

I learned this code from dissecting one of the exercises in the book. the book is Programming with Microsoft Visual Basics 2019/2022 by Dianne Zak

2 Comments
2024/11/23
09:16 UTC

2

Filtering a table based on multiple values in a column

I have in column h multiple names on a table called SYS

I need to keep only which values on column h does not contain David Sama Sught Maria

How can I achieve this ? Thanks

2 Comments
2024/11/22
18:38 UTC

3

VB script won't run after working once, baffled.

Hi all,

I have 0 experience with VB, but I cobbled this together today using google, stack overflow and chatgpt (I know, please don't hate me) and I managed to get it to work once, and it seemed to work perfectly it did exactly what I wanted, and then I tried to run it again, exact same code, just on a different excel workbook and it now does nothing when I run it. No errors asking me to debug or anything just runs fine but doesn't actually do anything.

Code is meant to take an excel sheet called "Transactions", and then randomly select 10% of the rows and copy them over to the 2nd sheet called "Random" basically got a list of transactions that relate to company spending and want to create a way to just get the transaction report, run the script, then I have 10% of the transactions randomly selected which I can use for spot checking.

Anyone got any ideas? Code below:

Sub RandomLinePicker()

'Define the Start and End of the data range

Const STARTROW As Long = 1

Dim LastRow As Long

LastRow = Sheet1.Cells(Worksheets("Transactions").Rows.Count, 1).End(xlUp).Row

'Create an Array - Length = Number of Rows in the data

Dim RowArr() As Long

ReDim RowArr(STARTROW To LastRow)

'Fill the Array - Each element is a row #

Dim i As Long

For i = LBound(RowArr) To UBound(RowArr)

RowArr(i) = i

Next i

'Shuffle the Row #'s within the Array

Randomize

Dim tmp As Long, RndNum As Long

For i = LBound(RowArr) To UBound(RowArr)

RndNum = WorksheetFunction.Floor((UBound(RowArr) - LBound(RowArr) + 1) * Rnd, 1) + LBound(RowArr)

tmp = RowArr(i)

RowArr(i) = RowArr(RndNum)

RowArr(RndNum) = tmp

Next i

'Calculate the number of rows to divvy up

Const LIMIT As Double = 0.1 '10%

Dim Size As Long

Size = WorksheetFunction.Ceiling((UBound(RowArr) - LBound(RowArr) + 1) * LIMIT, 1)

If Size > UBound(RowArr) Then Size = UBound(RowArr)

'Collect the chosen rows into a range

Dim TargetRows As Range

' Initialize TargetRows as Nothing

Set TargetRows = Nothing

' Assuming RowArr is already populated and Size is correctly calculated

For i = LBound(RowArr) To LBound(RowArr) + Size - 1

If TargetRows Is Nothing Then

Set TargetRows = Sheet1.Rows(RowArr(i))

Else

Set TargetRows = Union(TargetRows, Sheet1.Rows(RowArr(i)))

End If

Next i

'Define the Output Location

Dim OutPutRange As Range

Set OutPutRange = Worksheets("Random").Cells(1, 1) 'Top Left Corner

'Copy the randomly chosen rows to the output location

TargetRows.Copy Destination:=OutPutRange.Resize(TargetRows.Rows.Count).EntireRow

End Sub

Thanks all!

8 Comments
2024/11/22
13:11 UTC

3

Other VB6/VBA/VBScript gotchas?

I notices that, VB6/VBA/VBScript have a gotcha in its language design; where subsequent conditions of an if statement, are evaluated even though they're not supposed to.

For array e.g.:

arr = array(3, 4, 5)
i = ubound(arr) + 5 'beyond array length
if (i < ubound(arr)) and isempty(arr(i)) then
  rem above line causes exception
end if

In above code, arr(i) is not supposed to be evaluated. But it does anyway.

Same thing goes to collection. e.g.:

set fl = createObject("scripting.filesystemobject").getfolder(".").files
i = fl.count + 5 'beyond collection length
if (i < fl.count) and isempty(fl(i)) then
  rem above line causes exception
end if

Or object. e.g.:

set x = nothing
if (not (x is nothing)) and isempty(x.prop) then
  rem above line causes exception
end if

I already know the workaround for above gotcha, and I'm not asking for other workaround, or any alternative language.

I want to know any other kind of gotcha in VB6/VBA/VBScript.

19 Comments
2024/11/21
09:03 UTC

4

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

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.

0 Comments
2024/11/13
21:21 UTC

4

RWRUN60 CMD failure

Hi, My employer upgraded Oracle from 11g to 19c.Now the Oracle forms builder fails to connect to Oracle 19c.RWRUN60 CMD just vanishes once the creds are entered and nothing happens.

Anyone has any experience with this and any suggestions or fixes for this?

Forms builder 6i was earlier connecting to 11g and everything was working fine.

Please let me know if any additional info is needed from my end.

I have no knowledge or experience on VB.So seeking out for help

They thought it has to do with encryption in 19c and altered the sqlnet.ora file to setting LOGON.ENCRYPTION=rejected but dint help

1 Comment
2024/11/08
19:25 UTC

7

Vb to mobile

Hi guys! I've made a program for my dad that he can know how many hours he made at job. But I don't know how to transfert my program to a phone. Can you help me? I do so many search and I can't find anything. I think that I can't do this, so please don't juge me about this. I'm with visual studio 2022, NET8.

Sorry if my english is bad, I'm learning. I hope that you can understand. Thank you!

9 Comments
2024/11/06
22:56 UTC

2

need help withinput validation

I have this button set up to increase an int value when clicked and decrease when you press shift and the button. It then displays the amount in a label. I'm trying to figure out how to prevent it from going below 0. As I currently have it, it drops to a negative number then display the message box. Any thoughts how I can make this work?

 If OGeneralT >= 0 Then

     If My.Computer.Keyboard.ShiftKeyDown Then
         OGeneralT -= General
     Else
         OGeneralT += General
     End If

     lblOGeneral.Text = OGeneralT

 Else
     MessageBox.Show("Number can't be less than zero")
     OGeneralT = 0

 End If
7 Comments
2024/11/06
19:41 UTC

6

Hourly rate B2B contract for VB 6?

Hello VBers!
I was contacted by a recruiter from Capgemini for a mid-role I will paste some of the insights as the text is long.

I was just offered 32 euros per hour (B2B). I live in Romania and I have done a Bachelors here, and a Master's in Switzerland, but I have only a year of experience. The job is for a senior role, so I guess that I will be "sold" like that. Now I would like to counter it, and ask for more. I am thinking of 55 euros/hour (as the technology is old and many avoid it), is it too much? Now I have a very stable job as a .NET developer, but I don't earn that well, I get 1250 euros/month.

Also, if I am fired I have where to live and I have an small extra income flow, so I can still survive.

Thank you all guys, for your time to read this long text and even reply! Appreciate it.

___________________________________________________________________________________________________________

Join our dynamic team to work on a cutting-edge banking project for one of Europe’s largest financial institutions.

MAIN TASKS AND RESPONSIBILITIES

- Design, develop, and maintain backend services and APIs to support various banking

functionalities.

- Collaborate with cross-functional teams to define, design, and ship new features.

...

- 6+ years of experience in software development

- Experience with Visual Basic 6

6 Comments
2024/11/04
09:08 UTC

2

Object reference not set to an instance of an object - please help

This VB script is reading text field values being fed from a table, which are coming from an XML file. The values are constantly changing and the XML file is being re-written and the data table is constantly updating the text fields.

I keep getting an error in the application running the script. "Script 'ElectionFS_404' Error Line 7: Object reference not set to an instance of an object". The line this error is occurring is

If Input.Find("results_40").Text("Winner2Mark.Text") = "W" then

Sometimes the loop will run fine for 2 hours, other times it will error out in 3 minutes. I am about to lose my mind trying to figure out what to do with it. I assume the issue is when the XML file or data table is being updated, the text fields are temporarily blank or unavailable. If I immediately restart the script, it will run fine again for some time, then error out again on the same line. I have a couple of similar scripts that all error out on that first If line.

It doesn't seem to care if the field is empty as it errors out even when the "W" is present.

Is there a way to handle this in a way that causes it to ignore the error or start over again?

I'd appreciate any type of feedback or hints as to what I can add or subtract to stop this error. Thank you all for checking out my post. Here is the script -

Dim W, fswinmrk2, fswinmrk1, results_40, ElectionFS_40 As String

Do While True

If Input.Find("results_40").Text("Winner2Mark.Text") = "W" then
API.Function("SetMultiViewOverlay",Input:="ElectionFS_40",Value:="9,fswinmrk2")

Else If Input.Find("results_40").Text("Winner1Mark.Text") = "W" then
   API.Function("SetMultiViewOverlay",Input:="ElectionFS_40",Value:="9,fswinmrk1")

Else 
     API.Function("SetMultiViewOverlay",Input:="ElectionFS_40",Value:="9,none")

End If
Loop
10 Comments
2024/11/02
20:12 UTC

4

PrintDialog1.PrinterSettings.SupportsColor Not Working

Hi guys, I had some trouble with PrintDialog1.PrinterSettings.SupportsColor. When I set my printer with with PrintDialog1.PrinterSettings.PrinterName, I should get that the printer doesn't support colors, but it says that it does. Why? If a try to use the PrintDialog1.ShowDialog(), it knows that the printer can't use colors but the command says it can. I hate this. I even tried with the PrintDocument, it doesn't work, either. Can you guys please help me?

6 Comments
2024/11/01
15:26 UTC

2

Integers across forms

I'm trying to make a casino with multiple forms, but I don't know how to carry an integer for a money amount from one form to another (example: from the lobby form to the bar table form). Does anyone know how to do this?

2 Comments
2024/10/30
19:23 UTC

3

Crash course on VB/asp.net?

I need to quickly study source code of a working legacy project built with VB and asp.net (and a MS SQL Server db), figure out what all the core modules/procedures are and what they do, and turn it a Python FastAPI backend for a future website and mobile/desktop app. I'm a Python/JS dev and have no idea of VB or dotnet.

What would be the best way to approach this? Where should I start? Any resources that can help me with this?

17 Comments
2024/10/28
01:40 UTC

22

VB6 alternatives today?

Hi Guys,

Back in the 90s I used code a lot in VB5 and then VB6. It was great. Drag and drop elements on a form. Do some coding. Nothing fancy. I used to make small programs to do simple things. It was great fun building these desktop apps for Windows 9x.

Now I want to get back into this kind of development. Is there any similar solutions these days? Something very very similar and if it's for Mac and somehow can make the "app" into a web app as well, that would be great. Otherwise just desktops for Windows is also fine.

Looking forward to hearing from you all.

46 Comments
2024/10/22
04:54 UTC

2

Issue in color conversation using ghostscrript

Hi all, in my application, I am using Ghostscript to convert RGB to CMYK in a PDF. The conversion works, but I can't control the CMYK values from the RGB input. For example, the expected black CMYK value is 0/0/0/100, but the actual values are different. Does anyone have an idea on how to control this from HTML, or know of any plugin that can control the CMYK values? Alternatively, is there a way to control Ghostscript directly

0 Comments
2024/10/20
17:56 UTC

0

What’s the difference between Visual Basic and C?

9 Comments
2024/10/19
04:48 UTC

2

Trying to draw lines in a picture control

Nothing happens. Scale is in twips. picMain is the picture control. It should draw an horizontal line in the middle.

Private Sub Form_Load()
    x1 = PixelCoordX(picMain.Width, 50, -50, 100)
    y1 = PixelCoordY(picMain.Height, 50, 0, 100)
    x2 = PixelCoordX(picMain.Width, 50, 50, 100)
    y2 = PixelCoordY(picMain.Height, 50, 0, 100)
    DrawLine picMain, x1,  y1, x2, y2
End Sub

Function PixelCoordX(PictWidth, OffsetX, xCoord, FOVx)
    PixelCoordX = PictWidth * ((OffsetX + xCoord) / FOVx)
End Function

Function PixelCoordY(PictHeight, OffsetY, yCoord, FOVy)
    PixelCoordY = PictHeight * ((OffsetY + yCoord) / FOVy)
End Function

Function xCoord(PixelCoordX, PictWidth, FOVx, OffsetX)
    xCoord = PixelCoordX / PictWidth * FOVx - OffsetX
End Function

Function yCoord(PixelCoordY, PictHeight, FOVy, OffsetY)
    yCoord = PixelCoordY / PictHeight * FOVy - OffsetY
End Function

Sub DrawLine(object, x1, y1, x2, y2)
    Debug.Print x1, y1, x2, y2
    object.Line (x1, y1)-(x2, y2), RGB(0, 0, 0)
End Sub
1 Comment
2024/10/13
21:04 UTC

3

VB5 on Win98. How do I code DirectX stuff? Graphics and sound

I have been wondering how do I code two simple rotating pyramids in VB5 while playing some audio. I want to learn to code games. I am using enterprise edition. Help and books online show nothing about directx usage. Dxdiag shows DirectX 9.0c

24 Comments
2024/10/13
19:59 UTC

2

Looking for someone in Arizona that can help me install VB 6 on my laptop.

I live in Casa Grande, AZ. Looking for someone who can help me get VB 6 installed on my laptop.

7 Comments
2024/09/30
20:00 UTC

3

Looking for help with a vb6 project

A client has a VB6 project that they want to make some changes to. After I installed Visual Studios on my laptop, I realized that it would not work on this project. I think I need to install VB6. I went to source forge but not sure what to install. Need some help with what to install and uninstall on my laptop.

23 Comments
2024/09/29
02:42 UTC

Back To Top