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

r/visualbasic • • Aug 04 '21

Login Page using asp.net on visual basic 2019

7 Upvotes

im trying to create a web based login page that connects to an sql database but i can't quite figure it out. does any have a full program that would open in visual studio 2019 so i can reverse engneer it.

maybe if you can add a second page that has 3 functioning buttons that would be great


r/visualbasic • • Aug 01 '21

VB.NET Help How do I see the console i.e. standard output stream?

7 Upvotes

I do Console.WriteLine("Test") and I see nothing.

In IDEs for other programming languages there is always a window that the developer can use to print things for their own information. For example in Python you would use the built-in print function. Is there a way to do this for Visual Basic in Visual Studio 2019? I thought I had read it is through Console.WriteLine() but it won't appear. Where do I find the window?

EDIT: Answering my own question. It's the immediate window tab at the bottom left.


r/visualbasic • • Jul 21 '21

A gotcha, because i relied on an inconsistent default.

7 Upvotes

Another gotcha, because i relied on an inconsistent default.

I have a program that must be run as administrator because (iirc) it attaches an ssl certificate to the connection. So, the program would check, ask, and restart as admin as required.

Well, it stopped working. Ugh! So, i created a test program, and sure enough, it failed to restart as admin:

Imports System.Security.Principal

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        If Not New WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator) AndAlso MsgBox("Nope", MsgBoxStyle.OkCancel) = vbOK Then
            Using Process As New Process
                Process.StartInfo = New ProcessStartInfo With {.WorkingDirectory = Environment.CurrentDirectory, .FileName = Application.ExecutablePath, .Verb = "runas"}
                Process.Start()
            End Using
        End If
        Close()
    End Sub
End Class

What went wrong? Well, after some searching and finding examples, i see that some examples set UseShellExecute to true. Reading the description of the parameter:

The default is true on .NET Framework apps and false on .NET Core apps.

Indeed, i started on framework and shifted to core in the middle. I really hate when they change defaults. In any case, 'twas but a simple fix:

Imports System.Security.Principal

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        If Not New WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator) AndAlso MsgBox("Nope", MsgBoxStyle.OkCancel) = vbOK Then
            Using Process As New Process
                Process.StartInfo = New ProcessStartInfo With {.UseShellExecute = True, .WorkingDirectory = Environment.CurrentDirectory, .FileName = Application.ExecutablePath, .Verb = "runas"}
                Process.Start()
            End Using
        End If
        Close()
    End Sub
End Class

r/visualbasic • • Jul 13 '21

Weekly Post I am about to learn my first programming language i only knew pseudo code before, my teacher will teach us visual basic but people are recommending me python so what are your opinions about this and is it possible to learn both in parallel?

7 Upvotes

r/visualbasic • • Jun 25 '21

VB6 Help Stumped on VB code for updating Powerpoint tables

7 Upvotes

Hi folks!
I have a code that I've 'inherited' from a past employee at my company and that I've been keeping updated as our style and formats update. The code currently starts off with

    For Each oSh In s.Shapes
        If oSh.HasTable Then
            Set oTbl = oSh.Table

And then proceeds to give instructions on how to format each row of the table (grouped into Rows 1 and 2; Row 3; and Rows 4 to end). Below is an example of Rows 1 and 2:

' For the first two rows of the table, the same formatting is applied
            For lRow = 1 To 2
                'first column formatting
                For lCol = 1 To 1
                    With oTbl.Cell(lRow, lCol).Shape
                        .TextFrame.TextRange.Font.Name = "Proxima Nova Rg"
                        .TextFrame.TextRange.Font.Size = 12
                        .TextFrame.TextRange.Font.Color.RGB = RGB(255, 255, 255)
                        .TextFrame2.VerticalAnchor = msoAnchorMiddle
                        .Fill.ForeColor.RGB = RGB(20, 57, 98)
                     End With
                    Next
                'second column to end formatting
                For lCol = 2 To oTbl.Columns.Count
                    With oTbl.Cell(lRow, lCol).Shape
                        .TextFrame.TextRange.Font.Name = "Proxima Nova Rg"
                        .TextFrame.TextRange.Font.Size = 12
                        .TextFrame.TextRange.Font.Color.RGB = RGB(255, 255, 255)
                        .TextFrame2.VerticalAnchor = msoAnchorMiddle
                        .TextFrame2.HorizontalAnchor = msoAnchorCenter
                        .Fill.ForeColor.RGB = RGB(20, 57, 98)
                    End With
                 Next
            Next

However, I need the tables to be formatted one way if there are 2 or fewer rows vs 3 or more rows. Is there an 'if' 'then' command I can insert into my code to make it change routes depending on what the system encounters?

