xrjf 230 Posting Whiz

Here is a modification because it worked for comma delimited, but not for my contacts.csv semicolon delimited.

Imports System.IO
Imports System.Text
Imports System.Text.RegularExpressions

Public Class CSV

    Dim separator As String
    Dim nErr As Int32
    Private Sub btnLoad_Click(sender As System.Object, e As System.EventArgs) Handles btnLoad.Click
        Try
            btnLoad.Enabled = False
            OpenFileDialog1.Filter = "CSV Files (*.CSV)|*.CSV|All Files (*.*)|*.*"
            OpenFileDialog1.FilterIndex = 1
            Dim r As DialogResult = OpenFileDialog1.ShowDialog
            If r <> Windows.Forms.DialogResult.OK Then
                Exit Try
            End If
            nErr = 0
            Dim ts As New TimeSpan(Now.Ticks)
            Dim dt As DataTable = parseCSV(OpenFileDialog1.FileName)
            Dim ts2 As New TimeSpan(Now.Ticks - ts.Ticks)
            DataGridView1.DataSource = dt
            MessageBox.Show((ts2.TotalMilliseconds).ToString)
        Catch ex As Exception
        Finally
            btnLoad.Enabled = True
        End Try
    End Sub
    Function parseCSV(filename As String) As DataTable
        Dim dt As DataTable = Nothing
        Dim fs As FileStream = Nothing
        Try
            fs = New FileStream(filename, FileMode.Open)
            Dim sr As New StreamReader(fs)
            Dim sbCSV As New StringBuilder(sr.ReadToEnd)
            fs.Close()
            separator = tbSeparator.Text
            Dim pos As Int32 = 0
            Dim vFields(-1) As String, iv As Int32 = 0
            Dim firsRow() As String = nextRow(pos, sbCSV)
            dt = New DataTable
            For i As Int32 = 0 To firsRow.Length - 1
                dt.Columns.Add(firsRow(i))
            Next
            Do While pos < sbCSV.Length
                dt.Rows.Add(nextRow(pos, sbCSV))
            Loop
        Catch ex As Exception
            If nErr <> 5 Then
                MessageBox.Show(ex.Message)
            End If
        End Try
        Return dt
    End Function
    Function nextRow(ByRef pos As Int32, sbcsv As StringBuilder) As String()
        Dim vRet(-1) As String, iv As Int32 = 0
        Try
            Do
                Dim field As String = nextField(pos, sbcsv)
                If field = vbCrLf Then
                    Exit Do
                End If
                ReDim …
xrjf 230 Posting Whiz

I have tried to allow carriage returns:

Imports System.IO
Imports System.Text
Imports System.Text.RegularExpressions

Public Class CSV

    Dim separator As String
    Private Sub btnLoad_Click(sender As System.Object, e As System.EventArgs) Handles btnLoad.Click
        Try
            btnLoad.Enabled = False
            OpenFileDialog1.Filter = "CSV Files (*.CSV)|*.CSV|All Files (*.*)|*.*"
            OpenFileDialog1.FilterIndex = 1
            Dim r As DialogResult = OpenFileDialog1.ShowDialog
            If r <> Windows.Forms.DialogResult.OK Then
                Exit Try
            End If
            Dim dt As DataTable = parseCSV(OpenFileDialog1.FileName)
            DataGridView1.DataSource = dt
        Catch ex As Exception
        Finally
            btnLoad.Enabled = True
        End Try
    End Sub
    Function parseCSV(filename As String) As DataTable
        Dim dt As DataTable = Nothing
        Dim fs As FileStream = Nothing
        Try
            fs = New FileStream(filename, FileMode.Open)
            Dim sr As New StreamReader(fs)
            Dim sbCSV As New StringBuilder(sr.ReadToEnd)
            fs.Close()
            separator = tbSeparator.Text
            Dim pos As Int32 = 0
            Dim vFields(-1) As String, iv As Int32 = 0
            Dim firsRow() As String = nextRow(pos, sbCSV)
            dt = New DataTable
            For i As Int32 = 0 To firsRow.Length - 1
                dt.Columns.Add(firsRow(i))
            Next
            Do While pos < sbCSV.Length
                dt.Rows.Add(nextRow(pos, sbCSV))
            Loop
        Catch ex As Exception
        End Try
        Return dt
    End Function
    Function nextRow(ByRef pos As Int32, sbcsv As StringBuilder) As String()
        Dim vRet(-1) As String, iv As Int32 = 0
        Try
            Do
                Dim field As String = nextField(pos, sbcsv)
                If field = vbCrLf Then
                    Exit Do
                End If
                ReDim Preserve vRet(iv)
                vRet(iv) = field
                iv += 1
            Loop
        Catch ex As Exception

        End Try
        Return vRet
    End Function
    Function nextField(ByRef pos As Int32, sbcsv As StringBuilder) As String
        Dim sRet As String = ""
        Try
            Select Case …
