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?


r/visualbasic • • Dec 21 '20

Detect Window version with VB

6 Upvotes

Hi everyone. I'm working on a project that needs to install different components on users' machines based on their Windows version. Currently, we need to adapt for a range from Windows 7 to 10, and instead of distributing different version of installer, I have to integrate them into only one MSI file only. My colleague had written VB code for the MSI file, and I think I should continue his work instead of making a new one since it's time consuming (I'll consider this later when I have more time, but it's urgent now).

I'm wondering that if there is any function that help the MSI to detect Windows version (from 7 to 10). Also, I need to identify different version of Windows 10 too (currently, there are Windows 10 version 16, 17, 18, 19). I'll be very appreciate if someone can provide some references or sample codes for this work.

Thank you very much


r/visualbasic • • Dec 11 '20

How to keep an nput box within a range

6 Upvotes

So I'm making a random guessing game, the thing is that instead of putting my answer in a textbox it I have to put in a inputbox. I got most of the code to work how I want it, but I still need to make it so that the guess is invalid if 0 or lower or 101 and higher. Also if it was a regular textbox I could use tryparse to validate responses as an integer, but I have no idea how to go about it in an Inputbox. Any and all help appreciated. Btw the random number is generated in another sub that calld the one featured in the pic it's intGeneratedNum = randomNum.Next(1,100)


r/visualbasic • • Dec 01 '20

Get Source Code from Visual Basic 3?

6 Upvotes

I am working on a system that was originally written in VB 3 (I think) in 1991. I was able to recover the source files, but they're not in plain text.

Does anyone happen to have a running Visual Basic 3 and could open the files and save them as plain text?

I'm looking at ten files in all for the last two generations of the code. The files are

CUST.FRM FILE.FRM MOD1.BAS PLOT.FRM VGL.MAK

I'm thinking that last file might be a Visual Basic "makefile"? It's a binary file, but seems to list the other files and maybe a project name.


r/visualbasic • • Nov 02 '20

Formatting Question Help

Post image
6 Upvotes

r/visualbasic • • Oct 28 '20

debugging help!!!?: dice roll game (question in comment)

Post image
6 Upvotes

r/visualbasic • • Oct 27 '20

Adobe Acrobat combine several PDFs

6 Upvotes

Hello, I have a code that creates PDFs off all items listed in a listbox.

Now I want these newly created PDFs to be combined into one. I've searched around the web and can't seem to find a example I can write to my own, so I'm asking you for some help.

Dim Acroapp As Acrobat.CAcroApp = CreateObject("AcroExch.App")
Dim files(ListBox4.Items.Count) As String
Dim Path As String = TextBox1.Text

If Not System.IO.Directory.Exists(Path) Then IO.Directory.CreateDirectory(Path)

    Dim invapp As Inventor.Application
    invapp = GetObject(, "Inventor.Application")
    For Each itm In ListBox4.Items

        Dim x As Integer = ListBox4.Items.IndexOf(itm)

        invapp.Documents.Open(itm.ToString & "idw", True)

        invapp.ActiveDocument.SaveAs(Path & "\" & itm.ToString & ".pdf", True)

        files(x) = Path & "\" & items.ToString & ".pdf"

        invapp.ActiveDocument.Close()

    Next

'Acroapp.saveas(files(), Path & "\CombinedFile.pdf") 'This is the step I can't any examples of.

MsgBox("Completed")

(Tried to clean up the code to only show relevant info, so there might be some errors)

Thanks for any help!

Bonus: If its possible to skip creating the single PDFs before combining, that would be great.