r/visualbasic • u/jbohr • Jul 12 '15
r/visualbasic • u/Bonejob • May 04 '15
Discuss Please upvote the people are replying to your questions.
There is a lot of questions answered here on /r/visualbasic the least you can do is upvote the answers for those who put in the work.
<rant>I am getting pissed off about homework questions by the way. If you truly have tried to understand, I have no problems. But if it comes down to you have not read the material. I am going to start ignoring them.</rant>
r/visualbasic • u/tthomps • Dec 10 '14
Article New language features in VB14
r/visualbasic • u/Bonejob • Feb 21 '14
VB.NET Help File Operations - Part 1 "What file, where?"
In this post I am going to talk about File Operation in VB.NET. The Code Should work in all versions of .NET runtime
Back in the day when Visual Basic (The code below works in VB 3-6) was young we had to do back-flips to get simple information about files and folders. I used this code a lot for checking to see if a file existed;
In a standard Module: Module1.bas
Option Explicit
Private Const OF_EXIST As Long = &H4000
Private Const OFS_MAXPATHNAME As Long = 128
Private Const HFILE_ERROR As Long = -1
Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
Private Type OFSTRUCT
cBytes As Byte
fFixedDisk As Byte
nErrCode As Integer
Reserved1 As Integer
Reserved2 As Integer
szPathName(OFS_MAXPATHNAME) As Byte
End Type
Public Function FileExists(ByVal Fname As String) As Boolean
Dim lRetVal As Long
Dim OfSt As OFSTRUCT
lRetVal = OpenFile(Fname, OfSt, OF_EXIST)
If lRetVal <> HFILE_ERROR Then
FileExists = True
Else
FileExists = False
End If
End FunctionTo implement this we used
Private Sub Form_Load()
MsgBox FileExists("C:\file.txt")
End SubAs you can see we used the Kernal library to expose the OS functions. We had this compiled into a DLL that we included in all projects. If you want more information about Classic VB I would recomend this article over at Afralisp by Kenny Ramage. The article goes into details about directories and files.
Luckily in VB.NET we have the System.IO Namespace. This Namespace has all sorts of goodies in it for Creating, Opening, Manipulating, Deleting, Copying files and folders, getting parts of files, and much more.
NOTE: for these functions to work you either need to insert an application reference to the system.io namespace or import system.io at the top of your class
Lets start with the Simple Stuff;
Click the function name to go to the Microsoft documentation
With File :)
.Copy(SourceFileName,DestFileName,OverWrite) ' Paths are specific can not be a folder, must include filename. Overwrite is a boolean that determines if it is ok to replace the file on copy.
.Delete(path) ' Deletes specified file will throw exception if path is wrong, file is locked or not found.
.Exists(path) ' Returns boolean, must be exact match to a single file. Invalid path returns False
.Move(SourcePath,DestPath) 'Throws IO exception of the Destination exists or if source not found. IF you move a file that is in use the file is copied but the source is not removed.
'Here are some of the more complex ones.
GetAccessControl(FilePath) Gets a [FileSecurity](http://msdn.microsoft.com/en-us/library/8e1fc3b8.aspx) object that access control list for a specified file. Used to find out about a networks users capacity for a specific file.
GetAttributes(FilePath) Gets the FileAttributes of the file on the path.
' I included only the UTC versions of the these function the localized versions exist, but you should always use utc and convert based upon local timezone that way if you get users in diffrent timezones it deals with it autmoatically.
GetCreationTimeUtc(FilePath) Returns the creation date and time, in coordinated universal time (UTC), of the specified file or directory.
GetLastAccessTimeUtc(FilePath) Returns the date and time, in coordinated universal time (UTC), that the specified file or directory was last accessed.
GetLastWriteTimeUtc(FilePath) Returns the date and time, in coordinated universal time (UTC), that the specified file or directory was last written to.
'All of these have the equivalent set function as well.
End WithNext post we will talk about Implementing file functions that do all of your heavy lifting to add to your bag of tricks.
-Bone
r/visualbasic • u/eight26 • Apr 26 '12
Black Jack VBA
Bored at work? Black Jack
Edit: New Version
r/visualbasic • u/Acceptable_Ad664 • Oct 26 '26
VB6 Help "CONFIGDRIVER: Unable to configure ODBC driver Microsoft Access Driver (*.mdb):" Problem during installation
I have been trying for days to install Visual Basic 6 on my Windows 11 laptop for a university assignment, but when I use "acmsetup" to complete the installation, an error occurs, making it impossible to install.
I’ve seen tutorials on YouTube and in forums for installing VB6, but no one else has encountered this error. What should I do?
r/visualbasic • u/WorldlinessSlow9893 • Dec 16 '25
Made my custom WORKING FilePicker/Dialog on Visual Basic! (So after you for exp. press "Open" in mspaint, notepad,... it will show up this dialog instead of Windows')
r/visualbasic • u/MyWifesTTsRSmol • Jul 04 '25
My first application
Making this basic dumb little program is one of my greatest accomplishments so far, but I can't take all the credit unfortunately. I had a good amount of help from ChatGPT. I run through Operating Systems often so I wanted a way to grab the programs that I needed to be installed and a wallpaper that I would set automatically and it fully works and does exactly what I needed it to. next up is having it autogenerate a batch script to autorun all programs from the apps folder
r/visualbasic • u/Patow143 • Nov 06 '24
VB.NET Help 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!
r/visualbasic • u/Kuba_Z2 • Aug 22 '24
Meet Sharp: A Discord Bot for Running and Decompiling .NET Languages!
Hey everyone,
I wanted to share a tool I have been working on that I think could be useful for the .NET community here. It’s called Sharp, and it’s a Discord bot that allows you to run .NET languages, view JIT disassembly, and decompile code directly within Discord itself. No more jumping between third-party websites and Discord to share your code and results!
Sharp supports C#, Visual Basic.NET, F#, and IL. It also lets you run your code and view JIT disassembly for both x64 and ARM64 architectures.
The bot is verified and is open source. You can find the GitHub repository with all the details and instructions here: https://github.com/KubaZ2/Sharp.
If you’re looking for a more streamlined way to work with .NET languages in Discord, give Sharp a try and let me know what you think!
r/visualbasic • u/Firm-Analysis-790 • May 05 '23
Looking for Working Visual Basic Code to Send Email
I am new to this this. I am looking for Visual Basic 2005 or 2010 code that can send Email. I want to include it in my programming I have older code that used a Gmail account, but that has been blocked from working since May of 2022. So you many need to suggest an email server that works with your code. Ron Gerard
r/visualbasic • u/Gjcerda • Apr 05 '23
VB6 Help [VB6.0] Modifying forms using code and pass it to the design interface
I was handled a project with 280 different forms where we need to change the colors and font properties of all forms. I decided to make a subprocess that can do this called Color_form and it works good, but now I would also like to see the change reflected in the design interface instead of just once the project is up.
Right now I'm having Color_form to be executed as the first line inside the Form_Load subprocess, but I would like to be able to execute them in a way that changes the design interface permanently. This way when someone else takes the project what they see there it matches with what I have in code.
Anyone has any idea on how to do this?
r/visualbasic • u/[deleted] • Dec 21 '22
How to use VB6 on Windows 11?
Hey sorry if this question has been asked before.
I know the vb6 ide is no longer supported, but the language is still supported on windows 11. Any recommendations for how to use Vb6 if the ide isn't supported? Do you just not use an ide?
r/visualbasic • u/ariebe9115 • Nov 29 '22
Visual Basic Program containing viruses (more info in comments)
r/visualbasic • u/chacham2 • Oct 24 '22
Tips & Tricks Just learnt of DebuggerDisplay
I just learnt of DebuggerDisplay (example usage) from Nick Chapsas' latest video Controlling your debugging experience in C#. Basically, it allows you to put information into the display when you mouseover an object.
Here's an example project to see it in action:
Public Class Form1
<DebuggerDisplay("B: {B}")>
Private Class A
Public B As Integer
Public Sub New(C As Integer)
B = C
End Sub
End Class
Private Sub Form1_Load(Sender As Object, Arguments As EventArgs) Handles MyBase.Load
Dim a As New A(25)
Stop
End Sub
End Classr/visualbasic • u/mortaltree • Oct 21 '22
VB6 Help VB6 IDE improvements?
Hey friends. I’m using VB6 and basically the standard IDE. Are there any better IDE’s in use by the community? I hate the lack of intellisense and things like loop/bracket closure markers. Am I doomed?
r/visualbasic • u/chacham2 • Oct 20 '22
VB.NET Help Using a cloned HttpRequestMessage (with Content) results in ObjectDisposedException: Cannot access a closed Stream.
I'm trying to implement retries on a webrequest. FedEx's test server has a lot of errors, which forces you to write better code. :) The issue is that HttpRequestMessages cannot be reused. So, you have to clone it. Cloning headers and options is straight forward, but cloning the content requires reading the content stream and creating a new one. That adds a little complexity, but seems doable. However, on retries that include content i am receiving: ObjectDisposedException: Cannot access a closed Stream.
My code is currently:
Friend Async Function Get_Server_Response(Request As HttpRequestMessage, Log_Header As String, Log_Message As String) As Task(Of Server_Response)
' Get's response from server, including a retry policy. (Note: Not using Polly, see Readme.)
Const Max_Tries As Integer = 5
Dim Response_Text As String
Debug_Request(Request)
For Counter As Integer = 1 To Max_Tries
Log.Debug("({Log_Header}) Connecting for: {Description} (Attempt {Counter})", Log_Header, Log_Message, Counter)
Using Response As HttpResponseMessage = Await Http_Client.SendAsync(Request, Cancellation_Token)
' On a fail, retry (a limited amount of times). (BadRequest is returned by FedEx sometimes, when requesting the SPoD.)
If Counter < Max_Tries AndAlso Response.StatusCode <> Net.HttpStatusCode.OK AndAlso Response.StatusCode <> Net.HttpStatusCode.Unauthorized Then
Log.Debug("({Log_Header}) Connect failed (Status Code: {StatusCode}). Delaying {Counter} second(s) before trying again.",
{Log_Header, Response.StatusCode, Counter})
' Requests cannot be reused, so we'll get a new one by cloning the old one.
Request = Await Clone_HttpRequestMessage(Request).ConfigureAwait(False)
' Pause a little longer with each retry.
Await Task.Delay(1000 * Counter)
Continue For
End If
' Send the response back (even if it is a failure).
Using Response_Content As HttpContent = Response.Content
Response_Text = Await Response_Content.ReadAsStringAsync
Log.Debug("({Log_Header}) Status Code: {Status}", Log_Header, Response.StatusCode)
Log.Debug("({Log_Header}) Body: {Text}", Log_Header, Response_Text)
Return New Server_Response With {.Status_Code = Response.StatusCode, .Text = Response_Text}
End Using
End Using
Next
Return Nothing
End Function
Public Async Function Clone_HttpRequestMessage(Request As HttpRequestMessage) As Task(Of HttpRequestMessage)
Dim New_Request As New HttpRequestMessage() With {.Method = Request.Method, .Version = Request.Version, .VersionPolicy = Request.VersionPolicy, .RequestUri = Request.RequestUri}
' Content has to copy the content itself.
With Request
If .Content IsNot Nothing Then
Using Stream As New IO.MemoryStream()
Await .Content.CopyToAsync(Stream).ConfigureAwait(False)
Stream.Position = 0
New_Request.Content = New StreamContent(Stream)
For Each Header In .Content.Headers
Select Case Header.Key
Case "Content-Type"
' Content Type cannot be added directly.
For Each Type In Header.Value
New_Request.Headers.Accept.ParseAdd(Type)
Next
Case "Content-Length"
' Set automatically. (Throws exception if added manually.)
Case Else
For Each Header_Value In Header.Value
New_Request.Content.Headers.TryAddWithoutValidation(Header.Key, Header_Value)
Next
End Select
Next
End Using
End If
For Each Opt In .Options
New_Request.Options.TryAdd(Opt.Key, Opt.Value)
Next
For Each Header In .Headers
New_Request.Headers.TryAddWithoutValidation(Header.Key, Header.Value)
Next
' The old request is now redundant.
.Dispose()
End With
Return New_Request
End Function
Private Async Sub Debug_Request(Request As HttpRequestMessage)
Debug.WriteLine(String.Empty)
Debug.WriteLine("-------------------------------------------------------------------------")
Debug.WriteLine("[Debug Request]")
Debug.WriteLine("-------------------------------------------------------------------------")
With Request
Debug.WriteLine($"Endpoint: { .RequestUri}")
For Each Header In .Headers
For Each Value In Header.Value
Debug.WriteLine($"(Header) {Header.Key}: {Value}")
Next
Next
For Each Opt In .Options
Debug.WriteLine($"(Option) {Opt.Key}: {Opt.Value}")
Next
If .Content IsNot Nothing Then
Using Stream As New IO.MemoryStream()
For Each Header In .Content.Headers
For Each Value In Header.Value
Debug.WriteLine($"(Content Header) {Header.Key}: {Value}")
Next
Next
Debug.WriteLine($"Content: {Await .Content.ReadAsStringAsync()}")
End Using
End If
End With
Debug.WriteLine("-------------------------------------------------------------------------")
End SubThe error crops up on a retry (when there is content) at:
Using Response As HttpResponseMessage = Await Http_Client.SendAsync(Request, Cancellation_Token)
Fwiw, commenting out .Dispose() does nothing. This is expected, as it is disposing the old request, which is no longer being used.
What am i doing wrong?
r/visualbasic • u/Main_Evidence_1331 • Sep 17 '22
VB.NET Help I need help !!! (Please Check Comment for more info about the problem)
r/visualbasic • u/Reapers_Mask • May 27 '22
VBScript Help with reading text file
So I am creating a program that edits a text file, and then reads a specific line of the text file. So far, I have 2 options:
1: Read a specific file line, which I need help understanding how to do.
2: Read a line that starts with a specific string/group of numbers and letters. Each line has a little identifier string at the start, so all I need is a way to check if the line starts with the string.
Sorry if this is too little information, I can give more info if needed.
r/visualbasic • u/InvestigatorOwn6817 • May 15 '22
Free camping 'payment' project
My uncle and I created a mini free camping 'payment' system and a Ebook If you want to have a look at it: https://dorethy.eu/ For the code: https://github.com/Johan684/Dorethy
r/visualbasic • u/Artfull-Mystery • Dec 18 '21
VB.NET Help What Happens if code is running in a timer event and another timer event happens
Do they run concurrently in different threads or does the second event wait till the first event has finished.
Thanks
Mike
r/visualbasic • u/Super-Youth • Nov 14 '21
VB6 Help Please help me understand !!
I’m doing a question sheet to get the output for some code. I put the code into a compiler and it prints hello sixty times but I don’t exactly understand why….
For x = 0 To 100 For y = 5 To -10 step -1 If y = 0 Then Exit For End If Console.Write("Hello") Next If x > 10 Then Exit For End If Next
r/visualbasic • u/AutoModerator • Oct 28 '21
Happy Cakeday, r/visualbasic! Today you're 12
Let's look back at some memorable moments and interesting insights from last year.
Your top 10 posts:
"Dark Year, vb6 project. Moving onto c++ now and this is my last vb6 prj ever, tentatively. I hope some people like it, 35+k lines of code. I'm not sure it's what I initially intended, nevertheless.." by u/DarkYearGamer
"Been working on this game for a span of 15 years now. And it's now nearing completion!" by u/PT_William
"Hello guys, l am the author of this book called Visual Basics Programming Solutions and l made this book because l am very passionate about programming especially with visual basics.So l was wondering if you could check it out and tell me your comments.I have made the book free on Amazon so that you" by u/Pleasant_Chef3798
"Top 10 Most Popular Programming Languages (PYPL) - 2004 / October 2020"
"Visual Basic WinForms Apps in .NET 5 and Visual Studio 16.8" by u/ben_a_adams
"Im making this with a custom VB6 dib/dma "engine" , its about 6-7 months in now. Im just hoping to get a little input atm and/or ideas etc…" by u/DarkYearGamer
"Mercury: A modern Visual Basic, with a future, parity with C#, and support for more target platforms." by u/dwarfland
"I need to make a program that works kinda like a coinstar. So I would be able to enter a certain amount of coins and then be able to see my change in dollars quarters, etc. Any leads or something would help me" by u/DDDevise