Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all 27433 articles
Browse latest View live

VS 2013 Serial data outputs nonsense

$
0
0
Hi guys,

I'm attempting at just displaying the raw values from a COM serial port from a sensor, which gives around 4000 rows of data per cycle.

Here's the code:

Code:

Imports System
Imports System.IO.Ports
Imports System.Threading

Public Class Form1

    Dim readThread As Thread = New Thread(AddressOf ReadFromCom)
    Dim abortThread As Boolean

    Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        SerialPort2.Open()
        readThread.Start()

    End Sub

    Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        With SerialPort2
            .PortName = "COM9"
            .BaudRate = 2000000
            .Parity = Parity.None
            .DataBits = 8
            .StopBits = 1
            .ReadTimeout = Nothing
            .DtrEnable = True
            .RtsEnable = True
        End With
    End Sub

    Public Sub ReadFromCom()

        While abortThread = False
            Try
                Dim message As String = SerialPort2.ReadExisting
                updateStatus("Received: " & message)
            Catch ex As TimeoutException
                updateStatus(ex.ToString)
            End Try
        End While
    End Sub

    Public Delegate Sub updateStatusDelegate(ByVal newStatus As String)

    Public Sub updateStatus(ByVal newStatus As String)
        If Me.InvokeRequired Then
            Dim upbd As New updateStatusDelegate(AddressOf updateStatus)
            Me.Invoke(upbd, New Object() {newStatus})
        Else
            TextBox1.Text = newStatus & vbCrLf & vbCrLf & TextBox1.Text
        End If
    End Sub
End Class

The output textbox gives out a string of ????????? most of the time, sometimes numerical. Sometimes it's nothing.

Anything I should read more into? It seems not many thread discusses this at length so I'm tweaking about other people's code hoping for the best.

Anyhow an independent Python code with MatPlotLib, with the same settings for the serial port outputs the data quite nicely.

Thanks.
Vizier87

VS 2012 Run cmd minimized

$
0
0
Hi! Quick question that I hope someone can answer.
Basically I have a bit of code which when runs opens a cmd window. What I'm wondering is would it be possible to run the cmd window minimimzed?

Here's what I have:
Code:

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        TextBox1.Text = "Dir"
        TextBox2.Text = "tree"
        TextBox3.Text = "mkdir temp"

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim psi As New ProcessStartInfo()
        psi.Verb = "runas"
        psi.FileName = ("cmd.exe")
        psi.Arguments = "/c " & TextBox1.Text & " && " & TextBox2.Text & " && " & TextBox3.Text 'dir|more"

        Try
            Process.Start(psi)

        Catch
            MsgBox("User cancelled the operation", 16, "") ' User pressed No
        End Try

    End Sub

If user computer only NET Framework 3.0, which VS(VB) version is better?

$
0
0
I have trouble, I'm use VS2008. If guest, user computer only NET Framework 3.0, which version(VB) is better?

Visual Studio (2002,2003,2005,2008,2010,2012,2013,2015,2017,2019)


And a lot of (year) version, write that sample code (VB) "Hello Word" same? or difference?


Cheers.

[RESOLVED] VB.Net 2019: A list of the class "A" within the class "A" ?

$
0
0
I am trying to expand my knowledge of classes and I don't understand why having a list of the host class within that same class works. Why does that not result in an 'infinite regress'?

Is there a good book/resource all about classes?

In the partial code below in the class 'Class Account', a List(Of Account) is created inside the same class. But each element of that List(Of Account) would also contain a field "Records" which would then also contain a further List(Of Account) would it not?

Applicable part of code example (from web video):

PHP Code:

Public Class Account
    
Public Property AccountId As String
    
Public Property AccountName As String
    
Public Property Balance As Decimal
    
Public Property FilePath As String
    
Public Property ErrorMsg As String
    
Public Property Records As List(Of Account)

    Public 
Sub New()  Â’ Constructor
        AccountName 
String.Empty
        
Balance 0D
        Records 