xrjf 230 Posting Whiz

jointables.png

SELECT e.classid, 
       a.planname, 
       b.workoutname,
       e.date,
       c.timeslot,
       e.status,
       d.staffemail
FROM   tblclass e
JOIN   tblallocation f ON e.planallocationid = f.planallocationid
JOIN   tblplan a     ON a.planid = f.planid
JOIN   tblworkout b  ON b.workoutid = f.workoutid
JOIN   tblstaff d  ON d.staffid = e.staffid
JOIN   tbltimeslot c ON c.timeslotid = e.timeslotid
xrjf 230 Posting Whiz

turretangle.png

This is physics and has to do, in my opinion, with OOP more or less like physical.
The solution I think is θ' = π - θ because I should have taken PP' instead of P'P.

xrjf 230 Posting Whiz

Try this:

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 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()
            treeView1.Nodes.Clear()
            treeView1.Nodes.Add(New TreeNode(dom.DocumentElement.Name))

            ' Populate the treeView with the dom nodes.
            '
            AddNode(dom.DocumentElement, treeView1.Nodes(0))
            If iv Then
                For i = 0 To iv - 1
                    imgLst.Images.Add(Image.FromFile(vImgPath(i)))
                Next
                treeView1.ImageList = imgLst
            End If
            treeView1.EndUpdate()
            treeView1.ExpandAll()
        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 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
                If xNode.Attributes IsNot Nothing Then
                    For Each att As XmlAttribute In xNode.Attributes
                        If att.Name = "Icon" Then
                            imgIndex = addImage(att.Value)
                            Exit For
                        End If
                    Next
                End If
                Dim tNode As New TreeNode(xNode.Name)
                Dim bIsTxt As Boolean = False
                If tNode.Text = "#text" Then
                    tNode.Text = xNode.Value
                    bIsTxt = True
                End If
                If imgIndex <> -1 Then
                    tNode.ImageIndex = …
xrjf 230 Posting Whiz

Perhaps you are asking for DataGridView1.CellClickevent ?

xrjf 230 Posting Whiz

You must develope and install a driver. Search for MS' DDK, driver deveopment kit.

rproffitt commented: That's most likely the right way to do it. But the OP's story is untold. +12
xrjf 230 Posting Whiz

Be more explicit, please, and explain what amount, what listbox and what code is there. Copy here any code you have and tell what you expect the program to do for you.

xrjf 230 Posting Whiz

Do you get any error message? Enclose in a try/catch. Variable bFound is what for?

xrjf 230 Posting Whiz

What I get with the variated code:

treeView3.PNG

xrjf 230 Posting Whiz

1) Perhaps it can't find the executables because you didn' t employ your's xml:

<?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>

