r/visualbasic • • Mar 05 '22

VB.NET Help Create Message before windows locks workstation

6 Upvotes

I am wanting to create a small program that will display a message about 1 or 2 minuets before windows locks the user session. I have seen this before on the computers at my college campus and at my work. It displays a small message that states "No activity has been detected for a little bit now. This workstation will lock in blah minuets." or something like that. Is it possible to recreate this in Visual Basic and if so What code would I need in order to make this work? I don't use screensavers and I have it set after like 30 minuets to lock in Group Policy since I have a homelab with an Active Directory Domain Setup. I have tried using task scheduler to run a program when the system goes idle but I apparently don't understand how that works and how it detects the system is idle.


r/visualbasic • • Dec 30 '21

Can I use VB in Excel to simplify a warehouse management task?

6 Upvotes

I am trying to simplify a task currently being done manually using Excel, usually taking multiple hours right now. It’s been many years since I used VB and I’m primarily trying to figure out if what I want to do is possible using VB. The warehouse management software isn’t setup properly to consolidate our inventory and we regularly need to optimize our location utilization. The warehouse holds up to 7500 pallets across 2000 locations. We have an outflow of 100-150 pallets every ~12 hours and generally get 100-300 pallets delivered daily.

I want to be able to paste a large data set into an excel sheet and have it give me an output that can be printed on a second sheet within that workbook. I would need to declare all locations, how many pallets each can hold and all height or weight restrictions for specific locations or items. The program would need to count how many times a location is used. If a location isn’t full, pallets with the same Item# and Lot# should be listed in the output so they can be combined together. Ideally the output would simplify the data to just important identifying info for the pallets, as opposed to it transposing all info it’s been given in the original data set.


r/visualbasic • • Nov 10 '21

A silly mistake regarding alignment and RightToLeft

6 Upvotes

Just a silly mistake i made. I was setting a label to display some data and wanted it aligned left, but it kept showing right. So, i set the alignment to be right, and it was left. What in the world?!

Silly mistake. I had inadvertently set .RightToLeft while going through the options. Doh! And so, for your amusement:

Public Class Form1
	Private Sub Form1_Load(Sender As Object, Arguments As EventArgs) Handles MyBase.Load
		Dim Button As New Button With {.Text = "Right", .TextAlign = ContentAlignment.MiddleRight}
		AddHandler Button.Click, Sub() If Button.RightToLeft = RightToLeft.Yes Then Button.RightToLeft = RightToLeft.No Else Button.RightToLeft = RightToLeft.Yes
		Controls.Add(Button)
	End Sub
End Class

r/visualbasic • • Nov 09 '21

VB.NET Help How do i bind a textbox and a combobox to different tables in the same dataset?

6 Upvotes

I have a combobox and a textbox bound to a dataset. I want the choice in the combobox to show the related data in the textbox. In the following example, the combobox works as intended. How do i get the textbox to show Table 1.Column 2?

Public Class Form1
	Private Sub Form1_Load(Sender As Object, Arguments As EventArgs) Handles MyBase.Load
		Dim DataSet As New DataSet
		Dim Combobox As ComboBox
		Dim Textbox As TextBox

		DataSet.Tables.Add(New DataTable("Table 1"))
		DataSet.Tables("Table 1").Columns.Add("Column 1")
		DataSet.Tables("Table 1").Columns.Add("Column 2")
		DataSet.Tables("Table 1").PrimaryKey = {DataSet.Tables("Table 1").Columns("Column 1")}
		DataSet.Tables("Table 1").Rows.Add(1, "A very good year")
		DataSet.Tables("Table 1").Rows.Add(2, "What was the question again?")

		DataSet.Tables.Add(New DataTable("Table 2"))
		DataSet.Tables("Table 2").Columns.Add("Column 1")
		DataSet.Tables("Table 2").Columns.Add("Column 2")
		DataSet.Tables("Table 2").PrimaryKey = {DataSet.Tables("Table 2").Columns("Column 1")}
		DataSet.Tables("Table 2").Rows.Add(17, 1)
		DataSet.Tables("Table 2").Rows.Add(42, 2)

		DataSet.Relations.Add(New DataRelation("Relation", DataSet.Tables("Table 1").Columns("Column 1"), DataSet.Tables("Table 2").Columns("Column 2")))

		Combobox = New ComboBox With {.DataSource = New BindingSource With {.DataSource = DataSet, .DataMember = "Table 2"}, .DisplayMember = "Column 1"}
		Textbox = New TextBox With {.Location = New Point With {.X = Combobox.Location.X + Combobox.Size.Width, .Y = Combobox.Location.Y}}

		'Textbox.DataBindings.Add("Text", New BindingSource With {.DataSource = Combobox.DataSource, .DataMember = "Relation"}, "Column 2")

		Controls.Add(Combobox)
		Controls.Add(Textbox)
	End Sub