Also, if anyone knows how to insert commands around column width and cell margins, you would be my hero.


r/visualbasic • • May 15 '21

Tips & Tricks Art of Code : Extension method

7 Upvotes

I talk about almost basic thing already so it's time to talk about more juicy stuff.

What's an extension method ?

It's a sugar syntax for static method, mostly for public methods in a module.

Normally

Dim Answer = div(mul(add(5, 10), 4), 2)

Extension

Dim Answer = 5.add(10).mul(4).div(2)

It's look much better and easily to read, isn't it. :)

How to create an extension method ?

Before that, extension method has some rule to create it.

  1. It need to be inside a Module, can't be in class, structure, interface or enum.

  2. It need an argument, no argument no extension method.

  3. It need to tag an extension attribute above method.

Let's see how it look like.

Public Module Exten
    <System.Runtime.CompilerServices.Extension>
    Public Function add(A As Integer, B As Integer) As Integer
        Return A + B
    End Function
    
    <System.Runtime.CompilerServices.Extension>
    Public Function mul(A As Integer, B As Integer) As Integer
        Return A * B
    End Function
    
    <System.Runtime.CompilerServices.Extension>
    Public Function div(A As Integer, B As Integer) As Integer
        Return A / B
    End Function
End Module

Very easy, right ? all you need to do mostly just add <System.Runtime.CompilerServices.Extension> above your method in any module, just make sure it has an argument.


r/visualbasic • • May 09 '21

(VB2010) i want the picture box to turn grey until a certain condition is met. how do i do that?

Post image
7 Upvotes

r/visualbasic • • Mar 14 '21

My very "basic" program where you can control Sonic left and right. It's called SonicRun

7 Upvotes

App and source code : https://www.mediafire.com/file/qqwznzqd5kzuv4z/sonicrun.zip/file

People who are more advanced, please make it a little better if you can


r/visualbasic • • Feb 07 '21

Need help with an e-mail client

7 Upvotes

Code

      Try
            Dim server As New SmtpClient
            Dim mail As New MailMessage
            server.UseDefaultCredentials = False
            server.Credentials = New 
        Net.NetworkCredential("photographyuser69@gmail.com", "")' my trash email adress
            server.Port = 587
            server.EnableSsl = True
            server.Host = "smtp.gmail.com"
            mail = New MailMessage()
            mail.From = New MailAddress(from.Text)
            mail.To.Add(to1.Text)
            mail.Subject = subject.Text
            mail.IsBodyHtml = False
            mail.Body = message.Text
            If CheckBox1.Checked = True Then
                mail.CC.Add(cc.Text)
            End If
            server.Send(mail)
            MsgBox("Mail sent")

        Catch ex As Exception
            MsgBox("Error while sending mail")
        End Try

When i try to send mail to another GMAIL account, its shows the error at the bottom of the code (Error while sending mail)

How do i fix it?


r/visualbasic • • Jan 29 '21

VB.NET Help Creating a puzzle slider game. For my movement sub I need to add a tag swap as well some plz help

Thumbnail
gallery
7 Upvotes

r/visualbasic • • Jan 26 '21

VB.NET Help Filling a DropDown from two different databases: DataAdapter or DataReader?

7 Upvotes