2) You may use this variation in order to join node and node text:

    Private Sub AddNode(ByVal inXmlNode As XmlNode, ByVal inTreeNode As TreeNode)
        Dim i As Integer
        If inXmlNode.HasChildNodes Then
            Dim nodeList As XmlNodeList
            nodeList = inXmlNode.ChildNodes
            i = 0
            While i <= nodeList.Count - 1
                Dim imgIndex As Int32 = -1
                For Each att As XmlAttribute In inXmlNode.Attributes
                    If att.Name = "Icon" Then
                        imgIndex = addImage(att.Value)
                    End If
                Next
                Dim xNode As XmlNode = inXmlNode.ChildNodes(i)
                Dim tNode As New TreeNode(xNode.Name)
                Dim bIsTxt As Boolean = False
                If tNode.Text = "#text" Then
                    tNode.Text = xNode.Value
                    bIsTxt = True
                End If
                If imgIndex <> -1 Then
                    tNode.ImageIndex = imgIndex
                End If
                If Not bIsTxt Then
                    inTreeNode.Nodes.Add(tNode)
                    AddNode(xNode, tNode)
                Else
                    inTreeNode.Text += " " + tNode.Text
                End If
                i += 1
            End While
        End If
    End Sub
xrjf 230 Posting Whiz

Yes, get the AddNode() from my last code, because seems to me the AddNode() is not working properly

    Private Sub AddNode(ByVal inXmlNode As XmlNode, ByVal inTreeNode As TreeNode)
        Dim i As Integer
        If inXmlNode.HasChildNodes Then
            Dim nodeList As XmlNodeList
            nodeList = inXmlNode.ChildNodes
            i = 0
            While i <= nodeList.Count - 1
                Dim imgIndex As Int32 = -1
                For Each att As XmlAttribute In inXmlNode.Attributes
                    If att.Name = "Icon" Then
                        imgIndex = addImage(att.Value)
                    End If
                Next
                Dim xNode As XmlNode = inXmlNode.ChildNodes(i)
                Dim tNode As New TreeNode(xNode.Name)
                If tNode.Text = "#text" Then
                    tNode.Text = xNode.Value
                End If
                If imgIndex <> -1 Then
                    tNode.ImageIndex = imgIndex
                End If
                inTreeNode.Nodes.Add(tNode)
                AddNode(xNode, tNode)
                i += 1
            End While
        End If
    End Sub
xrjf 230 Posting Whiz

One thing you may do is try to define exactly what do you mean by a complete solution and try by yourself to accomplish that target. Then you may share your code, doubts and difficulties -if any.

xrjf 230 Posting Whiz

...also it may be a static variable.

xrjf 230 Posting Whiz

The number does not increment because the error counter in erorcunt is defined locally, so each time there is a try for username and password erorcunt value is 0 and incremented to 1. Define this variable errorcntat class level.

xrjf 230 Posting Whiz

What's the message? In which line?

xrjf 230 Posting Whiz