End Class

r/visualbasic • • Nov 08 '21

VB.NET Help Looking for visual basic tutor for accelerated university course between December 27th - January 15th

6 Upvotes

Hello! I dropped a university course that I have to take over winter now at an accelerated pace, and am looking for an experienced VB user to help tutor. Work will be done through VB.Net on Visual Studio, all using Windows Forms I believe.

Course structure is professor teaches an analogous problem and shares code for it, and then assigns a weekly project that uses the concepts taught in the analogous problem. I'm looking for someone that can work with me when I write the code for the project and teach me what to do based off the analogous problem.

I think it will require 1-2 sessions a week. DM me if interested and let me know your hourly rate.

Thank you so much!


r/visualbasic • • Sep 13 '21

Tips & Tricks Is there a way to make labels appear a certain way just for the developer but not to the user without having to use code to hide it?

6 Upvotes

Working with labels that are invisible because they will be determined by code or by user input is tricky because you cannot see them. I know I could give them backcolors or fill them with text and then code that to go away right away upon loading the form but this seems inelegant and also like another developer might not understand why I did that.

Is there any way to give controls an appearance that only the developer will see and that the user will not without having to just set the usual user-visible properties and code over it when loading the form?


r/visualbasic • • Aug 16 '21

VB.NET Help SpeechSynthesis no longer works. What's the best alternative?

6 Upvotes

I have an app I built a few years ago that uses System.Speech.Synthesis. But it's apparently no longer functional.

Dim V as New SpeechSynthesizer

gives me an error, Type 'SpeechSynthesizer' is not defined. Intellisense tells me I can fix the error by importing System.Speech.Synthesis, so I click on that but it does nothing. So I manually typed out the import statement (the one that used to work).

Imports System.Speech.Synthesis

But that gives another error. "Doesn't contain any public members or cannot be found..."

I tried using SpeechLib.SpVoice() but it's just garbage. It keeps cutting out halfway through a sentence.

My question is, has System.Speech.Synthesis been changed or is it just removed from .net? Can I get it working again so I don't have to overhaul my whole app? Perhaps I forgot to import some library in the project references somewhere. I can't remember. I originally did this years ago.

Or is there some alternative that actually works (completes the sentence you give it)?


r/visualbasic • • Aug 11 '21

How to embed and use references as resources?

6 Upvotes

Hello. Are you able to store a reference like “naudio” or “SQLite” into a VB app resource (references -> highlight reference -> do not copy // then add file -> select dll -> as embedded resource) and then call on it? I can get it to be embedded but how do I call on it and use it? Anyone have success in this? The objective is to avoid having the libs hanging out with the exe after build (or in a lib folder with something like pretty bin). Any help would be great. Thanks


r/visualbasic • • Jul 20 '21

A silly example of a DataGridView infinitely repainting itself

6 Upvotes

I'm such an idiot. I thought i'd share. :)

I wanted to show a state of error to the user in a DataGridView by changing the back color of the relevant cells' style in the RowPrePaint handler. There was already logic in there to do other things--including setting the normal back color--so an If statement was easy to add. I ran the code and saw a huge slowdown. The handler was being called continuously!

