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

[RESOLVED] VS2019 type “AutomationElement” is not defined

$
0
0
I added reference to UIAutomationTypes and to UIAutomationClient and use those imports

Code:


    Imports System.Windows.Automation
    Imports System.Runtime.InteropServices
    Imports System.Text

But I get an error: type "AutomationElement" is not defined when I use that code

Code:

Dim rootElement As AutomationElement = AutomationElement.FromHandle(hwnd)
I even get an error when I add
Code:

using System.Windows.Automation.AutomationElement
AutomationElement is not a member of System.Windows.Automation

what is wrong?

VS 2010 Ping Network Computer

$
0
0
Very simple setup. Local network with 2 computers, a printer and Internet access. The server often needs to know the status of the 2nd computer. I am using the following code which seems a common solution:


Code:

If My.Computer.Network.Ping("Jack-Laptop") Then
    MsgBox("Pinged successfully.")
Else
    MsgBox("Pinged computer is off-line")
End If

When "Jack-Laptop" is on-line, all is well ... MsgBox prints correctly.
When "Jack-Laptop" is 0ff-line there is an error and MsgBox is not printed.

The error msg is a rather ambiguous 'unhandled exception.'

What am I missing here?

Having seen my 83rd birthday come and go, I am thinking this will be my last project. Over the years you guys have been great ... there is VB Forum input in almost all of my projects. Thanks for that!

Get a Chrome URL

$
0
0
I'm trying to get a Chrome URL but I get an error:

System.MissingMethodException: 'Method not found: 'System.Windows.Rect System.Windows.Automation.Provider.IRawElementProviderFragment.get_BoundingRectangle()'.'

when I use this code:
Code:

Dim procsChrome As Process() = Process.GetProcessesByName("chrome")
    For Each chrome As Process In procsChrome
        If chrome.MainWindowHandle = IntPtr.Zero Then Continue For
        Dim elm As AutomationElement = AutomationElement.FromHandle(chrome.MainWindowHandle)
        Dim elmUrlBar As AutomationElement = elm.FindFirst(TreeScope.Descendants, New PropertyCondition(AutomationElement.NameProperty, "Address and search bar"))
        If elmUrlBar IsNot Nothing Then
            Dim patterns As AutomationPattern() = elmUrlBar.GetSupportedPatterns()
            If patterns.Length > 0 Then
                Dim val As ValuePattern = DirectCast(elmUrlBar.GetCurrentPattern(patterns(0)), ValuePattern)
                If Not elmUrlBar.GetCurrentPropertyValue(AutomationElement.HasKeyboardFocusProperty) Then Debug.Print(LCase(val.Current.Value).Trim)
                Exit For
            End If
        End If
    Next

The error appears in this line:
Code:

Dim elm As AutomationElement = AutomationElement.FromHandle(chrome.MainWindowHandle)

[RESOLVED] TickMark in Each Checkbox of Listview to get fullRowSelected

$
0
0
Hello

Basically i am trying to tick mark in each checkbox of Listview1 so that the FullRowSelected gets hilited.
if no tickmark then Each FullRowSelected remains No Focus.

The following events i tried but remained successful.

Code:

    Private Sub ListView1_DrawColumnHeader(sender As Object, e As DrawListViewColumnHeaderEventArgs) Handles ListView1.DrawColumnHeader
        Dim strFormat As New StringFormat()
        If e.Header.TextAlign = HorizontalAlignment.Center Then
            strFormat.Alignment = StringAlignment.Center
        ElseIf e.Header.TextAlign = HorizontalAlignment.Right Then
            strFormat.Alignment = StringAlignment.Far
        End If

        Dim headerFont As New System.Drawing.Font("Calibri", 11, FontStyle.Bold)
        e.Graphics.FillRectangle(Brushes.SteelBlue, e.Bounds)
        e.Graphics.DrawString(e.Header.Text, headerFont, Brushes.White, e.Bounds, strFormat)

    End Sub


Private Sub ListView1_DrawSubItem(sender As Object, e As DrawListViewSubItemEventArgs) Handles ListView1.DrawSubItem
        If e.Item.Selected = True Then
          e.Item.BackColor = Color.Red
          e.Item.ForeColor = Color.White
          e.DrawText()
        Else
            e.DrawDefault = True
            e.DrawText()
        End If
End Sub

Private Sub ListView1_DrawItem(sender As Object, e As DrawListViewItemEventArgs) Handles ListView1.DrawItem
        e.DrawBackground()
        e.DrawDefault = True

End Sub

