joshi1984 47 Light Poster

the message is : BC30574 "Option Strict On" lässt spätes Binden nicht zu.

joshi1984 47 Light Poster

The error message is at line 40. "Option Strict On can not bind later" (or something like that, because I have to translate it by myself)

rproffitt commented: To give everyone the best chance at solving, supply the message as-is in whatever language it is. +17
joshi1984 47 Light Poster

Hello,

i have an excel-file whith 2 sheets.
There are much columns, but I need only a few of them.
I want to delete some columns by name.

I found this code but, I don´t know why it doesn´t work!?!?
It tells me ".UsedRange" is wrong.

Can you help me, please?

(Reference "Microsoft Excel 16.0 Object Library" is already added in my project)

Option Strict On
Imports System.IO
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Excel

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim Excel As Microsoft.Office.Interop.Excel.Application
        Dim xlWB As Microsoft.Office.Interop.Excel.Workbook
        Dim xlWSTabelle1 As Excel.Worksheet = CType(CType(xlWB.Sheets("Tabelle1"), Excel.Worksheet), Excel.Worksheet)
        Dim xlWSTabelle2 As Excel.Worksheet = CType(CType(xlWB.Sheets("Tabelle2"), Excel.Worksheet), Excel.Worksheet)
        Dim Path = "D:\Test.xlsx"
        Excel = New Microsoft.Office.Interop.Excel.Application
        xlWB = Excel.Workbooks.Open(Path)

        Dim xlSheets As Object
        Dim xlSheetsArray(0 To 1) As Excel.Worksheet
        Dim k As Long
        Dim i As Long

        xlSheetsArray(0) = xlWSTabelle1
        xlSheetsArray(1) = xlWSTabelle2


        For Each xlSheets In xlSheetsArray

            With xlSheets

                k = .UsedRange.Columns.Count

                For i = k To 1 Step -1
                    Select Case LCase(.UsedRange.Cells(1, i).Value)

                        'Keep these columns
                        Case "#Num", "Product A", "Number 1" '...

                        Case Else

                            'Delete all others not listed above
                            .UsedRange.Columns(i).Delete()

                    End Select
                Next i

            End With

        Next xlSheets
    End Sub
End Class
joshi1984 47 Light Poster

Hi,

I had a longer break, but now I want to continue working on my little project to make my work easier.

I have an Excel file which I converted to CSV because there is no Excel on the target system.

I would like to search for a number or word via vb.net. This word can appear in all columns! If the word was found, then
the cell in column A, B, D, AA and AB is to be output in the respective labels from this line. (lbl_Cell_A, lbl_Cell_B, lbl_Cell_D, lbl_Cell_AA, lbl_Cell_AB)

Unfortunately I only know how to search in the first column (A) and only output columns one after the other.
Here is my code:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Try
            For Each row As String In File.ReadAllLines("Test.csv")
                ' split the fields from the row '
                Dim vFields() As String = Split(row, ";")
                If vFields(0).Contains(TextBox1.Text) Then
                    lbl_Cell_B.Text = vFields(1)
                    lbl_Cell_C.Text = vFields(2)
                End If
            Next
        Catch ex As Exception
            MessageBox.Show("Error : " & ex.Message)
        End Try
    End Sub

Can you help me, please?

joshi1984 47 Light Poster

hi,

I got a string and it look like : "test : this is a test. for me."
How can I remove the first charakters? At this example I want to remove the characters "test : ". How can I do this?

I know how to delete from the end, but I realy need it from the beginning :

​Dim s As String = Label1.Text
TextBox1.Text = s.Substring(s.Length-9)
joshi1984 47 Light Poster

It isn´t necessary to know it is vbox or something else. So you don´t have to use a sdk for vbox.

because you can have at a pc 2 and much more LAN-Ports, so it is the same like in a vbox...

rproffitt commented: Good luck. Removing possible solution paths isn't how to solve problems. +15
joshi1984 47 Light Poster

Thanks, but i am looking for something waht I can use in VBox and normal Windows 7/10.
Maybe WMI but I don´t know how to select the adapter (LAN-BRIDGED or LAN-NAT), where I want to change the IP...

rproffitt commented: That's not normal. W7/10 has no knowledge about Vbox so you are back to the SDK for Vbox. +15
joshi1984 47 Light Poster

Hi,

i want to change my IP-Adress (IP + Subnet + Gateway/DNS) in a Virtual-Box (VBox - System = Windows 10 and 7) to a static-IP.
Til today I use "netsh", but sometimes it doesn´t work and I don´t know why. Thats why I am looking for an other method to change the IP.
In VBox are 3 different LAN-Adapters (LAN-HOST + LAN-NAT + LAN-BRIDGED). I only want to change the IP at "LAN-BRIDGED"!

I'm quite green and not sure if this is even possible. Someone told me it works with wmi maybe, but I don´t know how to do it in vb.net!

This was my old code :

Shell("netsh interface ip set address LAN-BRIDGED static 192.168.178.27 255.255.255.0 192.168.178.1", AppWinStyle.Hide, True)

Can you help me please, to do it without netsh?

joshi1984 47 Light Poster

It works now, with your last code. Thank you.
Here is the image from the console.

Unbenannt.png

joshi1984 47 Light Poster