I hope it makes sense to you:

    Private Sub Dgv_Formate(ByVal e As DataGridViewCellFormattingEventArgs, _
                            ByVal Stat As String, _
                            ByVal processDate As Date, _
                            ByVal Extra_Days As Boolean)
        Try
            Dim YN As Int32 = IIf(Me.DGV_Machining.Rows(e.RowIndex).Cells(Stat).FormattedValue = "n", 0, 1)
            Dim extraDays As String = IIf(Not DGV_Machining.Rows(e.RowIndex).Cells(0).Value, 1, 0)
            Dim procDate As Date = DGV_Machining.Rows(e.RowIndex).Cells(1).Value
            Dim lt As Int32
            If procDate < thisDate Then
                lt = 0
            ElseIf procDate > thisDate Then
                lt = 1
            Else
                lt = 2
            End If
            Dim nAction As Int32 = YN * 6 + Extra_Days * 3 + lt
            Select Case nAction
                Case 0 : Action(e, Color.Yellow, Color.Red, False, True, False)
                Case 1 : Action(e, Color.White, Color.Red, True, True, False)
                Case 2 : Action(e, Color.White, Color.Red, False, True, False)
                Case 3 : Action(e, Color.Yellow, Color.Black, False, False, False)
                Case 4 : Action(e, Color.White, Color.Black, True, False, False)
                Case 5 : Action(e, Color.White, Color.Black, False, False, False)
                Case 6 : Action(e, Color.Yellow, Color.Red, False, True, True)
                Case 7
                Case 8
                Case 9
                Case 10
                Case 11
            End Select
        Catch ex As Exception

        End Try
    End Sub
    Sub Action(e As DataGridViewCellFormattingEventArgs, _
               bkClr As Color, _
               foreClr As Color, _
               Bold As Boolean, _
               italic As Boolean, _
               _strike As Boolean)
        Dim fnt As Font = Me.DGV_Machining.DefaultCellStyle.Font
        With e.CellStyle
            .BackColor = bkClr
            .ForeColor = foreClr
            Dim style As New FontStyle
            If Bold Then
                style = FontStyle.Bold
            End If
            If italic Then
                style = style Or FontStyle.Italic
            End If
            If _strike Then
                style = style Or FontStyle.Strikeout …
xrjf 230 Posting Whiz

You are welcome.

xrjf 230 Posting Whiz

I pass to you all the code again to be sure you can get it well.

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 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()
            treeView1.Nodes.Clear()
            treeView1.Nodes.Add(New TreeNode(dom.DocumentElement.Name))

            ' Populate the treeView with the dom nodes.
            '
            AddNode(dom.DocumentElement, treeView1.Nodes(0))
            If iv Then
                For i = 0 To iv - 1
                    imgLst.Images.Add(Image.FromFile(vImgPath(i)))
                Next
                treeView1.ImageList = imgLst
            End If
            treeView1.EndUpdate()
            treeView1.ExpandAll()
        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 i As Integer
        If inXmlNode.HasChildNodes Then
            Dim nodeList As XmlNodeList
            nodeList = inXmlNode.ChildNodes
            i = 0
            While i <= nodeList.Count - 1
                Dim imgIndex As Int32 = -1
                For Each att As XmlAttribute In inXmlNode.Attributes
                    If att.Name = "Icon" Then
                        imgIndex = addImage(att.Value)
                    End If
                Next
                Dim xNode As XmlNode = inXmlNode.ChildNodes(i)
                Dim tNode As New TreeNode(xNode.Name)
                If tNode.Text = "#text" Then
                    tNode.Text = xNode.Value
                End If
                If imgIndex <> -1 Then
                    tNode.ImageIndex = imgIndex
                End If
                inTreeNode.Nodes.Add(tNode) …
xrjf 230 Posting Whiz

Yes, sorry, you must remove baseStream so the instruction in line #11 will be dom.Load(_rStream)

xrjf 230 Posting Whiz

Then copy the xml file to the executable's folder and replace what now is commented by the uncommented:

         ' 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)
xrjf 230 Posting Whiz

You may perfectly change the xml file outside VS. But whenever you want to distribute or use the executable you'll have to compile first, that's all.

xrjf 230 Posting Whiz

Each time you compile in VS, the xml file is embedded into the .exe file.

xrjf 230 Posting Whiz

I am not very sure if I have understood. The xml file can be modified inside or outside VS, but because it's embedded it goes 'inside' the .exe file. This is, if you copy the executable .exe file to another folder you are also copying the xml file because it's inside the executable (=embedded).

xrjf 230 Posting Whiz

xmlembed1.PNG xmlembed1.PNG xmlembed2.PNG xmlembed4.PNG xmlembed5.PNG

In Visual Studio explorer right click over the application name and add a new element: a xml file. Paste the xml text inside the new xml file. Next, right click (in VS explorer) over the xml file name and select "properties" (I am translating from spanish) and in "Compile actions" set option "embedded file".
Finally change "MyNameSpace.XMLFile1.xml" to your name space and file name.
You may find the 'MyNameSpace' in the application properties, "application" tab, box "root namespace".
Change 'XMLFile1.xml' by the name you have given to the file.