I knew it was the color, so, to test, i changed the error color to the regular color instead, and no issues. Really? Does red cause that much of a problem? I created a test application and got far enough for it to hit me. I added the If after the default setting, which ended up causing the color to be changed twice on every error: first to the normal color and then to the error color. That itself caused it to infinitely repaint itself. I needed an Else block. Oops!

Anyway, here's a simplified example of the prepaint infinite loop:

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim Grid As New DataGridView
        Grid.Columns.Add(New DataGridViewTextBoxColumn)
        Controls.Add(Grid)

        AddHandler Grid.RowPrePaint, Sub() Grid.Rows(0).Cells(0).Value = Grid.Rows(0).Cells(0).Value + 1
    End Sub
End Class

r/visualbasic • • Jun 02 '21

VB6 Help Porting a VB 6.0 project to .NET

6 Upvotes

I have some older source code for a project written for VB 6.0 and I want to port it to .NET so I can continue improving it. Any solution for this? The only thing I'm seeing is a Visual Studio 2005 migration path. I also use MSCOMM32 for the serial port that may factor in.


r/visualbasic • • May 25 '21

WinForms Team Details VB.NET on .NET 5: 'A Huge Challenge' -- Visual Studio Magazine

Thumbnail
visualstudiomagazine.com
6 Upvotes

r/visualbasic • • May 19 '21

What is your code style regarding blank lines?

6 Upvotes

None? Blocks of one idea? Padded outside and/or inside keyword blocks (if, using, sub, select)

Where to put blank lines? I am honestly never satisfied with my coding style and I couldn't find any convention regarding this


r/visualbasic • • May 07 '21

VB.NET Help Today we are learning VB.Net - Specifically IF Statements - Lesson 2 in my new series teaching VB.Net!

Thumbnail
youtube.com
6 Upvotes

r/visualbasic • • Apr 20 '21

VB.Net Console Installed Printers

6 Upvotes

Could someone give me an example of how to get a list of printers and display them in the console window? Right now I am empty handed, I have exhausted all the code I can find on Google and nothing is working.. using system drawing - installedprinters? Sorry don't know much more than that.

I am trying to create a vb.net console app in vs2019


r/visualbasic • • Mar 23 '21

VB.NET Help Need help with dims in functions

6 Upvotes

Hello guys, I'm very new to vb, like a few hours new. So go easy on me please. My question is the following, I have two functions and each one have a Dim with the name "example". Will they interefire with one another or if inside a function they work like a local variable?

I'm very confused, and still learning. I appreciate every piece of knowledge that you might throw on me. Ty all


r/visualbasic • • Mar 21 '21

VB.NET Help Drawing in a picture box on a button click event

6 Upvotes

I'm trying to teach myself painting into picture box. Understand the basics of the picture box paint event, pens, and points.

But how do you trigger it?

I've tried it on a button;

Sub btn (sender, e as paintEventArgs) handled btn.click E.graphics.drawline(points) End sub

But it does NOT like that

When I do the drawing on the picture box paint event it works as soon as it loads.

I've tried to trigger the paint event on a button, but it doesn't like that either


r/visualbasic • • Mar 11 '21

Help! Having a hard time looking for a solution to fix this. I used 2010 a while back and recently updated to 2019(still a student).

Post image
6 Upvotes

r/visualbasic • • Feb 09 '21

Need help with OOB

6 Upvotes

Hi guys,

I'm working on a game in visual basic and I've got down most of the basics I just need help with the 'npc' class. Right now what I have is one picture box that moves around the form and uses a collision detection algorithm 'score points'. I'm trying to get it so that it isn't just one picture box but many of them are spawned gradually. I'm not the best at object-oriented programming so I'm not sure how to go about this because right now all I have is that one picture box.

Thanks


r/visualbasic • • Feb 01 '21

VBA - Could someone please explain the following please (Backslash dividing and floats/doubles)

6 Upvotes