ok, I only need the function "find_device_by_name".
I tried your console-version, after Question Devices name is "g930" nothing happens and it starts again with selection.
After this i tried it by changing it to my code with textbox and msgboxes to see where it is. So it doesn´t start with "For Each info..." and there is no exception too.

Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
        'Console.Write("Device's name is?: ")
        Dim name As String = TextBox1.Text
        Find_Device_By_Name(name)
    End Sub

    Function Find_Device_By_Name(name As String) As Boolean
        Try
            MsgBox("1")
            ' See if the desired device shows up in the device manager. '
            Dim info As Management.ManagementObject
            Dim search As New System.Management.ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE Name='" + name + "'")
            MsgBox("2")
            For Each info In search.Get()
                Dim ID As String = CType(info("DeviceID"), String)
                Label1.Text = "Device ID is: " + ID.ToString
                MsgBox("3")
                Return True ' Device has been Found '
                MsgBox("4")
            Next
        Catch ex As Exception
            MsgBox("5")
        End Try
        'We did not find the device we were looking for '
        Return False
    End Function
joshi1984 47 Light Poster

Please have a look at my post 1 minute earlier then your post ;)

Or is it only possible to search VID_PID? I thougt it is possible to search only for a name...
Because, I think VID_PID is like a searialnumber and it will be allways different at my pc to another pc!?!

joshi1984 47 Light Poster

I changed the code to do it with Textbox, Button and Label.
But it doesn´t find my devices furthermore.
For example : I got 2 Logitech USB-Devices connected. "Logitech G930 Gaming Headset" and "Logitech G19 LCD" (thats the names in the system control center)

here is my code :

Option Strict On
Imports System.Management

Public Class Form1
    Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
        Dim VID_PID_device = TextBox1.Text ' Change to your's 
        If Find_Device_By_VID_PID(VID_PID_device) Then
            Label1.Text = "Connected!"
        Else
            Label1.Text = "not connected"
        End If
    End Sub

    Sub ListDevices_VID_PID(Optional sFilter As String = "")
        Try
            Dim info As Management.ManagementObject
            Dim search As System.Management.ManagementObjectSearcher
            Dim Name As String
            search = New System.Management.ManagementObjectSearcher("SELECT * From Win32_PnPEntity")
            For Each info In search.Get()
                Name = CType(info("Caption"), String)
                Dim ID As String = CType(info("DeviceID"), String)
                If sFilter = "" OrElse InStr(ID, sFilter) Then
                    Console.WriteLine(Name + " " + ID)
                End If
            Next
        Catch ex As Exception

        End Try
    End Sub
    Function Find_Device_By_VID_PID(Device_VID_PID As String) As Boolean
        Try
            ' See if the desired device shows up in the device manager. '
            Dim info As Management.ManagementObject
            Dim search As System.Management.ManagementObjectSearcher
            search = New System.Management.ManagementObjectSearcher("SELECT * From Win32_PnPEntity")
            For Each info In search.Get()
                ' Go through each device detected.'
                Dim ID As String = CType(info("DeviceID"), String)
                If InStr(info.Path.ToString, Device_VID_PID) Then
                    Return True
                End If
            Next
        Catch ex As Exception

        End Try
        'We did not find the device we were looking for '
        Return False
    End Function
    End Class

So, why doesn´t find the …

joshi1984 47 Light Poster

ok, my fault... I got it.
Thank you!

joshi1984 47 Light Poster

I´m sorry. Ofcourse I know how to call a function, but I don´t know how to get the result in my case...

    Private Sub Is_USB_Device_Connected_Button_Click_1(sender As Object, e As EventArgs) Handles Is_USB_Device_Connected_Button.Click
        DetectDevice(TextBox1.Text, Label1.Text)
    End Sub
joshi1984 47 Light Poster

ok, got it and how can i search with this code "Logitech" or another name, what i´m looking for in my usb by typing in a textbox?

joshi1984 47 Light Poster

I knew this thread from vbforums.com, but it doesn´t work.
I did already imported the system.management with :

Imports System.Management

But it says "Management.ManagementObject"+"System.Management.ManagementObjectSearcher" is not defined.
And with this code I can´t get the status of "Logitech" or another name, what i´m looking for in my usb
periphery.

On my form is a textbox, label and a button. if i write "keyboard" or "logitech" in the textbox and i click on button the label should switch to "is connected" or "is not to connected"...

I´m so sorry, but my programming skills are to low for this, but I want to have this feature in my tool ;)

joshi1984 47 Light Poster

Hey community,

how can i show the connected USB-Device like keyboard, mouse, webcam and so on?
Or how can i search in the connected USB-Devices, if I know the name or only a part of the name?
I am looking for some examples since 2 days, but no one doesn´t work. So I hope you can help me with some code examples in vb.net.

best regards
joshi

joshi1984 47 Light Poster

I want a MessageBox if the "specification" is not in the csv-file.
I tried it with this code :

Try
            For Each row As String In File.ReadAllLines("Table.csv")
                ' split the fields from the row '
                Dim vFields() As String = Split(row, ";")
                If vFields(0).Contains(TextBox1.Text) Then ' vFields(0) = specificaion '
                    lblValue1.Text = vFields(1) ' vFields(1) is value 1 '
                    lblValue2.Text = vFields(2) ' vFields(2) is value 2
                Else
                    MsgBox("specification was not found")
                    Exit For
                End If
            Next
        Catch ex As Exception
            MsgBox(ex.Message) 'File was not found or something else
        End Try