xrjf 230 Posting Whiz

I hope this helps:

            Dim rdr As SqlDataReader = cmd.ExecuteReader
            Dim bFound As Boolean = False
            If rdr.Read() Then
                Dim category As String = rdr("categoryname")
                If txtcontent = category Then
                    bFound = True
                End If
            End If
            rdr.Close()
            If Not bFound Then
                cmd = New SqlCommand(query2, connect)
                x = cmd.ExecuteNonQuery
                lblResult.Text = "New category added"
            End If
xrjf 230 Posting Whiz

You should close first rdr.close() before the insert into command.

xrjf 230 Posting Whiz

Perhaps a better approximation may be this 'simpler' code:

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)

            ' Load Xml document.
            '
            Dim dom As New XmlDocument()
            dom.Load(_rStream.BaseStream)

            ' Initialize treeView control.
            '
            treeView1.BeginUpdate()
            treeView1.Nodes.Clear()
            treeView1.Nodes.Add(New TreeNode(dom.DocumentElement.Name))

            ' Populate the treeView with the dom nodes.
            '
            AddNode(dom.DocumentElement, treeView1.Nodes(0))
            If iv Then
                For i = 0 To iv - 1
                    imgLst.Images.Add(Image.FromFile(vImgPath(i)))
                Next
                treeView1.ImageList = imgLst
            End If
            treeView1.EndUpdate()
            treeView1.ExpandAll()
        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 i As Integer
        If inXmlNode.HasChildNodes Then
            Dim nodeList As XmlNodeList
            nodeList = inXmlNode.ChildNodes
            i = 0
            While i <= nodeList.Count - 1
                Dim imgIndex As Int32 = -1
                For Each att As XmlAttribute In inXmlNode.Attributes
                    If att.Name = "Icon" Then
                        imgIndex = addImage(att.Value)
                    End If
                Next
                Dim xNode As XmlNode = inXmlNode.ChildNodes(i)
                Dim tNode As New TreeNode(xNode.Name)
                If tNode.Text = "#text" Then
                    tNode.Text = xNode.Value
                End If
                If imgIndex <> -1 Then
                    tNode.ImageIndex = imgIndex
                End If
                inTreeNode.Nodes.Add(tNode)
                AddNode(xNode, tNode)
                i += 1
            End While
        End If
    End Sub
    Function addImage(path As String) …
xrjf 230 Posting Whiz

If the xml is the following:

<?xml version="1.0" encoding="utf-8" ?>
<Nodes>
  <Node Text="Programme" Icon="C:\Users\Public\Pictures\treeView1.bmp">
    <Node Text="Test" Icon="C:\Users\Public\Pictures\treeView2.bmp">
      <Programm Path="devenv.exe">Visual Studio</Programm>
      <Programm Path="EXCEL.EXE">Excel</Programm>
    </Node>
    <Node Text="andere" Icon="C:\Users\Public\Pictures\treeView2.bmp">
      <Programm Path="VB6.EXE">VB.NET</Programm>
    </Node>
    <Node Text="Test1" Icon="C:\Users\Public\Pictures\treeView1.bmp">
      <Programm>bla</Programm>
      <Programm>blup</Programm>
    </Node>
  </Node>
</Nodes>

and the code maybe this one:

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)

        ' Load Xml document.
        '
        Dim dom As New XmlDocument()
        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 iv Then
            For i = 0 To iv - 1
                imgLst.Images.Add(Image.FromFile(vImgPath(i)))
            Next
            treeView1.ImageList = imgLst
        End If
    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 xNode As XmlNode
    Dim tNode As TreeNode
    Dim nodeList As XmlNodeList
    Dim i As Integer
    If inXmlNode.HasChildNodes Then
        nodeList = inXmlNode.ChildNodes
        i = 0
        While i <= nodeList.Count - 1
            xNode = inXmlNode.ChildNodes(i)
            Dim imgIndex As Int32 = -1
            For Each att As XmlAttribute In inXmlNode.Attributes
                If att.Name = "Icon" Then …