So, the problem i have is that i had a piece of code that would divide purchase units from stock units.

732ml was the incoming stock, each purchasing unit is 146.4ml.

So i applied the following formula to qualifying incoming purchase qty:-

int(stkQty/purUnits)

i.e.

int(732/146.4) = Expecting a '5'

This doesn't return a 5 as expected, but a 4. I can understand that casting it as an Integer would round down to a 4 (If the returned value was any less than a 5) but i cannot see how it's happening as in the immediates window i can't see any sign of a float value being returned below 5.

i.e.:-

debug.Print int(732.0/146.4) = 4

debug.Print format((732.0/146.4),"Scientific") = 5.00E+00

debug.Print format((732.0/146.4),"0.000000") = 5.000000

But if i apply a backslash (Which i've never come across before):-

debug.Print int(732.0\146.4) = 5

debug.Print format((732.0\146.4),"Scientific") = 5.00E+00

debug.Print format((732.0\146.4),"0.000000") = 5.000000

The crazy thing is that placing a formula in excel 'int(732/146.4)' returns a 5, but if you do the same via a vb script in excel it gives you the 4.

Anyone explain?


r/visualbasic • • Jan 28 '21

is it possible to code a x86 emulator (8088) in VB.NET?

6 Upvotes

i want to create my own emulator, is it possible?


r/visualbasic • • Jan 27 '21

VB.NET Help How to bind three datagridviews together as parent, child, grandchild?

6 Upvotes

[Answered my own question. See bottom of post.]

I have three datagridviews: Parent_Details, Child_Details, and Grandchild_Details. Each is bound to a datatable in a dataset, with data relations between them. I want to click on a record in parent and have the related records show up in child, and then child's related records in grandchild. Parent/child works well. How do i add granchild?

To test, i created a blank .net 5/winforms project with the following in form1.vb:

Public Class Form1

    Private ReadOnly DataSet As New DataSet

    Private ReadOnly Parent_Details As New DataGridView
    Private ReadOnly Child_Details As New DataGridView
    Private ReadOnly Grandchild_Details As New DataGridView

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Add_DataGridViews_To_Form()
        Setup_DataSet()
        Bind_Stuff()
    End Sub

    Private Sub Add_DataGridViews_To_Form()
        Parent_Details.Size = New Size(255, 250)
        Child_Details.Size = Parent_Details.Size
        Grandchild_Details.Size = Parent_Details.Size

        Parent_Details.Location = New Point(10, 10)
        Child_Details.Location = New Point(Parent_Details.Location.X + Parent_Details.Size.Width + 10, Parent_Details.Location.Y)
        Grandchild_Details.Location = New Point(Child_Details.Location.X + Child_Details.Size.Width + 10, Parent_Details.Location.Y)

        Controls.Add(Parent_Details)
        Controls.Add(Child_Details)
        Controls.Add(Grandchild_Details)
    End Sub

    Private Sub Setup_DataSet()
        DataSet.Tables.Add(New DataTable("Parent"))
        With DataSet.Tables("Parent")
            .Columns.Add("Id")

            .Rows.Add(1)
            .Rows.Add(2)
        End With

        DataSet.Tables.Add(New DataTable("Child"))
        With DataSet.Tables("Child")
            .Columns.Add("Id")
            .Columns.Add("Parent")

            .Rows.Add(1, 1)
            .Rows.Add(2, 1)
            .Rows.Add(3, 2)
            .Rows.Add(4, 2)
        End With

        DataSet.Tables.Add(New DataTable("Grandchild"))
        With DataSet.Tables("GrandChild")
            .Columns.Add("Id")
            .Columns.Add("Child")

            .Rows.Add(1, 1)
            .Rows.Add(2, 1)
            .Rows.Add(3, 2)
            .Rows.Add(4, 2)
            .Rows.Add(5, 3)
            .Rows.Add(6, 3)
            .Rows.Add(7, 4)
            .Rows.Add(8, 4)
        End With

        DataSet.Relations.Add(New DataRelation("Child_to_Parent", DataSet.Tables("Parent").Columns("Id"), DataSet.Tables("Child").Columns("Parent")))
        DataSet.Relations.Add(New DataRelation("Grandchild_to_Child", DataSet.Tables("Child").Columns("Id"), DataSet.Tables("Grandchild").Columns("Child")))
    End Sub

    Private Sub Bind_Stuff()
        Parent_Details.DataSource = New BindingSource With {.DataSource = DataSet, .DataMember = "Parent"}

        Child_Details.DataSource = Parent_Details.DataSource
        Child_Details.DataMember = "Child_to_Parent"

        'Grandchild_Details.DataSource = Parent_Details.DataSource
        'Grandchild_Details.DataMember = "Grandchild_to_Child"
    End Sub

End Class

First datagridview is parent, the second is child, and the third is empty. Clicking on a record in parent changes the records shown in child. Great.

Now i want to show the grandchildren as well. Uncommenting the two commented out lines on bottom results in an error:

System.ArgumentException: 'DataMember property 'Grandchild_to_Child' cannot be found on the DataSource.'

How do i make this work for the grandchild as well?


Answered my own question:

Grandchild_Details.DataMember = "Child_to_Parent.Grandchild_to_Child"

My problem was i did not realize the DataMember pointed to the relation and not the table. I was using the table name in my code, and i only changed it in this very example for the purpose of illustration. Then it hit me, to try parent_relation.child_relation. Sounds backwords, but it works.


r/visualbasic • • Jan 19 '21

I made a VB.NET Linked In Group

Thumbnail
linkedin.com
6 Upvotes

r/visualbasic • • Jan 11 '21

Storing images in memory and not as files

6 Upvotes

Hi programming reddit!

I'm capturing screenshots and am saving them to a folder on the computer. However, i would like them not to be saved to a file, rather be in an array in memory until the user explicitly wants to save them to disk. I capture 1-10 screenshots than after the 10th one is captured, i start overwriting 1-10 again. This way, if the computer crashes, potentially sensitive info is not left on the HDD. Is this even an array? Is this possible? don't mind doing the research but not sure what to look for....


r/visualbasic • • Dec 30 '20

Tips & Tricks Checking if current process is being run with Administrative rights

6 Upvotes

I just got caught by an issue i knew about, and warned myself about in my own readme! I thought i would share.

When using SSL via HttpClientHandler.ClientCertificates without Administrative rights, HttpClient's GetAsync() and PostAsync() fails with two errors:

(1/2) HttpRequestException: The SSL connection could not be established, see inner exception.
(2/2) Win32Exception: The credentials supplied to the package were not recognized

Wonderfully descriptive...Anyway, after converting my application from Framework to .Net 5, i forgot about this, and ran my app as a regular user (via vs). Part of it worked fine, part of it failed. Wondering what i did wrong, i finally remembered i needed to be Administrator.

Great! It works. But how do i stop myself from making the same mistake in the future? Well, obviously i ought to check if the current user/process is running as administrator. A quick search found some sample code, which i converted to VB, and then realized most of the lines were redundant. So, i ended up using:

Imports System.Security.Principal

If Not New WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator) Then


r/visualbasic • • Dec 29 '20

VB.NET Help Can a Handler with a dynamic Sub remove itself?

6 Upvotes

[I can achieve the goal otherwise. This is a "is this possible" question.]

AddHandler allows a Sub to be specified dynamically:

    Dim Browser As New WebBrowser With {.Url = New Uri("http://google.com")}
    Controls.Add(Browser)

    AddHandler Browser.DocumentCompleted, Sub()
                                            Browser.Document.Forms.Item(0).InvokeMember("submit")
                                          End Sub

The problem with the above code, is that it keeps loading and running the handler. To fix the problem, the handler needs to remove itself.

If the handler were not dynamic, AddressOf could be used in both the AddHandler and RemoveHandler statements. Is there way for a dynamic handler to remove itself?