r/visualbasic • • May 04 '15

Discuss Please upvote the people are replying to your questions.

8 Upvotes

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 • • Dec 10 '14

Article New language features in VB14

Thumbnail
roslyn.codeplex.com
8 Upvotes

r/visualbasic • • Feb 21 '14

VB.NET Help File Operations - Part 1 "What file, where?"

8 Upvotes

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 Function

To implement this we used

Private Sub Form_Load()
	MsgBox FileExists("C:\file.txt")
End Sub

As 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

System.io.file

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 With

Next 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 • • Jun 18 '12

Listen up, Maggots...

Thumbnail
youtube.com
8 Upvotes

r/visualbasic • • Apr 26 '12

Black Jack VBA

8 Upvotes

Bored at work? Black Jack

Edit: New Version


r/visualbasic • • 29d ago

VB6 Help "CONFIGDRIVER: Unable to configure ODBC driver Microsoft Access Driver (*.mdb):" Problem during installation

Thumbnail
gallery
7 Upvotes

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 • • 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')

Post image
7 Upvotes

r/visualbasic • • Jul 04 '25

My first application

Thumbnail
gallery
7 Upvotes

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 • • Nov 06 '24

VB.NET Help Vb to mobile

7 Upvotes

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 • • Sep 26 '24

Whats the difference between my code and the correct code?

7 Upvotes

One says declaration error in visual studio but i already declared. in the coe before this

this is the correct one

If bmi < 18.5 Then

category = ("Underweight")

ElseIf bmi >= 18.5 And bmi < 24.9 Then

category = ("Healthy Weight")

ElseIf bmi >= 25 And bmi <= 29.9 Then

category = ("Overweight")

ElseIf bmi >= 30 Then

category = ("Obese")

End If

and this is my code

if bmi < 18.5 Then

category = ("underweight")

ElseIf bmi >= 18.5 And bmi < 24.9 Then

category = ("Healthy Weight")

ElseIf bmi >= 25 And bmi <= 29.9 Then

category = ("Overweight")

ElseIf bmi >= 30 And bmi Then

category = ("Obese")

End If


r/visualbasic • • Jul 02 '24

Tips & Tricks Still worth?

7 Upvotes

Hi,

I remember doing VB6 back in my elementary school (more than 20 years ago) and I was making cool apps with friends. Some of them are even still published at download com. I am now totally in different area of development for more than 15 years, but I'd like from time to time to make some cool VB6 apps again. I remember it was quite easy just to save project as .exe file and that's it, that's why I liked VB6 so much.

Is this still a thing now when we are at W10/W11 era? Do you recommend some other VB version and how to export apps as .exe simply as in VB6? Are there some alternatives?

Cheers!


r/visualbasic • • May 05 '23

Looking for Working Visual Basic Code to Send Email

7 Upvotes

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 • • Apr 05 '23

VB6 Help [VB6.0] Modifying forms using code and pass it to the design interface

7 Upvotes

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 • • Dec 21 '22

How to use VB6 on Windows 11?

7 Upvotes

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 • • Nov 29 '22

Visual Basic Program containing viruses (more info in comments)

Post image
7 Upvotes

r/visualbasic • • Oct 24 '22

Tips & Tricks Just learnt of DebuggerDisplay

7 Upvotes

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 Class

r/visualbasic • • Oct 20 '22

VB.NET Help Using a cloned HttpRequestMessage (with Content) results in ObjectDisposedException: Cannot access a closed Stream.

7 Upvotes

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 Sub

The 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 • • Sep 17 '22

VB.NET Help I need help !!! (Please Check Comment for more info about the problem)

7 Upvotes

r/visualbasic • • May 27 '22

VBScript Help with reading text file

7 Upvotes

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 • • May 15 '22

Free camping 'payment' project

7 Upvotes

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 • • Feb 22 '22

No idea how VB works, but I can't compile because of this error which was never a problem before

Post image
7 Upvotes

r/visualbasic • • Feb 17 '22

Looking to learn VB.net but a little overwhelmed...

7 Upvotes

Please can someone help suggest a place or course to start learning VB.net please.

I currently know PS and a few other object languages and would like to learn VB.net to improve my skills...

I am not looking to develop any application, but would like to learn about looping and functions etc.

Any help appreciated.

Thanks.


r/visualbasic • • Nov 14 '21

VB6 Help Please help me understand !!

7 Upvotes

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 • • Oct 28 '21

Happy Cakeday, r/visualbasic! Today you're 12

7 Upvotes

Let's look back at some memorable moments and interesting insights from last year.

Your top 10 posts:


r/visualbasic • • Oct 08 '21

Currently my company has an application in VB.NET 2010, and is wanting to set up a software development team to maintain it. Do you think it's possible? Or would it be better to migrate to a newer version of VB.NET or .NET Core?

7 Upvotes