xrjf 230 Posting Whiz

I am sorry, I can do the work in my own style but you may adopt what you please of the former, of course.

xrjf 230 Posting Whiz

If you need to resize the images before embedding them into the ImageList control you may take a look here.

xrjf 230 Posting Whiz

First you should copy the images to an ImageList Click Hereinstance and assign to the TreeView.ImageList property.

xrjf 230 Posting Whiz

Another good election for Font Type is 'Lucida Sans Typewriter', also monospace/fixed witdth. Like here:

multiColumnListBox3.PNG

xrjf 230 Posting Whiz

Note almost all the strings have been replaced by StringBuilder.

xrjf 230 Posting Whiz

Setting the form's font to 'Courier New' is best because the letter width is fixed, this is the same for all characters.

Imports System.Text

Public Class multiColumnListbox
    Dim vCars() As car = {New car("X1", "BMW", "140", "276", 1), _
                          New car("XS", "BMW", "225", "375", 2), _
                          New car("XSR", "BMW", "415", "189", 3), _
                          New car("X7", "BMW", "178", "119", 4), _
                          New car("718", "Porsche", "88", "112", 5), _
                          New car("911", "Porsche", "75", "137", 6), _
                          New car("Carrera", "Porsche", "127", "219", 7), _
                          New car("A4", "Audi", "234", "229", 8), _
                          New car("Q3", "Audi", "197", "251", 9), _
                          New car("Q5", "Audi", "236", "289", 10), _
                          New car("Q7", "Audi", "119", "264", 11) _
                         }
    Private Sub multiColumnListbox_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim lastBrand As New StringBuilder(20)
        For i = 0 To vCars.Length - 1
            ListBox1.Items.Add(vCars(i))
            If lastBrand.ToString <> vCars(i).getBrand.ToString Then
                lastBrand = vCars(i).getBrand
                ComboBox1.Items.Add(lastBrand.ToString)
            End If
        Next
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim unitsUK, unitsUSA, total As Int32
        For i As Int32 = 0 To vCars.Length - 1
            If ComboBox1.SelectedItem.ToString = vCars(i).getBrand.ToString Then
                unitsUK += vCars(i).getUnitsUK
                unitsUSA += vCars(i).getUnitsUSA
                total += vCars(i).getUnitsUK + vCars(i).getUnitsUSA
            End If
        Next
        tbUnitsUK.Text = unitsUK.ToString
        tbUnitsUSA.Text = unitsUSA.ToString
        tbTotal.Text = total.ToString
    End Sub

End Class
Public Class car
    Dim ID As Int32
    Dim model, brand As StringBuilder
    Dim unitsUK, unitsUSA As Int32
    Public Sub New(model As String, brand As String, unitsUK As Int32, unitsUSA As Int32, ID As Int32)
        Me.model = New StringBuilder(model)
        Me.brand = New StringBuilder(brand)
        Me.unitsUK …
xrjf 230 Posting Whiz

I take it in this way: a play will finish always with a winner A or B. In state TT both next options H or T, player B is winner, i.e., 2 wins; while in state TH player A only wins once (in case H). There are 3 winners (3 possible choices), twice for B (p=2/3), once for for A (p=1/3).

xrjf 230 Posting Whiz

Yes, it's clear that once in state TT player B will always win, while in state TH player A will win only in case of H, i.e., half the time. All this comes from the way B bets knowing beforehand A's bet.

xrjf 230 Posting Whiz

Your welcome.

xrjf 230 Posting Whiz

Be sure to set ListBox1.MultiColumn property to 'True'.

xrjf 230 Posting Whiz