But now is the problem its allways the MessageBox "specification was not found". It seems it doesn't search complete... but why?

joshi1984 47 Light Poster

Thank you very much.
It´s so simple and I didn´t found it how to split it...

joshi1984 47 Light Poster

Hello,

i got a table in Excel (or exported to CSV).
There are 3 columns (1. column = specification / 2. columns = value1 / 3. column = value2).
On my vb.net form i got a textbox, 2 labels and a button. If i write in in the textbox "5" it should search in the Excel or CSV-File in columns A (specification" the "5" and then it should show the both values in this row in label1 and label2.

I tried much things but i can only read and show the complete row in only one label and only from csv-file. but with the csv-file my result is like "47,55;33,2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"

Here is my code

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        For Each row As String In IO.File.ReadAllLines("Table.csv")
            If zeile.Contains(TextBox1.Text) Then 
                Label1.Text = row
                'Label2.Text = ????
            End If
        Next
End Sub

In the Attachement you can a screenshot from the Excel/CSV-File.

Can you help me please?

thank you
josh

Excel_CSV.png

joshi1984 47 Light Poster

Thank you, it works.

joshi1984 47 Light Poster

These examples doesn´t helped ;(

So here is my code : on the form is only a MaskedTextBox and a Button.

Option Strict On
Imports System
Imports System.Net.NetworkInformation
Imports System.IO
Imports System.Text
Imports System.ComponentModel
Imports System.Management
Imports System.Xml
Imports System.Text.RegularExpressions

Public Class Form1
    Dim myIPValue As String

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        MaskedTextBox1.Mask = "###.###.###.###"
        MaskedTextBox1.PromptChar = Chr(32) 'space character
    End Sub

    Private Sub MaskEdBox1_KeyPress(KeyAscii As Integer)
        Dim mySplit() As String, c As Integer, jumpC As Integer, tmpString As String, tmpSplit As String
        If KeyAscii = 46 Then
            mySplit = Split(MaskedTextBox1.Text, Chr(46), -1)
            For c = 0 To UBound(mySplit)
                If IsNumeric(mySplit(c)) Then jumpC = jumpC + 4
                If Len(Trim(mySplit(c))) < 3 Then mySplit(c) = Space(3 - Len(Trim(mySplit(c)))) & Trim(mySplit(c))
            Next c
            tmpString = mySplit(0) & "." & mySplit(1) & "." & mySplit(2) & "." & mySplit(3)
            MaskedTextBox1.Text = tmpString
            MaskedTextBox1.SelectionStart = jumpC
            KeyAscii = 0
        End If
    End Sub

    Private Sub MaskEdBox1_KeyUp(KeyCode As Integer, Shift As Integer)
        Dim validSplit() As String, v As Integer, validString As String
        validSplit = Split(MaskedTextBox1.Text, Chr(46), -1)
        For v = 1 To UBound(validSplit)
            If validSplit(v) = "" Or v = UBound(validSplit) Then
                If Val(Trim(validSplit(v - 1))) > 255 Or (v = UBound(validSplit) And Val(Trim(validSplit(v))) > 255) Then
                    MsgBox("Invalid value")
                    If Val(validSplit(3)) > 0 Then v = v + 1
                    validSplit(v - 1) = ""
                    validString = validSplit(0) & "." & validSplit(1) & "." & validSplit(2) & "." & validSplit(3)
                    MaskedTextBox1.Text = validString
                    MaskedTextBox1.SelectionStart = (v - 1) * 4
                    Exit …
joshi1984 47 Light Poster

Hello,

I want to have a manual IP-input-box like windows.

tcpip_properties.gif

I tried by MaskedTextBox but the problem is, the 3 pionts are sliding when i insert some numbers and i can insert letters and numbers higher then 255 (higher is not allowed in IP´s).

I hope anyone helps me, maybe with some codesnips!?! :)

best regards
josh

joshi1984 47 Light Poster

Now, I got the fault. It starts with the os (autostart windows), so "CurrentDirectory" is not equal "StartupPath".

I changed code to :

Function addImage(path As String) As Int32
        Label8.Text = Application.StartupPath
        Label12.Text = Environment.CurrentDirectory
        ListBox1.Items.Add(Environment.CurrentDirectory)
        Environment.CurrentDirectory = Application.StartupPath
        Dim i As Int32 = Array.IndexOf(vImgPath, path)
        'If i = -1 AndAlso Not IO.File.Exists(path) Then MsgBox("file not found: " + path)
        If i = -1 AndAlso IO.File.Exists(path) Then
            ReDim Preserve vImgPath(iv)
            Me.vImgPath(iv) = path
            i = iv
            iv += 1
        End If
        Return i
    End Function
joshi1984 47 Light Poster

I am so sorry, but I got a new problem with my code and I don´t find a fault in my code...

My Tool starts with windows automaticaly (autostart). At a "slow" machine the Images/icons from the nodes are not shown, but there is no exception...

What is the problem or how can I check where is the fault in my code???

Here is my code :

    Public Class MeineXmlWerte
        Public RunPath As String
        Public Argumente As String
    End Class
    Public Sub Load_XML()
        Try
            ' Get Xml's file stream.
            imgLst.ImageSize = New Drawing.Size(30, 27)
            Dim vPath() As String = Split(Application.ExecutablePath, "\")
            vPath(vPath.Length - 1) = "MyNodes.xml"
            Dim filepath As String = Join(vPath, "\")
            Dim _rstream As New FileStream(filepath, FileMode.Open)
            ' Load Xml document.
            '
            Dim dom As New XmlDocument()
            dom.Load(_rstream)
            _rstream.Close()
            ' Initialize treeView control.
            '
            TreeView_XML.BeginUpdate()
            TreeView_XML.Nodes.Clear()
            TreeView_XML.Nodes.Add(New TreeNode(dom.DocumentElement.Name))
            ' Populate the treeView with the dom nodes.
            '
            AddNode(dom.DocumentElement, TreeView_XML.Nodes(0))
            If CBool(iv) Then
                For i = 0 To iv - 1
                    imgLst.Images.Add(Image.FromFile(vImgPath(i)))
                Next
                TreeView_XML.ImageList = imgLst
            End If
            TreeView_XML.EndUpdate()
            'TreeView1.ExpandAll()
            TreeView_XML.Nodes(0).Expand()
        Catch xmlEx As XmlException
            MessageBox.Show(xmlEx.Message)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    Private Sub AddNode(ByVal inXmlNode As XmlNode, ByVal inTreeNode As TreeNode)
        Dim mk As MeineXmlWerte = New MeineXmlWerte()
        inTreeNode.Tag = mk
        Dim i As Integer
        If inXmlNode.HasChildNodes Then
            Dim nodeList As XmlNodeList
            nodeList = inXmlNode.ChildNodes
            i = 0
            While i <= nodeList.Count - 1
                Dim xNode As XmlNode = inXmlNode.ChildNodes(i)
                Dim imgIndex As Int32 = -1
                Dim SelimgIndex As Int32 = -1
                If xNode.Attributes …
joshi1984 47 Light Poster

Thank you very much. I will try it and make some tests.

joshi1984 47 Light Poster

Hello Daniweb-Community,

I got a node in my xml-File for a java-link. it looks like "C:\Program Files (x86)\Tool7\javaw.exe -splash:splash.png -cp ./cl/cl.jar; -Dawt.useSystemAAFontSettings=on"
If i start the tool by double click on the node, it doesn´t start it, because it doesn´t load the arguments.
Next i createt a new attribut (called Argument) in the xml-file at this node and the value in "Argumente" is "-splash:splash.png -cp ./cl/cl.jar; -Dawt.useSystemAAFontSettings=on". But it still doesn´t work.

So, it doesn´t read the attribut in the XML, but i don´t know why. I hope you can help me again? :)

Here is the XML-Code :

<?xml version="1.0" encoding="UTF-8"?>
<Programme Path="1">
  <Feld Icon="Folder.ico" Path="2">Feld 1<VisualStudio Path="C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe" Icon="VS.png">Visual Studio</VisualStudio>
    <Excel Path="C:\Program Files\Microsoft Office 15\root\office15\EXCEL.EXE" Icon="Excel.png">Excel</Excel>
  </Feld>
  <Home Icon="Folder.ico" Path="3">Home Place<Notepad Path="C:\Program Files\Notepad++\notepad++.exe" Icon="notepad.png">Notepad ++</Notepad>
    <JaTool Path="C:\Program Files (x86)\Tool7\javaw.exe" Argumente="-splash:splash.png -cp ./cl/cl.jar; -Dawt.useSystemAAFontSettings=on" Icon="JaTool.ico" RunPath="C:\Program Files (x86)\Tool7\bin\..">JaTool</JaTool>
  </Home>
</Programme>

Here is my VB-Code :

Option Strict On
Imports System.Xml
Imports System.IO
Imports System.Text
Imports System.Text.RegularExpressions
Public Class treeViewLoadXml
    Dim imgLst As New ImageList
    Dim vImgPath(-1) As String, iv As Int32 = 0
    Private Sub treeViewLoadXml_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Load_XML()
    End Sub
    Public Sub Load_XML()
        Try
            ' Get Xml's file stream.
            imgLst.ImageSize = New Drawing.Size(30, 27)
            Dim vPath() As String = Split(Application.ExecutablePath, "\")
            vPath(vPath.Length - 1) = "XMLFile1.xml"
            Dim filepath As String = Join(vPath, "\")
            Dim _rstream As New FileStream(filepath, FileMode.Open)
            ' Load Xml document.
            '
            Dim dom As New XmlDocument()
            dom.Load(_rstream)
            _rstream.Close()
            ' Initialize treeView control.
            '
            TreeView1.BeginUpdate() …
joshi1984 47 Light Poster

5 months ago and now i got a new problem in my code ;-)

I got a node in my xml-File for a java-link. it looks like "C:\Program Files (x86)\Tool7\javaw.exe -splash:splash.png -cp ./cl/cl.jar; -Dawt.useSystemAAFontSettings=on"

If i start the tool by double click on the node, it doesn´t start it, because it doesn´t load the arguments.

Next i createt a new attribut (called Argument) in the xml-file at this node and the value in "Argumente" is "-splash:splash.png -cp ./cl/cl.jar; -Dawt.useSystemAAFontSettings=on". But it still doesn´t work.

So, it doesn´t read the attribut in the XML, but i don´t know why. I hope you can help me again? :)

Here is the XML-Code :

<?xml version="1.0" encoding="UTF-8"?>
<Programme Path="1">
  <Feld Icon="Folder.ico" Path="2">Feld 1<VisualStudio Path="C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe" Icon="VS.png">Visual Studio</VisualStudio>
    <Excel Path="C:\Program Files\Microsoft Office 15\root\office15\EXCEL.EXE" Icon="Excel.png">Excel</Excel>
  </Feld>
  <Home Icon="Folder.ico" Path="3">Home Place<Notepad Path="C:\Program Files\Notepad++\notepad++.exe" Icon="notepad.png">Notepad ++</Notepad>
    <JaTool Path="C:\Program Files (x86)\Tool7\javaw.exe" Argumente="-splash:splash.png -cp ./cl/cl.jar; -Dawt.useSystemAAFontSettings=on" Icon="JaTool.ico" RunPath="C:\Program Files (x86)\Tool7\bin\..">JaTool</JaTool>
  </Home>
</Programme>

Here is my VB-Code :

Option Strict On
Imports System.Xml
Imports System.IO
Imports System.Text
Imports System.Text.RegularExpressions
Public Class treeViewLoadXml
    Dim imgLst As New ImageList
    Dim vImgPath(-1) As String, iv As Int32 = 0
    Private Sub treeViewLoadXml_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Load_XML()
    End Sub
    Public Sub Load_XML()
        Try
            ' Get Xml's file stream.
            imgLst.ImageSize = New Drawing.Size(30, 27)
            Dim vPath() As String = Split(Application.ExecutablePath, "\")
            vPath(vPath.Length - 1) = "XMLFile1.xml"
            Dim filepath As String = Join(vPath, "\")
            Dim _rstream As New FileStream(filepath, FileMode.Open)
            ' Load Xml document.
            '
            Dim dom As …
joshi1984 47 Light Poster

Thank you for this trick

joshi1984 47 Light Poster

Thank you very much.

I changed the DoubleClick-Sub, because I don´t want any messagebox, if I click on a folder... But I think, my solution isn´t the best, because allways I have to change the vb-code, if I create a new folder in my xml-file.

    Private Sub TreeView1_NodeMouseDoubleClick(sender As Object, e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseDoubleClick
        Try
            Dim Path As String = TreeView1.SelectedNode.Name
            If e.Node.Text = "Programme" Then
            ElseIf e.Node.Text = "Feld 1" Then
            ElseIf e.Node.Text = "Home Place" Then
            Else
                If File.Exists(Path) Then
                    Process.Start(Path)
                Else
                    MsgBox("kein Programm gefunden")
                End If
            End If
        Catch ex As Exception
            MsgBox("kein Programm gefunden")
        End Try
    End Sub
joshi1984 47 Light Poster

I´m sorry, but I doesn´t understand what you mean.

Yes, my TreeView control on my form is called "TreeView1". If I change "MyTreeNode1.Load_XML()" to "TreeView1.Load_XML()" it is still the same problem.
Where can I find it to change the instances? I searched it also in the propertys from the TreeView1-Control, because I didn´t find something like that at the top of my toolsbar.

joshi1984 47 Light Poster

I can´t start the Sub "Load_XML" by

MyTreeNode1.Load_XML()

Error-code is something like : "Load_XML" is not declared. The object can not be used because the protection level.

I allready changed it in only Load_XML() but it is allways the same problem.

joshi1984 47 Light Poster

Great it works. I tried to change this line a few days ago, but only all things behind "+="... If i would changed it in only "=". Maybe then I would found it by myself some days ago ;-)

So, now I got only one thing which doesn´t work...
The doubleclick-event doesn´t start the programs. I think it doesn´t read the path from the xml!?

At the beginning I got :

Public Class MyTreeNode
        Inherits TreeNode
        Public Property Path As String
    End Class

and this is my double-click-sub

Sub treeView1_NodeMouseDoubleClick(ByVal sender As Object, ByVal e As TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseDoubleClick
        Try
            Dim Path = TryCast(TreeView1.SelectedNode, MyTreeNode).Path
            If Path IsNot Nothing Then Process.Start(Path)
        Catch ex As Exception
            MsgBox("kein Programm gefunden")
        End Try
    End Sub

If I double click on the programs, always the Exception (Messagebox) comes.

Can you tell me, please, what is wrong?

joshi1984 47 Light Poster

In the screenshot you can see the nodes. to explain my problem, look (for example) only to the node "VisualStudio Visual Studio".

The first"VisualStudio" (without empty space between the 2 words) = node-name in the xml-file.
The second "Visual Studio" (with empty space between the 2 words) = node-text in the xml-file.

Normaly you can only see the node-text in treeviews.

For more example maybe this : if i create the nodes manualy in the form, it shows ONLY the node.text
Tree_Create.png

I´m sorry, but i can´t solve it by myself, because i don´t know how...

joshi1984 47 Light Poster

I don´t know why, but it still show the node names like "visualstudio". normaly it shows only the nodes-text like "visual studio" (space between the words).
tree3105.jpg

this is the xml :

<?xml version="1.0" encoding="UTF-8"?>
<Programme>
  <Feld Icon="Folder.ico">Feld 1<VisualStudio Path="C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe" Icon="VS.png">Visual Studio</VisualStudio>
    <Excel Path="C:\Program Files\Microsoft Office 15\root\office15\EXCEL.EXE" Icon="Excel.png">Excel</Excel>
  </Feld>
  <Home Icon="Folder.ico">Home Place<Notepad Path="C:\Program Files\Notepad++\notepad++.exe" Icon="notepad.png">Notepad ++</Notepad>
  </Home>
</Programme>
joshi1984 47 Light Poster

I don´t know why, but the images for each nodes are allways the same. I tried by the taking the whole path to the icon/png in the xml and i tried it with only the the file too. <- nothing works. It´s allways the "old" folder.ico for all nodes in the treeview.
tree.png

<?xml version="1.0" encoding="UTF-8"?>
<Programme>
  <Feld Icon="Folder.ico">Feld 1<VisualStudio Path="C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe" Icon="I:\TestProgramm\eigen Test\xmltest_vb-paradies\xmltest\bin\Debug\VS.png">Visual Studio</VisualStudio>
    <Excel Path="C:\Program Files\Microsoft Office 15\root\office15\EXCEL.EXE" Icon="Excel.png">Excel</Excel>
  </Feld>
  <Home Icon="Folder.ico">Home Place<Notepad Path="C:\Program Files\Notepad++\notepad++.exe" Icon="notepad.png">Notepad ++</Notepad>
  </Home>
</Programme>

I tried also to changes the code, that it shows only the node.text, but it doesn´t work.

And the last problem is, it doesn´t read the "path"-attribute, so i can´t start the programs. the error message is always the exception from try/catch in my sub treeView1_NodeMouseDoubleClick.
Here is my complete code :

Option Strict On
Imports System.Xml
Imports System.Reflection
Imports System.IO
Imports System.Text
Imports System.Text.RegularExpressions

Public Class treeViewLoadXml
    Public Class MyTreeNode
        Inherits TreeNode
        Public Property Path As String
    End Class
    Dim imgLst As New ImageList
    Dim vImgPath(-1) As String, iv As Int32 = 0
    Private Sub treeViewLoadXml_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        imgLst.ImageSize = New Drawing.Size(30, 27)
        LoadXML()
    End Sub
    Private Sub LoadXML()
        Try
            Dim vPath() As String = Split(Application.ExecutablePath, "\")
            vPath(vPath.Length - 1) = "nodes.xml"
            Dim filepath As String = Join(vPath, "\")
            Dim _rstream As New FileStream(filepath, FileMode.Open)
            Dim dom As New XmlDocument()
            dom.Load(_rstream) 
            treeView1.Nodes.Clear()
            treeView1.Nodes.Add(New TreeNode(dom.DocumentElement.Name))
            Dim tNode As TreeNode = treeView1.Nodes(0)
             treeView1.Nodes.Add(dom.DocumentElement.Name)
            AddNode(dom.DocumentElement, …
joshi1984 47 Light Poster

Yes, you can see for Example at "Programm Visual Studio" <-- "Programm" = node-name ; "Visual Studio" = node-text.

Normaly in TreeViews only node-text is shown.

joshi1984 47 Light Poster

Something more goes wrong now ;-)

1) here is my xml. the path to the executable is in there.

<?xml version="1.0" encoding="UTF-8"?>
<Programme>
  <Feld Icon="Folder.ico">Feld 1<VisualStudio Path="C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe" Icon="VS.png">Visual Studio</VisualStudio>
    <Excel Path="C:\Program Files\Microsoft Office 15\root\office15\EXCEL.EXE" Icon="Excel.png">Excel</Excel>
  </Feld>
  <Home Icon="Folder.ico">Home Place<Notepad Path="C:\Program Files\Notepad++\notepad++.exe" Icon="notepad.png">Notepad ++</Notepad>
  </Home>
</Programme>

2) now, it shows name and text together... normaly it would shows only the text. And now it loads the first image for all nodes.
form_XML_1.png

joshi1984 47 Light Poster

2 more Questions :

  1. It creates also a separate node for Node Name and Node Text. But normaly it should only show one node with only the node text...

  2. Bevor I added the code for the Icons/Pictures, I can start the programms by double click on it with my code. Now I get allways the Exception MessageBox, it can´t find the program. But I don´t know why... The path-string in the xml is the same like bevor!?!?

Here is my code with the process.Start and so on :

Option Strict On
Imports System.Xml
Imports System.Reflection
Imports System.IO
Imports System.Text
Imports System.Text.RegularExpressions

Public Class treeViewLoadXml
    Public Class MyTreeNode
        Inherits TreeNode
        Public Property Path As String
    End Class
    Dim imgLst As New ImageList
    Dim vImgPath(-1) As String, iv As Int32 = 0
    Private Sub treeViewLoadXml_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        imgLst.ImageSize = New Drawing.Size(30, 27)
        LoadXML()
    End Sub
    Private Sub LoadXML()
        Try
            ' Get Xml's file stream.
            'Dim _assembly As [Assembly] = [Assembly].GetExecutingAssembly
            ''Dim _stream As Stream = _assembly.GetManifestResourceStream("MyNameSpace.XMLFile1.xml")
            ''Dim _rStream As New IO.StreamReader(_stream)
            '
            Dim vPath() As String = Split(Application.ExecutablePath, "\")
            vPath(vPath.Length - 1) = "XMLFile1.xml"
            Dim filepath As String = Join(vPath, "\")
            Dim _rstream As New FileStream(filepath, FileMode.Open)
            ' Load Xml document.
            '
            Dim dom As New XmlDocument()
            dom.Load(_rstream) 'dom.Load(_rStream.BaseStream)
            ' Initialize treeView control.
            '
            treeView1.Nodes.Clear()
            treeView1.Nodes.Add(New TreeNode(dom.DocumentElement.Name))
            Dim tNode As TreeNode = treeView1.Nodes(0)
            ' Populate the treeView with the dom nodes.
            '
            treeView1.Nodes.Add(dom.DocumentElement.Name)
            AddNode(dom.DocumentElement, tNode)
            If CBool(iv) Then
                For i = 0 To …
joshi1984 47 Light Poster

2 more Questions :

  1. It creates also a separate node for Node Name and Node Text. But normaly it should only show one node with only the node text...

  2. Bevor I added the code for the Icons/Pictures, I can start the programms by double click on it with my code. Now I get allways the Exception MessageBox, it can´t find the program. But I don´t know why... The path-string in the xml is the same like bevor!?!?

Here is my code with the process.Start and so on :

Option Strict On
Imports System.Xml
Imports System.Reflection
Imports System.IO
Imports System.Text
Imports System.Text.RegularExpressions

Public Class treeViewLoadXml
    Public Class MyTreeNode
        Inherits TreeNode
        Public Property Path As String
    End Class
    Dim imgLst As New ImageList
    Dim vImgPath(-1) As String, iv As Int32 = 0
    Private Sub treeViewLoadXml_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        imgLst.ImageSize = New Drawing.Size(30, 27)
        LoadXML()
    End Sub
    Private Sub LoadXML()
        Try
            ' Get Xml's file stream.
            'Dim _assembly As [Assembly] = [Assembly].GetExecutingAssembly
            ''Dim _stream As Stream = _assembly.GetManifestResourceStream("MyNameSpace.XMLFile1.xml")
            ''Dim _rStream As New IO.StreamReader(_stream)
            '
            Dim vPath() As String = Split(Application.ExecutablePath, "\")
            vPath(vPath.Length - 1) = "XMLFile1.xml"
            Dim filepath As String = Join(vPath, "\")
            Dim _rstream As New FileStream(filepath, FileMode.Open)
            ' Load Xml document.
            '
            Dim dom As New XmlDocument()
            dom.Load(_rstream) 'dom.Load(_rStream.BaseStream)
            ' Initialize treeView control.
            '
            treeView1.Nodes.Clear()
            treeView1.Nodes.Add(New TreeNode(dom.DocumentElement.Name))
            Dim tNode As TreeNode = treeView1.Nodes(0)
            ' Populate the treeView with the dom nodes.
            '
            treeView1.Nodes.Add(dom.DocumentElement.Name)
            AddNode(dom.DocumentElement, tNode)
            If CBool(iv) Then
                For i = 0 To …
joshi1984 47 Light Poster

I got one more problem with my XML-File or TreeView :

If I create the xml-file it looks all right.
Edit_XML.png

If I start my program there are more nodes and then I created... Normaly there is only the first Tree named "Nodes" under this, there should be 2 Nodes named "Programme" and "andere". In the Node "Programme" are only "Visual Studio" and "Excel" and in "andere" only "Notepad".
It looks a little bit strange, then my created XML-File...
form_XML.png

I think there is something wrong in "LoadXML"- or "AddNode"-Private Sub?

Option Strict On
Imports System.Xml
Imports System.Reflection
Imports System.IO
Imports System.Text
Imports System.Text.RegularExpressions

Public Class treeViewLoadXml

    Dim imgLst As New ImageList
    Dim vImgPath(-1) As String, iv As Int32 = 0
    Private Sub treeViewLoadXml_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        imgLst.ImageSize = New Drawing.Size(30, 27)
        LoadXML()
    End Sub
    Private Sub LoadXML()
        Try
            ' Get Xml's file stream.
            'Dim _assembly As [Assembly] = [Assembly].GetExecutingAssembly
            ''Dim _stream As Stream = _assembly.GetManifestResourceStream("MyNameSpace.XMLFile1.xml")
            ''Dim _rStream As New IO.StreamReader(_stream)
            '
            Dim vPath() As String = Split(Application.ExecutablePath, "\")
            vPath(vPath.Length - 1) = "XMLFile1.xml"
            Dim filepath As String = Join(vPath, "\")
            Dim _rstream As New FileStream(filepath, FileMode.Open)
            ' Load Xml document.
            '
            Dim dom As New XmlDocument()
            dom.Load(_rstream) 'dom.Load(_rStream.BaseStream)
            ' Initialize treeView control.
            '
            treeView1.Nodes.Clear()
            treeView1.Nodes.Add(New TreeNode(dom.DocumentElement.Name))
            Dim tNode As TreeNode = treeView1.Nodes(0)
            ' Populate the treeView with the dom nodes.
            '
            treeView1.Nodes.Add(dom.DocumentElement.Name)
            AddNode(dom.DocumentElement, tNode)
            If CBool(iv) Then
                For i = 0 To …
joshi1984 47 Light Poster

Yeah thank you very much. You made my day!!!

joshi1984 47 Light Poster

I get an error : "BaseStream is not a Member of System.IO.FileStream"

    Private Sub LoadXML()
        Try
            ' Get Xml's file stream.
            Dim vPath() As String = Split(Application.ExecutablePath, "\")
            vPath(vPath.Length - 1) = "XMLFile1.xml"
            Dim filepath As String = Join(vPath, "\")
            Dim _rstream As New FileStream(filepath, FileMode.Open)
            ' Load Xml document.
            '
            Dim dom As New XmlDocument()
            dom.Load(_rStream.BaseStream)
joshi1984 47 Light Poster

I compiled it in vs.
then I copy my exe-File in another folder. After this i started the application, it used the XML-File from inside the application and it created the xml-File in the folder. Then i closed the application.
After this i changed the xml-File by another tool.
When I started again my application it takes again the xml-file from inside the exe-file.

It is necessary, that it starts alway the xml-file from my folder. now matter if my application is newer then the XML-File from my folder.

joshi1984 47 Light Poster

Thank you, it works.

But now i got my next question : If I do it like this, i can only change the code in the XML-File in my application himself via Visual-Studio.
If i changed the code only in the XML-File in my Application-Folder on my hdd, it ignored them and overwrite it by the old file.
Do you know what i mean?

How can I do change it, that my application load at start the XML-File from my hdd?

joshi1984 47 Light Poster

ok, if i copy your code and create a xml named "XMLFile1.xml" with your xml-code too, it is still the same Errormessage.
But which value is it?

joshi1984 47 Light Poster

I tried both codes.

But, i get always at startup the messagebox with the error "the value should not be 0" (it is my translation in english, because i got a german version) and after this my treeview is empty.

Is it because i changed

Dim _stream As Stream = _assembly.GetManifestResourceStream("MyNameSpace.XMLFile1.xml")

to

Dim _stream As Stream = _assembly.GetManifestResourceStream("MyNameSpace.nodes-kopie.xml")

?

joshi1984 47 Light Poster

I know, but i don´t know how to copy the images to an ImageList and assign to the TreeView.ImageList property by my code...

joshi1984 47 Light Poster

Hello,
I´m not a professional in vb.net, but i try to make a tool for my colleague and me. I got a XMLTreeView on my form and i load a XML-File in it. Now, I want to set each node in the XMLTreeView another icon, but it must set by the XML-File.

This is my XML-File :

<?xml version="1.0" encoding="utf-8" ?> <Nodes> <Node Text="Programme" Icon="BlaBlub.ico"> <Node Text="Test" Icon="C:\MyProgramm\Icons\icon2.ico"> <Programm Path="C:\Program Files (x86)\Microsoft Visual" & _
        "Studio\2017\Enterprise\Common7\IDE\devenv.exe">Visual Studio</Programm> <Programm Path="C:\Program Files (x86)\Microsoft" & _
      "Office\root\Office16\EXCEL.EXE">Excel</Programm> </Node> <Node Text="andere" Icon="C:\MyProgramm\Icons\23.ico"> <Programm Path="C:\Program Files (x86)\Microsoft Visual" & _
        "Studio\VB98\VB6.EXE">VB.NET</Programm> </Node> <Node Text="Test1" Icon="Huhu.ico"> <Programm>bla</Programm> <Programm>blup</Programm> </Node> </Node> </Nodes>

This is my vb.net code :

Option Explicit On
Option Strict On
Imports System
Imports System.Net
Imports System.Net.Sockets
Imports System.Runtime.InteropServices
Imports System.Net.NetworkInformation
Imports System.IO
Imports System.Text
Imports System.Diagnostics
Imports System.ComponentModel
Imports System.Drawing
Imports System.Management
Imports Microsoft.Win32
Imports System.Threading
Imports System.Xml
Imports System.Collections.Generic
Imports System.Windows.Forms
Public Class XmlTreeView
    Public Class MyTreeNode
        Inherits TreeNode
        Public Property Path As String
    End Class
   Public Shared Sub LoadFromXml(ByVal FileName As String, ByVal TheTreeView As TreeView)
        Dim xDoc As New XmlDocument
        xDoc.Load(FileName)
        FillTreeView(TheTreeView.Nodes, xDoc.DocumentElement)
    End Sub
    Private Shared Sub FillTreeView(ByVal CurrentNodes As TreeNodeCollection, ByVal xNode As XmlNode)
        For Each xChild As XmlNode In xNode.ChildNodes
            If xChild.Name <> "Programm" Then
                FillTreeView(CurrentNodes.Add(xChild.Name).Nodes, xChild)
            Else
                CurrentNodes.Add(New MyTreeNode With {.Text = xChild.InnerText, .Path = xChild.Attributes("Path").Value})
            End If
        Next
    End Sub
    Sub treeView1_NodeMouseDoubleClick(ByVal sender As Object, ByVal e As TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseDoubleClick
        Try
            Dim path = TryCast(TreeView1.SelectedNode, MyTreeNode).Path
            If path IsNot Nothing Then Process.Start(path)
        Catch …