= New List(Of Account)        Â‘ A list of the class "Account" within the class Account
    End Sub

End 
Class 

[RESOLVED] If user computer only NET Framework 3.0, which VS(VB) version is better?

$
0
0
I have trouble, I'm use VS2008. If guest, user computer only NET Framework 3.0, which version(VB) is better?

Visual Studio (2002,2003,2005,2008,2010,2012,2013,2015,2017,2019)


And a lot of (year) version, write that sample code (VB) "Hello Word" same? or difference?


Cheers.

Is there any way to listen to WebSockets in Visual Basic .NET

$
0
0
Hello, I am using VB to develop a software which needs to listen to WebSocket for Binance API at wss://fstream.binance.com/ws/btcusdt@klike. I have seen several tutorials online how to do it in NodeJS. But I need to do it and integrate it in my WinForms software. So, is there any similar approach in the .NET Framework? I'll be very happy to know

Class library project not the same as windows form project for string functions

$
0
0
' This works fine in a windows form project
PHP Code:

 Dim numStr As String Trim(Str(theNumber)) 

' However, if I use the same line of code in a class library project it doesn't work. Instead I get the errors:

Error BC30451 'Trim' is not declared. It may be inaccessible due to its protection level.
Error BC30451 'Str' is not declared. It may be inaccessible due to its protection level.

I'm wondering what is the difference between the two whereby the line of code works in a windows form project but not in a class library project.

Modern C# to VB

$
0
0
I'm clearly behind the times. I'm trying to convert this example from C# to VB:

Code:

{
    services.AddMvc();

    JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

    services.AddAuthentication(options =>
        {
            options.DefaultScheme = "Cookies";
            options.DefaultChallengeScheme = "oidc";
        })
        .AddCookie("Cookies")
        .AddOpenIdConnect("oidc", options =>
        {
            options.SignInScheme = "Cookies";

            options.Authority = "http://localhost:5000";
            options.RequireHttpsMetadata = false;

            options.ClientId = "mvc";
            options.SaveTokens = true;
        });
}

Not being a real fan of lambdas, there some syntax there that I'm not familiar with. I believe I got the first part converted, but what is happening with that .AddCookie is not something I'm familiar with.

VS 2015 console app only shows console when double clicked

$
0
0
Using Windows7, Visual Studio 2015

This VB code runs fine in the debugger and it runs fine as an executable when double clicked. Console appears, files are copied and there is no problem with permissions. Moreover, I can drag and drop files to this network folder, no problem. However, when the executable is called from an external program, no console appears and no files are copied.

More to the story...

I have two desktops I believe are set up the same (mapped drives, permissions, OS, etc.). Only ONE machine displays the problem above. The other does just fine.

Code:

Imports System.IO
Module Module1
    Sub Main()
        Dim fiThisFile As FileInfo
        Dim diSource As DirectoryInfo = New DirectoryInfo("c:\MyFolder\MyFiles")
        For Each fiThisFile In diSource.GetFiles
            fiThisFile.CopyTo("\\myNetwork\myFolder" & fiThisFile.Name)
        Next
    End Sub
End Module

When enclosed in a Try/Catch Exception/End Try, I see the exception below is thrown, but seems odd, based on what I have described above. I contacted my IT and they say there is no reason I should get this error.

System.UnauthorizedAccessException: Access to the path '\\myNetwork\myFolder\myFile.pdf' is denied.

I am perplexed. Suggestions? Solutions?

SSLStream - "The handshake failed due to an unexpected packet format"

$
0
0
I'm trying to implement a secure socket server using the code provided from the MS example:

https://docs.microsoft.com/en-us/dot...rity.sslstream

But when it tries to authenticate it gives the error:

"The handshake failed due to an unexpected packet format"

I'm testing this by running the server on a web hosting account using .NET core and the client on my computer. It works with regular sockets.

What could be the cause? How can I troubleshoot this?

Thanks

String sort