As a start you may do something like the following:

Imports System.Text

Public Class multiColumnListbox
    Private Sub multiColumnListbox_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        ListBox1.Items.Add(New car("X1", "BMW", "140", "276", 1))
        ListBox1.Items.Add(New car("XS", "BMW", "225", "375", 2))
        '...
        '...
        ListBox1.Items.Add(New car("718", "Porsche", "88", "112", 2))
    End Sub
End Class
Public Class car
    Dim ID As Int32
    Dim model, brand As String
    Dim unitsUK, unitsUSA As Int32
    Public Sub New(model As String, brand As String, unitsUK As Int32, unitsUSA As Int32, ID As Int32)
        Me.model = model
        Me.brand = brand
        Me.unitsUK = unitsUK
        Me.unitsUSA = unitsUSA
        Me.ID = ID
    End Sub
    Public Overrides Function ToString() As String
        Dim sb As New StringBuilder(String.Format("{0,-15} {1,-15}", model, brand))
        sb.Append(String.Format("{0,5} {1,5} {2,10}", unitsUK, unitsUSA, unitsUK + unitsUSA))
        Return sb.ToString
    End Function
End Class

multiColumnListBox.PNG

xrjf 230 Posting Whiz

Well, I'm just trying to clarify my ideas of the problem and I think I have progressed: just that, nothing else. So a last thought:
If first toss is H-c2-c3 let's see a bit of what happens depending on c2, c3, c4 and c5.

T=c2 | H=c3 | H=c4, THH A wins   | H=c5 HHH, no winner
                                                                      | T=c5 HHT, no winner

                          | T=c4 THT no winner | H=c5 HTH, no winner
                                                                      | T=c5 HTT, no winner

           | T=c3 | H=c4, TTH B wins   | H=c5 THH, A should win but does 
                                                            not because of res() re-initialization

              .....
xrjf 230 Posting Whiz
If player A plays THH then player B choose is TTH.
If first toss is T-c2-c3 let's see what happens depending on c2, c3 and the
next toss c4.

T(H=c2) | (H=c3) A player wins | H=c4 none wins (although this will
        |                      | not happen because res() will be
        |                      | initialized)
        |                      | 
        |                      | T=c4 none wins (same as before)
        |                      | 
        | (T=c3) no winner