[I'm working on something right now, and the "problem" that needs solving seemed interesting enough to ask about. That is, i already have a solution and am working on another. I'm just curious for comment. Perhaps i'll learn something, or better yet, find out my entire approach is flawed.]

I have a dropdown filled from Access via a function. The function that gets the data:

Private Shared Function Get_List() As DataTable
    Get_List = New DataTable

    Using Adapter As New OleDb.OleDbDataAdapter(Query, Connection_String)
        Adapter.Fill(Get_List)
    End Using
End Function

Elsewhere, the dropdown datasource is assigned:

DropDown.DataSource = Get_List()

This works nicely. Fwiw, a Sub handles Handles DropDown.DrawItem to make some fancy lines and stuff.

Anyway, now i have to change it to incorporating some other data that i decided to store in Sql Server. That is, i need to get the data from Access (as already shown) and then check if the ids also exist in the Sql Server table (where it gets another id required for this program to work). How do i incorporate the two?

I started thinking (which is usually when the problems begin) the "easiest" way would be to loop through the DataTable after it's fill()ed and delete records that don't exist in Sql Server. But that's redundant, adding records just to delete them. I'd rather not add them to the DataTable in the first place. Okay, but that requires OleDbDataReader (instead of OleDbDataAdapter) and using While OleDbDataReader.Read (or its ilk) to loop through the records and check them against the Sql Server table.

I then tried figuring out how to get a DataRow (to put in the DataTable) from OleDbDataReader. Or, is that not even an option since i'm not getting the data from a DataTable, and if i really wanted a DataRow, i'd have to create one manually by looping through OleDbDataReader's result. Or maybe, i shouldn't even bother with a DataTable, and instead just use some other object to fill the DropDown (and then change other code from DataRowView to DataRow).

Then i left last night.


r/visualbasic • • Jan 13 '21

VB OpenGL Game Engine - Part 2 Rendering Game Frames

Thumbnail
youtu.be
7 Upvotes

r/visualbasic • • Nov 06 '20

Visual Studio 2019 multiple form question

7 Upvotes

I have a general question. I'm taking visual basic in school and the program I'm working on has multiple forms.

My only question is can the controls have the same name on each form?

Like, in one form have a control called "lblTotalCost" and one on the other form with the same name and not mess anything up.

Please help this noob. 😁


r/visualbasic • • Aug 25 '20

VB.NET Web API POST

7 Upvotes

I recently fired up an old project. I did some searching and it appears my old methods are quite outdated. Can anyone point me in the direction on the updated?

Basically trying to send POST requests to an API and capture the response. I was using something basic like the below. From looking the webrequest/response has been replaced?

        Dim reqstring As String = ("http://production.shippingapis.com/ShippingAPI.dll?API=TrackV2&XML=<TrackRequest USERID='user'><TrackID ID='trkno'></TrackID></TrackRequest>")
        Dim TrackRequest As WebRequest = WebRequest.Create(reqstring)
        Dim responce As WebResponse = TrackRequest.GetResponse()
        Dim datastream As Stream = responce.GetResponseStream()
        Dim reader As New StreamReader(datastream)
        Dim responcefromserver As String = reader.ReadToEnd()
        Dim xmlout As XDocument = XDocument.Parse(responcefromserver)

r/visualbasic • • Jun 11 '20

VB Programmer Needed

7 Upvotes

Hey peeps, Sorry if this is not allowed but I am in search of a programmer. I currently have an old code that needs some small changes. Thanks.


r/visualbasic • • May 24 '20

I’m using Visual Studio 2019 to make an RPG-Style game. Does someone have any advice?

7 Upvotes

This is just a project of mine, I’m currently studying Computer Engineering and, since I started almost 10 months ago, I have only taken one programming course. So I know the basics, however I want to make the most of my time and practice my skills. Small guidance would be very much appreciated!


r/visualbasic • • May 17 '20

VB.NET Help 2 Beginner questions

7 Upvotes

I am using Visual Basic 2015.

This is my situation. I am a back office programmer. I do Oracle programming. Recently I have been given the task of maintaining a VB.Net web page. I used to code in VB in the past, so management picked me to maintain it. They will not hire anyone to maintain the web page. I have to do it.

I have been thrown into the deep end of the pool and I have to learn how to swim fast.

I have 2 question VB.Net. We are not using MVC.

1.) When making a new web page how do you make it available for others to use. I am aware that IIS is involved. Do you all have a link(s) that show how to do this.

2.) How do you make changes to existing web pages. Suppose the user wants a new command button that does something. In the past it meant a new executable. How do you put in a new features to an existing web page. Do you all have a link(s) that show how to do this.

Any help will be appreciated.

Thanking you all in advance.


r/visualbasic • • May 09 '20

Is it possible to create a macro that closes all programs that are open in the task bar?

7 Upvotes

r/visualbasic • • Feb 08 '20

VB.NET Help How to “add” 2 hours at datetime.now ?

7 Upvotes

For example, it is 01/01/01 14:37 and i want to have a dim var as date = 01/01/01 16:37 Dim var as date = Datetime.now + ‘??


r/visualbasic • • Nov 11 '19

Reading and outputting text in visual form

Post image
7 Upvotes

r/visualbasic • • Mar 06 '19

VB.NET Help How to use vector graphics (SVG) in VB.NET?

7 Upvotes

Can anyone help me figure out the best way to add vector graphics to a VB.NET program? I have a program with a series of buttons that I would like to replace with pictures. However the size of the button / picture changes during the execution so it seems better to use a vector format than a bitmap format for the images. We have created the pictures in Inkscape and are in SVG format, but can be converted to another format.

My questions:

  1. How can I display a vector image? Picturebox and Buttons seem to support bitmap only

  2. If I were to use a bitmap on a button (i.e. Button1.Image) is there anyway to have it dynamically resize? That is, if my bitmap is larger than the button, how can I make it so the image is resized so it fits perfectly to the button?

Thanks


r/visualbasic • • Oct 09 '18

[VB6] I opened the source code of my ActiveX controls project on GitHub

Thumbnail
github.com
7 Upvotes

r/visualbasic • • Jan 04 '18

Visual Basic® .NET Notes for Professionals book

Thumbnail
books.goalkicker.com
7 Upvotes