$
0
0
Hi, I am trying to create a little program that, imports a .txt file to VB.Net console, then puts each word into an array, then takes each word and tests each char of each word to calculate a value based on what char is in each word. I have got the .txt import part working and the words are in an array, the bit i'm stuck on is how do i then run through each word?

What i have been trying is to create a dictionary of String, Int, and then for/next through a word at a time and if say for example the first letter is a char a, then i would like to count up the corresponding item.key. So the string is scanned one char at a time and the value from each letter is derived from the keypair value for that letter, so i can change the value of the letter to what i want.

I have searched everywhere for any information on how to do this or even if i have the right idea doing it this way in the first place, any help or pointers to how this can be done would greatly be appreciated as i'm totally stumped.

Problem with my program

$
0
0
I am trying to create a program that would function as a "shopping list". I have completed all the code and setting it up and what not but when I try and run the program it will not run. I have 0 errors in my code and it will not debug either. There are two programs I am having this problem with. Here is the code for both of the programs.
PROGRAM 1:
Code:

Public Class Form1
    Dim Item As String = txtAdd.Text
    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Item = Me.txtAdd.Text
        Me.lstItems.Items.Add(Item)
    End Sub
    Private Sub btnMoveToList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveToList.Click
        Me.lstItems.Items.Remove(Item)
        Me.lstList.Items.Add(Item)
    End Sub
Private Sub btnMoveToItems_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveToItems.Click
    Me.lstList.Items.Remove(Item)
    Me.lstItems.Items.Add(Item)
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
    Me.lstItems.Items.Remove(Item)
End Sub
End Class

PROGRAM 2:
Code:

Public Class Form1
    Dim total As Double
    Dim Cost As Double = Me.txtCost.Text
    Dim Number As Integer = Me.txtNumber.Text


    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        total = (Cost * Number)

        If Int32.TryParse(Me.txtCost.Text, Me.txtNumber.Text) Then
            MessageBox.Show("The total cost of your items is:" & total)
        Else
            MessageBox.Show("Enter correct numeric values")
        End If
    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Application.Exit()
    End Sub
End Class

I am receiving a pop up window that says "An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object."

VS 2017 vb.net webbrowser dropdown list

$
0
0
Code:

<select name="ddl" id="ddl" class="frmInput2" style="width:160px;">
<option value="-1"> </option>
<option value="11"> Diğer</option>
<option value="4">Amca</option>
<option value="2">Anne</option>
<option selected="selected" value="1">Baba</option>
<option value="5">Dayı</option>
<option value="7">Hala</option>
<option value="3">Kardeş</option></select>


How do I get the data selected from the Vb.net webbrowser drop down list. I'm waiting for your help .. thanks.

Code:

  Dim el As HtmlElementCollection =  eokul.Document.GetElementById("ddl").GetElementsByTagName("option")
        For Each el_option As HtmlElement In el
            ???????????????????????????????????
        Next

Processing Files in a folder in sequence

$
0
0
I would really appreciate your help with the following interesting issue:
I am developing a Visual Basic program in MS Visual Studio version 16.3, as follows:

I have a list of several files in a folder on the computer. Each of the files in this folder contains customer information. Each file, referring to a separate customer, has exactly the same layout and contains the same information (e.g. Customer first name, Customer surname, Company name, Email, etc.).

I have extracted this customers files via a separate tool and placed them in the folder.

To process the customers information in my own Visual Basic program, ideally, I would like to have all my customers information in one ‘consolidated’ file instead of having each customer in a separate file. However, for reasons beyond the scope of the current discussion, this is not possible!

I have to deal with the situation as it is. Therefore, I need my own Visual Basic to perform the following steps:

1 – Access the folder where the customers files are stored (this is always the same path. If need be I can hard-code the path in the program)

2 – Access each file in the folder in turn. Open, read and process the customer information in the file. Once done, close the file and proceed to the next file containing the information for the next customer.

3 – Exit when the last file in the folder is processed.

I would really appreciate your help/advise with this rather intriguing problem! The prime question is how I can separate each file separately...