Private Sub ListView1_ItemChecked(sender As Object, e As ItemCheckedEventArgs) Handles ListView1.ItemChecked
    If e.Item.Index = 0 AndAlso e.Item.Checked Then
            e.Item.Checked = True
            e.Item.BackColor = Color.Red
            e.Item.ForeColor = Color.White
        Else
            e.Item.Checked = False
            e.Item.BackColor = Color.White 
            e.Item.ForeColor = Color.Black
        End If
   
End Sub

'The above routine also tried with For loop but no proper success
Code:

Private Sub ListView1_ItemChecked(sender As Object, e As ItemCheckedEventArgs) Handles ListView1.ItemChecked

 For i As Integer = 0 To ListView1.Items.Count - 1
    If e.Item.Index = i AndAlso e.Item.Checked Then
            e.Item.Checked = True
            e.Item.BackColor = Color.Red
            e.Item.ForeColor = Color.White
        Else
            e.Item.Checked = False
            e.Item.BackColor = Color.White 
            e.Item.ForeColor = Color.Black
        End If
 Next
End Sub

Thanks

SamD
Thread 9 892411
48

VS 2013 [RESOLVED] Split string to put first word into a text box

$
0
0
I am trying to split a string "Surname Forename Occupation" taken from a ListBox so I can put the first word into a text box. Using Split I can display in a message box but get errors trying to load into a textbox. It started out as a string but seems to be an array. I need the string to trim down to just the Surname.

HTML Code:

Dim str As String = Me.ListBox3.SelectedItem
        Dim strarr() As String
        strarr = str.Split(" "c)
       
        For Each s As String In strarr
            MessageBox.Show(s)

        Next
        Me.TextBox1.Text = strarr

VS 2019 How get location of control during OnControlAdded?

$
0
0
I'm trying to work around the problem, of not being able to reparent a control to its GrandParent in Design-mode.
I want to add control_A to control_B, while control_A is covered by its child; control_C.
So I set AllowDrop = False on control_C, so control_A drops through and parents to Control_B.
But I still have to know on witch child, contol_A would have dropped.
To get the position of Control_A, I call OnControlAdded of Control_B:
Code:

  Protected Overrides Sub OnControlAdded(e As ControlEventArgs)
        MsgBox(e.Control.Location.X)
        MsgBox(e.Control.Location.Y)
    End Sub

X and Y are always zero.
Though control_A is added somewhere else.
Is the "drop"location of a control saved in some variable and used later?

VS 2017 Pull data from DataGridView on open form

$
0
0
Hello:

I have the following lines of code to pull data from an open form, to another open form called frmGannt, which is where this code resides.

The code seems to have no problem knowing the name of the DataGridView, but for some reason it cannot get a count of the rows.

Code:
Code:

        Dim dgv As DataGridView = frmSchedule.dgvScheduleData
        MessageBox.Show(dgv.Name & ": " & dgv.Rows.Count - 1 & ", " & dgv.Columns.Count - 1)

Result below, I think it should read "dgvScheduleData: 9, 8"
Name:  OUTPUT.jpg
Views: 55
Size:  20.3 KB

Thank you for the help.
Attached Images
 

Help with Design please

$
0
0
I am rewriting a program originally created in VB6. I have data that was originally displayed in an MSFlexGrid (see attachment). The highlighted rows are user input and the others are calculated based on input. Under the "Fixed Expenses" heading, the user can insert as many rows as needed and the bottom rows are calculated based on the combined sections.

I am struggling with the best way to do this in VB.NET. My initial thought was to do in a DataGridView and just create placeholders in the database for the rows so they show correctly when populated. Although not 100% sure that will work like I want it to.

I am new to VB.NET, so any suggestions would be greatly appreciated.

Name:  FlexGridPic.jpg
Views: 53
Size:  22.7 KB

Thank you,
Chrissy
Attached Images
 

[RESOLVED] Help with Design please

$
0
0
I am rewriting a program originally created in VB6. I have data that was originally displayed in an MSFlexGrid (see attachment). The highlighted rows are user input and the others are calculated based on input. Under the "Fixed Expenses" heading, the user can insert as many rows as needed and the bottom rows are calculated based on the combined sections.

I am struggling with the best way to do this in VB.NET. My initial thought was to do in a DataGridView and just create placeholders in the database for the rows so they show correctly when populated. Although not 100% sure that will work like I want it to.

I am new to VB.NET, so any suggestions would be greatly appreciated.

Name:  FlexGridPic.jpg
Views: 105
Size:  22.7 KB

Thank you,
Chrissy
Attached Images
 

VS 2017 request coding

$
0
0
Kindly pls assist below:
Write a program requesting a sentence as input. Every word in the sentence has to be converted into a pig latin word. The rules for translating a word into pig latin are as follows:

• If the word begins with a consonant, move the first letter to the end of the word and add ary. For instance, chip becomes hipcary.