T(T=c2) | (H=c3) B wins        | H=c4 (A wins, combination=THH but
        |                      | this win is sidestep because B won
        |                      | and it'll never arrive here)
        |                      | T=c4 (THT, no winner)
        |                      | 
        | (T=c3) no winner     | H=c4  (TTH, B wins)
        |                      | T=c4  (TTT, no winner)

So, B wins two times while A player wins once.
xrjf 230 Posting Whiz

Splitting up btnStart_Click() as shown surprisingly the probability for both players tends to 1/8. Now, the difference is in that when a player wins res() is not initialized again.

    Private Sub btnStart_Click(sender As System.Object, e As System.EventArgs) Handles btnStart.Click
        Dim res(2) As Char

        'Seed with three initial tosses
        '
        For i As Integer = 0 To 2
            res(i) = ht(rnd.Next(0, 2))
        Next

        Dim sRepeat As String = InputBox("# of turns: ", "", 100)
        If IsNumeric(sRepeat) Then
            For i = 0 To Int32.Parse(sRepeat)
                play(res)
            Next
        End If
    End Sub
    Function ht(r As Int32) As Char
        Static ht1() As Char = {"H", "T"}
        Return ht1(r)
    End Function
    Sub play(res() As Char)

        'Repeat coin tosses until one player wins
        '

        Dim done As Boolean = False

        Do Until done

            'lbxResults.Items.Add(res(0) & "-" & res(1) & "-" & res(2))

            If CheckWin(1, res) Then
                'lbxResults.Items.Add("Player A wins")
                aWon += 1
                done = True
            ElseIf CheckWin(4, res) Then
                'lbxResults.Items.Add("Player B wins")
                bWon += 1
                done = True
            End If

            total += 1

            res(0) = res(1)
            res(1) = res(2)
            res(2) = ht(rnd.Next(0, 2))

            'Keep most recent results in view (scroll to bottom)

            'lbxResults.SelectedIndex = lbxResults.Items.Count - 1

        Loop

        Me.Text = "A - " & aWon & " games" & (aWon / total) & "    " & "B - " & bWon & " " & (bWon / total)

    End Sub
xrjf 230 Posting Whiz

Sorry, I was wrong Case CheckWin(4,res) is right. Any way, I can't see why player B after several hits approches a probability p=7/40, when one could expect p=1/8=1/2 x 1/2 x 1/2 < 7/40.

xrjf 230 Posting Whiz

The unique problem is a typo in line#42 where it says Case CheckWin(4, res) it should say Case CheckWin(3, res), because button3 is the first button for player B, isn't it?

xrjf 230 Posting Whiz

Suppose we need to populate and filter a Datagrid with the data coming from an Access table. It could be of course a table from Sql Server also.
Form dataGridSelect contains two buttons and a DataGridView. Clicking the first button will populate the DataGridView the data comming from a Sql Server database. The second button does the same comming the data from an Access database. Nothing new, but once the data is fetched a Linq filters through a Regex pattern.
The pattern "[^d|D]ata" tells to select the rows where the field Title has the sequence 'ata', not those [^d|D] preceeded by a capital or lower 'd'.
For ex. if present the word 'catalogue' will be selected. Not those with the word 'database' or 'Database'. If both words present also the row will be selected.
Note: in some internet pages (included a MS example) I've seen CopyToDataTable() called from an instance, while it's a shared function (as MS states here )

Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Data.DataTableExtensions
Imports System.Linq
Imports System.Text.RegularExpressions

Public Class dataGridSelect
    Dim sConn As String = String.Empty
    Private Sub btnFromSqlServer_Click(sender As System.Object, e As System.EventArgs) Handles btnFromSqlServer.Click
        Try
            CreateDataSetFromSqlServer()
        Catch ex As Exception
        End Try
    End Sub

    Private Sub btnFromAccess_Click(sender As System.Object, e As System.EventArgs) Handles btnFromAccess.Click
        Try
            CreateDataSetFromAccess()
        Catch ex As Exception
        End Try
    End Sub
    Sub CreateDataSetFromSqlServer()
        ' https://sudeeptaganguly.wordpress.com/2010/04/20/how-to-enable-sa-account-in-sql-server/    
        '
        sConn += "Server=DESKTOP-KD8CVG6\SQLEXPRESS;"
        sConn += "Database=biblio;"
        sConn += "User Id=sa;"
        sConn += "Password=password;"
        Dim cn As New SqlClient.SqlConnection(sConn)
        cn.Open() …
xrjf 230 Posting Whiz

Defining more than one instance has probability non-zero to repeat an earlier seed from a previous instance. Let's say there are 100 diferent possible seeds, every 200 tosses -more or less- there'll be a great probability to repeat every seed twice -more or less. For me this escenario is not a random sequence.

xrjf 230 Posting Whiz

I think the non random result is due to the fact that the random is defined inside a sub procedure and not a class level. The only way to create a random sequence is to define the random variable just once in all the analysis. Then you may play 100, 1000 times but all of the time with the same random seed.

xrjf 230 Posting Whiz

Watch out for strings outside the warning label. Replace strings by System.Text.StringBuilder.

xrjf 230 Posting Whiz

Nothing special to comment for the code except that it is setting port RA0 as ouput in line #5, port RA1 as input in line #6. Lines #4 and line #7 make no sense because status register is destination for arithmetic results, so to read and not to write into it. Lines #11 and #12 do nothing: an andoperation between register 'w' (=0xFF) and register 25 leaves register 25 as it was.