Newbie Question

$
0
0
Hi All,

I am good with VBA but new to VB.Net. I am interested in using ExcelDNA which is an Excel addin that enables the use of Net code languages to interact with Excel. It looks pretty good, but I don't know enough about VB.Net (or C#) to know if the following is possible.

Can an xll (or dll which can be compiled with, or called from, the xll) hold a form that is created in Visual Studio?

What I want to be able to do is to design a form in Visual Studio and then have it displayed in Excel through the xll (or indirectly through a dll) instead of using a VBA form.

But can an xll or dll store a form? Or can it be only be pro grammatically created through code in real time?

Thx, JonS

VS 2019 Display query result in data grid view

$
0
0
Hello all , I am very new to visual studio and i am very interested in learning vb.net language even though i don't have much of programming experience.
I am creating a winform app for data entry connected to a access-db as source.
I have a data grid box in form2(name:reminder) which will pop up when clicked on a button in form1(name:MSdies).
In this form2 data-grid box i just want view the query results i have created as below SQL :
Code:

SELECT        ID, [Size in mg], [Die head number], [Inspection Date], [Next Calibration Date], [Die size in microns]
FROM            MSdies
WHERE        ([Next Calibration Date] < NOW())

originally the table contains these details
Code:

SELECT        ID, [Size in mg], [Die head number], [Inspection Date], [Next Calibration Date], [Die size in microns], [Condition of DIE-1], [Condition of DIE-2], [Condition of DIE-3], [Condition of DIE-4], [Condition of DIE-5], [Condition of DIE-6],[Condition of DIE-7], Observations, Inspector
FROM  MSdies

Can anyone help me with this how can i achieve the same by step wise explanation.
for database name & details
Code:

    Private Sub Reminder_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.MSdiesTableAdapter.Fill(Me.TrialdatabaseDataSet.MSdies)
    End Sub

I have attached images too for your reference.Name:  Capture.jpg
Views: 32
Size:  31.2 KB
Attached Images
 

VS 2017 VB .Net Different Arithmetic Result in Two Apps

$
0
0
i have a compiled Vb .Net Program that have below Arithmetic line when i want to use this line in new App has different result the code is :

Code:

Protected Sub MethodOne(ByRef A_1 As UInteger,A_2 As UInteger,A_3 As UInteger,A_4 As UInteger,A_5 As UInteger,A_6 As UShort)
A_1 = A_2 + Class2.Method1(A_1 + ((A_2 And A_3) Or (Not A_2 And A_4)) + 127, A_6)
    End Sub

'====================== method in Class2 difinition ====================
Code:

        Public Shared Function Method1(A_0 As UInteger, A_1 As UShort) As UInteger
                          Return A_0 >> CInt((32US - A_1)) Or A_0 << CInt(A_1)
        End Function

=================================================

with predefined values as

A_1 = 1732584193UI

A_2 = 4023233417UI

A_3 = 2562383102UI

A_4 = 271733878UI

A_5 = 0

A_6 = 7

A_7 = 0

when i Call MethodOne in Compiled App the Result of MethodOne is

A_1 2770347892 uint
but when i Run Same Code in New App With Same A_1 to A_6 Values the Result is

A_1 4023249673 uint
notice : in both Assembly i have turned on RuntimeCompatibilityAttribute:WrapNonExceptionThrows=true

What i have mistake ?

regards

VS 2017 How to run a program on all wildcards in all subfolders?

$
0
0
I made a script with Batch which looks for a wildcard *.cc within all folders of the program and runs a program.exelike

Code:

program.exe folder1/ad.cc
program.exe folder2/cd.cc,

Is there a way to accomplish the same in Visual Basic? I am new and have been trying this with For each, but can't figure it out. Can someone please help?

VS 2015 vb.net VB SOAP/WSDL API I'm Stuck

$
0
0
Hi,

I'm stuck. I've been re-reading up on SOAP/WSDL's all last week but not making much headway. I would areally appreciate any help.