• If the word begins with a vowel, add way at the end of the word. For instance, else becomes elseway.

The program should also be able to change the pig words to normal words.

VS 2010 Drawing an Border to PrintDocument

$
0
0
Hello

I am trying to learn Printing in VB by creating some reports

To start with i tried to draw border to the PrintDocument at Margins 25,25,25,25, to do so i have used the below code,

the Preview of the printdocument shows the border at the specified location, but when i print the document, the border goes out of bound from the right and bottom portion.

kindly help

vb Code:
  1. Private Sub PrintDocument1_BeginPrint(sender As System.Object, e As System.Drawing.Printing.PrintEventArgs) Handles PrintDocument1.BeginPrint
  2.         Me.PrintDocument1.DefaultPageSettings.Margins = New Margins(25, 25, 25, 25)
  3.     End Sub
  4.  
  5.     Private Sub PrintDocument1_PrintPage(sender As System.Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
  6.         If Not Me.PrintDocument1.PrintController.IsPreview Then
  7.             Me.PrintDocument1.OriginAtMargins = True
  8.         End If
  9.  
  10.         Dim DrawRec As Rectangle = e.MarginBounds
  11.         e.Graphics.DrawRectangle(Pens.Red, DrawRec.X, DrawRec.Y, DrawRec.Width, DrawRec.Height)
  12.     End Sub
  13.  
  14.     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  15.         Me.PrintDocument1.Print()
  16.     End Sub

Can't Parse textbox.

$
0
0
I'm trying to restrict the input of a text box to allow only numbers (0-9). I intercept "KeyDown" and update Textbox1.Text only if a number is typed:

(Updated)
----------
Code:

Public Class Form1
    Dim strPreviousID As String = ""

    Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles Textbox1.KeyDown
        If e.KeyValue > 95 And e.KeyValue < 106 Then    ' Only ASCII values from "0" to "9".
            strPreviousID += Chr(e.KeyValue - 48)            ' ASCII value is Keyboard - 48
        Else
            TextBox1.Text = strPreviousID
        End If
        strPreviousID = TextBox1.Text
    End Sub
End Class

----------

PROBLEM (Updated): If the very first character is not a number, it STILL appears in the text box. If you type anything other than a number, the box contents are replaced with that one letter.

For the life of me, I can not figure out how to stop non-numeric values from appearing.

All "solutions" found online either don't work with VB.Net or are wildly unnecessarily complex.

So instead of "KeyDown", I tried "TextChanged":

Code:

Public Class Form1
    Dim strPreviousID As String = ""

    Private Sub Textbox1_TextChanged(sender As Object, e As EventArgs) Handles Textbox1.TextChanged
        If Textbox1.Text.Last.ToString >= "0" And Textbox1.Text.Last.ToString <= "9" Then ' Only "0" thru "9".
            strPreviousID += Textbox1.Text.Last.ToString
        Else
            Textbox1.Text = strPreviousID
        End If
        Textbox1.Text = strPreviousID
    End Sub
End Class

This comes with its own set of problem. Numbers work fine, but "If" line throws an exception if anything other than a number is typed.

I'm stumped. TIA

Compressing files

$
0
0
If have the following code to compress a .csv file into a .zip file :

Code:

Imports System
Imports System.IO.Compression

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


        Dim startPath As String = "D:\Wingerdbou\LutzvilleProgram\InvoerDataFiles\EZY Wine\Vessel_Composition\compositionVIRZIP.csv"
        Dim zipPath As String = "D:\Wingerdbou\LutzvilleProgram\InvoerDataFiles\EZY Wine\Zipped\test.zip"
        Dim extractPath As String = "D:\Wingerdbou\LutzvilleProgram\InvoerDataFiles\EZY Wine\Unzipped"

        ZipFile.CreateFromDirectory(startPath, zipPath)

        ZipFile.ExtractToDirectory(zipPath, extractPath)

        MsgBox("Done")
    End Sub

End Class





But I get the following error : System.IO.IOException: 'The parameter is incorrect. : 'D:\Wingerdbou\LutzvilleProgram\InvoerDataFiles\EZY Wine\Vessel_Composition\compositionVIRZIP.csv''


From https://docs.microsoft.com/en- I can see a @ is placed before the file description, but how to do it in VB.Net?

I have both System.IO.Compression and System.IO.Compression.ZipFile installed via NuGet.

I am using .NET 5.0

Regards

[RESOLVED] Compressing files

$
0
0
If have the following code to compress a .csv file into a .zip file :

Code:

Imports System
Imports System.IO.Compression

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


        Dim startPath As String = "D:\Wingerdbou\LutzvilleProgram\InvoerDataFiles\EZY Wine\Vessel_Composition\compositionVIRZIP.csv"
        Dim zipPath As String = "D:\Wingerdbou\LutzvilleProgram\InvoerDataFiles\EZY Wine\Zipped\test.zip"
        Dim extractPath As String = "D:\Wingerdbou\LutzvilleProgram\InvoerDataFiles\EZY Wine\Unzipped"

        ZipFile.CreateFromDirectory(startPath, zipPath)

        ZipFile.ExtractToDirectory(zipPath, extractPath)

        MsgBox("Done")
    End Sub

End Class





But I get the following error : System.IO.IOException: 'The parameter is incorrect. : 'D:\Wingerdbou\LutzvilleProgram\InvoerDataFiles\EZY Wine\Vessel_Composition\compositionVIRZIP.csv''


From https://docs.microsoft.com/en- I can see a @ is placed before the file description, but how to do it in VB.Net?

I have both System.IO.Compression and System.IO.Compression.ZipFile installed via NuGet.

I am using .NET 5.0

Regards

VB.net How to add one .rdlc report to another

$
0
0
Hello, I am coding in visual studio with vb.net but I have a problem with reportviewer. The problem is that I would like to add a report3.rdlc file after another report10.rdlc but when I do it second overwrites the first instead of adding it to the next page. Below my code, please help me.

Code:

Private Sub form37_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  Dim rds = New ReportDataSource("DataSet1", Testdata.Tables("FONDSGARANTIE"))
        report37.LocalReport.DataSources.Clear()
        report37.LocalReport.DataSources.Add(rds)
        Me.report37.LocalReport.ReportPath = "report10.rdlc"
        Me.report37.LocalReport.ReportPath = "report3.rdlc"
        Me.report37.RefreshReport()
end sub


how to find if a driver is installed

$
0
0
Hi, I am trying to find out if a driver is installed on the users system. Here is what I have:

Code:

Dim searcher As New ManagementObjectSearcher("root\cimv2", "SELECT * FROM Win32_PnPSignedDriver")
        Dim drivername As String = ""

        For Each queryObj As ManagementObject In searcher.Get()

            drivername = CStr(queryObj("Manufacturer"))

            If drivername IsNot String.Empty And drivername IsNot Nothing Then

                If drivername.Contains("CustomDriver") Then

                    ss_driverinstalled = 1 'the driver has been detected, set flag

                    Exit For

                End If

            End If

        Next

This does not detect the driver even though it is installed. I used this code to detect if a port is available by changing the search to: SELECT * FROM Win32_SerialPort. It works great.

I should also mention that this is an unsigned driver. I see that the search is for pnpsigneddriver. Is that the problem? If so, how can I find unsigned drivers?

Thanks!

Writing a structure to a file.

$
0
0
I have a data structure, mixed integer, string and arrays (x,y)..... I need to dump the contents of the structure to a file then read it back after re-dimensioning the arrays within the structure.

I am needing to do this because of the limitation of using the PRESERVE option when REDIM ing a multi-dimensional array (1st index).

I was hoping to use the FileSystem.FilePut Method rather than to do it by hand, but cannot seem to figure out how to do it.

If my structure is say

Employee.name
Employee.age
Employee.childs_name(x)
Employee.GrandChildren(x,y)

I was hoping there was a way to just write EMPLOYEE and then read it back into the same EMPLOYEE structure.

VS 2008 re entry data

$
0
0
hi im new here need help for my project

heres my problem:


i have 4 data to be save
but
if 2 out of 4 data are already in my data base i need to
re entry my data..

pls help me..


heres my code

cmd = con.CreateCommand()
cmd.CommandType = CommandType.Text
cmd.CommandText = "Select * from tblschedule where room like '%" & TextBox2.Text & "%' or teacher LIKE '%" & TextBox4.Text & "%'"
cmd = New SqlCommand(cmd.CommandText, con)
i = cmd.ExecuteNonQuery()
Dim sda As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim dt As DataTable = New DataTable()
sda.Fill(dt)
If (dt.Rows.Count > 0) Then
MsgBox("Room Name Already Exist", MessageBoxIcon.Error, "Error")

In need of help with drawing gauge controls with GDI+ vb.net 2017

$
0
0
Hi everyone , Im really struggling to find out how to draw gauge controls with GDI+ VB.NET 2017 like the attachments below from start to finish code , Please if anyone can shed some light on this drawing will be very helpful to me?
Name:  VU_Meters.JPG
Views: 49
Size:  16.6 KBName:  other_guage.JPG
Views: 50
Size:  20.8 KB

Thank you
Attached Images
  

Always-on-display VB.NET

$
0
0
Hi all,
Is there any code to force computer not to dim light, go to screensaver or standby? Like how they act when a media player is active.
Viewing all 28379 articles
Browse latest View live


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