I have a WSDL service reference/proxy class installed in in my project. I can see it all in my object browser. the wsdl is loacated at:

https://www.estes-express.com/tools/...teService?wsdl

I've constructed the call to the webservice below but am getting an error "InnerException: {"The type Estes_Test.wsdl_estes.FullCommodityType was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically."}"

Herein lies my problem.

The "commodity" is a load of 7000 pounds, class 60 freight and a quantity of 6 palletts. Since im requesting a volume load quote from Estes freightlines I have to use the "FullCommoditiesType" as opposed to the "BaseCommoditiesType" as dictated in the documentation
(https://www.estes-express.com/resour...b-service-v4-0). There can be up to 5 commodities loaded so I'm assuming it can/should be a array. I'll be happy just to get the one load rated.

FullCommoditiesType.commodity As Estes_Test.wsdl_estes.FullCommodityType()

The public class FullCommodityType has the public properties of class, ClassSpecified, description, peices, pieceType
weight, pieceType as wsdl_estes.packagngType, dimensions as wsdl_estes.DimensionsType

I can't seem to get my head wrapped around how to construct the Commodites to pass them into the request. By looking at the object browser I'm pretty sure they have to be added to the "quoteRequest.Item".

Can someone offer some assitance on this. Been strugeling with it for days.

Thanks


Code:

                Dim EstesService As ratingPortTypeClient = New ratingPortTypeClient()

                Dim quoteResponse As rateQuote = New rateQuote

                Dim quoteRequest As rateRequest = New rateRequest

                Dim estesAuth As New wsdl_estes.AuthenticationType With {
                .user = ("myestes"),
                .password = ("estesPW")
                }
 
                Dim shipfrom As New wsdl_estes.PointType With {
                .city = ("Memphis"),
                .stateProvince = ("TN"),
                .postalCode = ("38104"),
                .countryCode = ("US")
                }

                Dim shipto As New wsdl_estes.PointType With {
                .city = ("Atlanta"),
                .stateProvince = ("GA"),
                .postalCode = ("30369"),
                .countryCode = ("US")
                }


                Dim loaddimensions As New wsdl_estes.DimensionsType With {
                .length = ("48"),
                .width = ("44"),
                .height = ("55")
                }

                Dim myFreightLoad As New wsdl_estes.FullCommodityType With {
                .class = (60),
                .classSpecified = True,
                .description = ("Books"),
                .pieces = ("6"),
                .pieceType = PackagingType.SK,
                .weight = ("7000"),
                .dimensions = loaddimensions
                }


                Dim quoteRequest As rateRequest = New rateRequest With {
                .account = ("7451400"),
                .terms = ("P"),
                .linearFeet = ("12"),
                .stackable = YesNoBlankType.N,
                .payor = ("T"),
                .originPoint = shipfrom,
                .destinationPoint = shipto,
                .Item = myFreightLoad
                }


            ' The actual call for consuming the webservice is

                quoteResponse = EstesService.getQuote(estesAuth, quoteRequest)

VS 2019 Trouble with assigning the result of a function to a property

$
0
0
Hi, my issue is that I can't seem to be able to assign a function's return value to an instance of a Class of same type:

vb.net Code:
  1. Dim MTranslate_Z As Matrix3D = Matrix3D.Create_Scale(2, 2, 2)
  2.  
  3. For Each Vertex As PVector In PTriangle.Vertices
  4.     Dim unused As PVector = MTranslate_Z.MultiplyVector(Vertex)
  5.     Vertex = unused
  6. Next

More info on the above:

-PTriangle.Vertices is a property that returns an array of PVector objects.
-The "MultiplyVector" Function of the matrix returns a PVector object.

I want to assign the object returned by the function to each object looped trough in the array but it tells me "Unnecessary assignment of a value to Vertex"
I thought of making it a sub and directly change the PVector but I rather keep it as a function, how should I proceed ?
Is it in the PVector Class that I need to add something to allow this ?

Thanks in advance for the help !
Viewing all 27433 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>