xrjf 230 Posting Whiz

About DiDi

DiDi (Differential Directory) was originally developed as part of my thesis project in the early 1990s. The name bears no relation to the more recent Chinese ride-sharing company. At the time, DiDi was a novel approach within its academic context, but a change in legislation unfortunately led to the closure of the school and the discontinuation of its degrees.

Despite that setback, I have always believed in the value of the project. Now, decades later, I feel it is the right time to share it publicly. This release is both a technical revival and a tribute to its original vision.

rproffitt commented: Was it Tr-mp University? +17
xrjf 230 Posting Whiz

I am happy that you resolved the issue. Regards.

xrjf 230 Posting Whiz

I ment:

  rpt.SetDataSource(ds.Tables(0))
  rpt.Subreports("YourSubreport.rpt").SetDataSource(ds_detspk.Tables(0))
xrjf 230 Posting Whiz

There is an example Here

xrjf 230 Posting Whiz

A better aproach would be:

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Try
            Dim file As System.IO.StreamWriter
            Dim path As String = Application.StartupPath + "\test.txt"
            file = My.Computer.FileSystem.OpenTextFileWriter(path, False)
            For i As Integer = 0 To ComboBox3.Items.Count - 1
                ComboBox2.SelectedIndex = i
                Dim d As DateTime = DateTime.Now
                Dim parsedate As DateTime = ComboBox2.Items(i).ToString
                Dim d2 As DateTime = DateTime.ParseExact(parsedate, "dd/MM/yyyy HH:mm:ss", System.Globalization.CultureInfo.CurrentCulture)
                Dim ts As New TimeSpan((d - d2).Ticks)
                Dim dysdiff As Integer = ts.TotalDays
                Dim cbNum As Integer = 365 - dysdiff
                ComboBox3.Items(i) = cbNum.ToString
                Dim lstname As String
                lstname = ListBox1.Items(i).ToString()
                If cbNum <= 10 AndAlso cbNum >= 1 Then
                    file.WriteLine("test" + lstname + " have " + cbNum.ToString + " days left before will get delete")
                End If
            Next
            file.Close()
        Catch ex As Exception

        End Try
    End Sub
xrjf 230 Posting Whiz

For example, to write a text file just do:

    Sub WriteFile()
        Dim file As System.IO.StreamWriter
        file = My.Computer.FileSystem.OpenTextFileWriter("c:\test.txt", True)
        file.WriteLine("Here is the first string.")
        file.Close()
    End Sub

So, writing to a text file in Button5_Click could be:

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Try
            Dim file As System.IO.StreamWriter
            file = My.Computer.FileSystem.OpenTextFileWriter("c:\test.txt", True)
            For i As Integer = 0 To ComboBox3.Items.Count - 1
                ComboBox2.SelectedIndex = i
                Dim d As DateTime = DateTime.Now
                Dim parsedate As DateTime = ComboBox2.Items(i).ToString
                Dim d2 As DateTime = DateTime.ParseExact(parsedate, "dd/MM/yyyy HH:mm:ss", System.Globalization.CultureInfo.CurrentCulture)
                Dim ts As New TimeSpan((d - d2).Ticks)
                Dim dysdiff As Integer = ts.TotalDays
                Dim cbNum As Integer = 365 - dysdiff
                ComboBox3.Items(i) = cbNum.ToString
                Dim lstname As String
                lstname = ListBox1.Items(i).ToString()
                If cbNum <= 10 AndAlso cbNum >= 1 Then
                    file.WriteLine("test", lstname & " have " & cbNum & " days left before will get delete", ToolTipIcon.None)
                End If
            Next
            file.Close()
        Catch ex As Exception

        End Try
        Exit Sub
    End Sub
xrjf 230 Posting Whiz

One way to share data between, for example, two forms can be writing and reading a file in disk. Here is a tutorial if needed.

rproffitt commented: Next thing you know we'll talk about SQL, etc. Good direction. +16
xrjf 230 Posting Whiz

Perhaps, you may try my guess of what you want:

    Const maxVal As Integer = 30
    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Try
            Dim value As Integer = maxVal
            If Not IsNumeric(Label10.Text) Then
                Label10.Text = maxVal.ToString
            End If
            Integer.TryParse(Label10.Text, value)
            If value >= 1 And value <= maxVal Then
                value -= 1
                Label10.Text = value.ToString
            Else
                If value <= 0 Then
                    Button5.PerformClick()
                    Timer1.Stop()
                    Label10.Text = maxVal.ToString
                End If
            End If
        Catch ex As Exception

        End Try
    End Sub






    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Try
            For i As Integer = 0 To ComboBox2.Items.Count - 1
                ComboBox2.SelectedIndex = i
                Dim d As DateTime = DateTime.Now
                Dim parsedate As DateTime = ComboBox2.Items(i).ToString
                Dim d2 As DateTime = DateTime.ParseExact(parsedate, "dd/MM/yyyy HH:mm:ss", System.Globalization.CultureInfo.CurrentCulture)
                Dim ts As New TimeSpan((d - d2).Ticks)
                Dim dysdiff As Integer = ts.TotalDays
                Dim cbNum As Integer = 365 - dysdiff
                ComboBox3.Items(i) = cbNum.ToString
                If -10 <= cbNum AndAlso cbNum <= -1 Then
                    ComboBox3.Items(i) += " old post"
                End If
            Next
        Catch ex As Exception

        End Try
    End Sub
xrjf 230 Posting Whiz

Sorry about that. I forgot the device number:

    Private Sub BtnPlay_Click(sender As Object, e As EventArgs) Handles btnPlay.Click
        Try
            If outDev Is Nothing Then
                outDev = New WaveOut()
                outDev.DeviceNumber = devNum ' Here you set the Device Number '
            End If
            If reader Is Nothing Then
                reader = New AudioFileReader(sFile)
                outDev.Init(reader)
            End If
            outDev.Play()
        Catch ex As Exception
        End Try
    End Sub
xrjf 230 Posting Whiz

Yes, devnum is the sound card you will be using, but if I were you, I would stick to the sample. After Googling this is what it is said about employing two sound cards at a time:

«Can you run 2 sound cards at the same time?
In most cases you'll be able to run several different soundcards side by side without problems, although there are no guarantees, and some rare combinations may suffer from audio clicks and pops, or cause your computer to crash occasionally or even refuse to boot up at all.»

xrjf 230 Posting Whiz

Here is a sample out from the documentation translated into VB.NET.

Imports System.ComponentModel
Imports NAudio.Wave

Public Class Form1
    Dim devNum As Int32
    Dim sFile As String
    Dim reader As AudioFileReader
    Dim outDev As WaveOut
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            Dim i As Int32
            For i = -1 To WaveOut.DeviceCount - 1
                Dim woc As WaveOutCapabilities = WaveOut.GetCapabilities(i)
                ComboBox1.Items.Add(woc.ProductName)
            Next
            ComboBox1.SelectedIndex = 0
            With OpenFileDialog1
                .Filter = "All Media Files|*.wav;*.aac;*.wma;*.wmv;*.avi;*.mpg;*.mpeg;*.m1v;*.mp2;*.mp3;*.mpa;*.mpe;*.m3u;*.mp4;*.mov;*.3g2;*.3gp2;*.3gp;*.3gpp;*.m4a;*.cda;*.aif;*.aifc;*.aiff;*.mid;*.midi;*.rmi;*.mkv;*.WAV;*.AAC;*.WMA;*.WMV;*.AVI;*.MPG;*.MPEG;*.M1V;*.MP2;*.MP3;*.MPA;*.MPE;*.M3U;*.MP4;*.MOV;*.3G2;*.3GP2;*.3GP;*.3GPP;*.M4A;*.CDA;*.AIF;*.AIFC;*.AIFF;*.MID;*.MIDI;*.RMI;*.MKV"
            End With
        Catch ex As Exception
        End Try
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        devNum = ComboBox1.SelectedIndex - 1
    End Sub

    Private Sub Btn_File(sender As Object, e As EventArgs) Handles btnFile.Click
        OpenFileDialog1.ShowDialog()
    End Sub
    Private Sub OpenFile() Handles OpenFileDialog1.FileOk
        Try
            CloseAudio() ' Close if it's not first audio to play '
            sFile = OpenFileDialog1.FileName
            Dim vNom() As String = Split(sFile, "\")
            ' Get Audio File Name: '
            lblFile.Text = "File: " + vNom(vNom.Length - 1).Split(".")(0)
        Catch ex As Exception
        End Try
    End Sub

    Private Sub BtnPlay_Click(sender As Object, e As EventArgs) Handles btnPlay.Click
        Try
            If outDev Is Nothing Then
                outDev = New WaveOut()
            End If
            If reader Is Nothing Then
                reader = New AudioFileReader(sFile)
                outDev.Init(reader)
            End If
            outDev.Play()
        Catch ex As Exception
        End Try
    End Sub
    Private Sub btnStop_Click(sender As Object, e As EventArgs) Handles btnStop.Click
        outDev.Stop()
    End Sub
    Private Sub CloseAudio()
        Try
            If outDev IsNot Nothing Then
                outDev.Stop()
                outDev = Nothing
            End If
            If reader IsNot Nothing Then
                reader.Dispose()
                reader = Nothing
            End If
        Catch ex As Exception …
rproffitt commented: Most excellent example. +1 +16
xrjf 230 Posting Whiz

Also, you may consider reading NAudio's document "Understanding Output Devices" Here

xrjf 230 Posting Whiz

Be aware that all string or numeric comparisons must be between the same type:

  1. Number compared to Number or
  2. String compared to String.
    Never Number compared to String, or String compared to Number.

Line# 9:

If ComboBox3.Text.ToString >= 1 <= 10 Then 

compares ComboBox3.Text.ToString, i.e. a String, with numbers (also >= 1 <= 10 is a syntax error and, as ComboBox3.Text is already a String, the trailing .ToString is not necessary).

Therefore consider converting line#9 to a valid comparison:

 Public Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        Try
            For i As Integer = 0 To ComboBox3.Items.Count - 1
                ComboBox2.SelectedIndex = i
                Dim d As DateTime = DateTime.Now
                Dim parsedate As DateTime = ComboBox2.Items(i).ToString
                Dim d2 As DateTime = DateTime.ParseExact(parsedate, "dd/MM/yyyy HH:mm:ss", System.Globalization.CultureInfo.CurrentCulture)
                Dim dysdiff As Integer = (d - d2).Days
                ComboBox3.Items(i) = (365 - dysdiff).ToString
                Dim cbNum As Integer
                Integer.TryParse(ComboBox3.Text, cbNum)
                ' Compare pairs of numbers: '
                ' Numeric cbNum compared to number 1 '
                ' Numeric cbNum compared to number 10 '
                If cbNum >= 1 AndAlso cbNum <= 10 Then
                    MsgBox("post old", MessageBoxButtons.OK)
                End If
            Next
        Catch ex As Exception

        End Try
    End Sub
xrjf 230 Posting Whiz

Why not just supress the traling .toString and set value as an Integer?

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Dim value As Integer = CInt(Label10.Text)
        If value >= 1 And value <= 30 Then
            value -= 1
        Else
            If value <= 0 Then
                Form11.Button5.PerformClick()
                Timer1.Stop()
            End If
        End If
    End Sub
xrjf 230 Posting Whiz

Time format is "HH:mm:ss" and not "hh:mm:ss" so I think you should change instruction:

 Dim d2 As DateTime = DateTime.ParseExact(parsedate.ToString, "dd/MM/yyyy hh:mm:ss", System.Globalization.CultureInfo.CurrentCulture)

into:

 Dim d2 As DateTime = DateTime.ParseExact(parsedate.ToString, "dd/MM/yyyy HH:mm:ss", System.Globalization.CultureInfo.CurrentCulture)
xrjf 230 Posting Whiz

I am not sure what you are trying to do. At a guess, you may replace line #6 by:

        ComboBox3.Items(i) = (365 - dysdiff).ToString + " Days"
        ComboBox3.SelectedIndex = i
xrjf 230 Posting Whiz

You may add a timer and in Timer.tickevent call to Button5_Click(sender, e).
BTW, number 365 in line#7 is numeric and dysdiffis a string, so it's not possible the substraction to work.

xrjf 230 Posting Whiz

Let's see if (I am right and) I can explain the difference between My.Settings.Reload and My.Settings.Reset.
Reload recovers the values from design time, i.e., the values you enter manually in the application's settings.
Reset recovers the values saved in the last call to My.Settings.Save.

xrjf 230 Posting Whiz

Are you asking for this?:

            For Each prop As System.Configuration.SettingsProperty In My.Settings.Properties
                prop.DefaultValue = ""
            Next
xrjf 230 Posting Whiz

Line# 41 should be tennis, isn' it? Also, n1, n2, n3 and total aren't intialized to zero.

vaishnavi_13 commented: i initialized the ni,n2,n3 and total but intersection of set c and set a and union of set a,b,c result is not being displayed +0
xrjf 230 Posting Whiz

You may do:

    Public Sub Btn_Click(sender As System.Object, ByVal e As System.EventArgs)
        Try
            Dim btn As Button
            Dim cbx As ComboBox
            Dim txt As TextBox
            Select Case sender.GetType
                Case GetType(Button)
                    btn = CType(sender, Button)
                   ' TODO ... '

                Case GetType(ComboBox)
                    cbx = CType(sender, ComboBox)
                   ' TODO ... '

                Case GetType(TextBox)
                    txt = CType(sender, TextBox)
                    ' TODO ... '

            End Select
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
xrjf 230 Posting Whiz

Try this:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Try
            Dim sSearch As String = LCase(TextBox1.Text)
            If sSearch = "" Then Exit Try
            Dim line As Int32 = 0
            TextBox2.Text = ""
            For Each row As String In File.ReadAllLines("Test.csv")
                ' split the fields from the row '
                line += 1
                Dim vFields() As String = Split(row, ";")
                Dim iLbl As Int32 = 0
                For iLbl = 0 To vFields.Length - 1
                    If InStr(LCase(vFields(iLbl)), sSearch) Then
                        Exit For
                    End If
                Next
                If iLbl < vFields.Length Then
                    ' Found: " '
                    TextBox2.Text += "line#=" + line.ToString + " "
                    ' TextBox2 is Multiline '
                    '                                A  B  D  AA  AB '
                    Dim vColumnsToShow() As Int32 = {0, 1, 3, 26, 27}
                    Dim vLabel() As String = {"A", "B", "D", "AA", "AB"}
                    For iLbl = 0 To vColumnsToShow.Length - 1
                        Dim Col_in_Excel As Int32 = vColumnsToShow(iLbl)
                        If Col_in_Excel < vFields.Length Then
                            TextBox2.Text += "cell " + vLabel(iLbl) + "= " + vFields(Col_in_Excel) + " "
                        End If
                    Next
                    TextBox2.Text += vbCrLf
                End If

            Next
        Catch ex As Exception
            MessageBox.Show("Error : " & ex.Message)
        End Try
    End Sub
fnaf commented: Thanks a lot for your help. +0
jwatson commented: Yes i try, its working. . Thanks guys. +3
xrjf 230 Posting Whiz

Probably the code is missing the following Imports:

Imports Microsoft.VisualBasic.DateAndTime
shane1961 commented: Hi xrjf. That was the problem. Many thanks. +0
xrjf 230 Posting Whiz

"Windows PowerShell is a programming language from Microsoft that is primarily designed for system administration. Since PowerShell is built on top of the .NET framework, .NET’s excellent regular expression support is also available to PowerShell programmers."

Now, try using .NET's sequence (?!subexpr) and (?<!subexpr).

(?!subexpr) for ex. \w+\b(?![,:;]) will find a word that is not followed by coma, colon or semicolon

(?<!subexpr) for example (?<!,)\b\w+will find a word that is not preceeded by a coma

xrjf 230 Posting Whiz

@rproffitt: If the file is large and assuming we can buffer a first bunch of lines so that streamreader and streamwriter will never overlap:

        Try
            Dim path As String = "Append.txt"
            Using fs As New FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.None)
                Dim sr As New StreamReader(fs)
                Dim sw As New StreamWriter(fs)
                Dim lineNum As Int32 = 1
                Dim fileLen As Long = fs.Length
                Dim linesToBuffer As Int32 = 3
                Dim currBufferLine As Int32 = 0
                Dim vBuffer(linesToBuffer - 1) As String
                Dim EndofBuffer As Int32 = -1
                Dim rdPos As Long = 0
                Dim wrPos As Long = 0
                For i = 0 To vBuffer.Length - 1
                    vBuffer(i) = sr.ReadLine
                Next
                rdPos = fs.Position
                Do
                    fs.Seek(wrPos, SeekOrigin.Begin)
                    sw.WriteLine(String.Format("Line #{0:0000000} ", lineNum) + vBuffer(currBufferLine))
                    wrPos = fs.Position 
                    ' if wrPos >= rdPos signifies buffer too small'
                    If rdPos < fileLen Then
                        fs.Seek(rdPos, SeekOrigin.Begin)
                        vBuffer(currBufferLine) = sr.ReadLine
                        rdPos += vBuffer(currBufferLine).Length + 2
                        lineNum += 1
                    Else
                        If EndofBuffer = -1 Then
                            sr.Close()
                            EndofBuffer = linesToBuffer
                        End If
                        EndofBuffer -= 1
                        If EndofBuffer < 0 Then Exit Do
                    End If
                    currBufferLine = (currBufferLine + 1) Mod linesToBuffer
                Loop
                sw.Close()
            End Using
        Catch ex As Exception

        End Try
rproffitt commented: Now throw this a zero byte file. Excellent examples where something simple grows and grows to cover every condition. +0
xrjf 230 Posting Whiz

Consider reading all the lines at the beginning and, then, prepending the line number, like in:

        Try
            Dim vLines() As String = IO.File.ReadAllLines("Append.txt")
            Using sw As New StreamWriter("Append.txt")
                For i As Int32 = 0 To vLines.Length - 1
                    sw.Write(String.Format("Line #{0:0000} ", i) + vLines(i) + vbCrLf)
                Next
            End Using
        Catch ex As Exception

        End Try
rproffitt commented: I'd like to try that on a 4+ terabyte file just to see what vb.net would do. There are reasons to code this with input and output files. +15
xrjf 230 Posting Whiz

I am very happy that you could resolve the issue. Thanks.

xrjf 230 Posting Whiz

There should be no problem by name. Could you upload an image of the Console listing the name (option 2.) ? Use the snipping tool for that purpose.

rproffitt commented: I agree but I've seen folk go down this rabbit hole and the name wasn't in the data. +15
xrjf 230 Posting Whiz

¿Are you entering the complete name? The select command is NOT case sensitive, but if you want to use the percent wildcard '%', the function would be then:

    Function Find_Device_By_Name(name As String) As Boolean
        Try
            ' 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 LIKE '%" + name + "%'")
            For Each info In search.Get()
                Dim devname As String = CType(info("Name"), String)
                Dim ID As String = CType(info("DeviceID"), String)
                Console.WriteLine("Device ID is: " + ID.ToString)
                Console.WriteLine("       name=" + devname)
            Next
            Return True ' Device(s) Found '
        Catch ex As Exception

        End Try
        'We did not find the device we were looking for '
        Return False
    End Function
xrjf 230 Posting Whiz

Vendor ID (VID) and Product (ID) is not the same as serial number. Two equal devices from the same vendor will have the same VID & PID because are the same product from the same vendor, but different serial numbers.
I have made same changes to the code so you can find also a device by name:

Imports System.Management

Module Module1

    Dim vIDs() As String, iv As Int32 = 0
    Dim deviceID = "VID_0461&PID_4E22" ' Change to your's 
    Dim bDsp As Boolean = True
    Dim bAttached As Boolean = False
    Sub Main()
        Do
            Console.WriteLine("1. List All Devices")
            Console.WriteLine("2. List USB Devices")
            Console.WriteLine("3. Find out the device ID")
            Console.WriteLine("4. Find if Device " + deviceID + " is connected.")
            Console.WriteLine("5. Find device(s) by name.")
            Console.WriteLine("6. Exit")
            Select Case Console.ReadLine
                Case "1" : Detect_missing_VID_PID()
                Case "2" : Detect_missing_VID_PID("USB" + Chr(92))
                Case "3"
                    Console.Clear()
                    Console.WriteLine("Press 'Enter' key when the device is attached.")
                    Console.ReadLine()
                    bDsp = False
                    iv = 0
                    Detect_missing_VID_PID("USB" + Chr(92))
                    Console.WriteLine("Detach the device and press 'Enter' key.")
                    Console.ReadLine()
                    Detect_missing_VID_PID("USB" + Chr(92))
                    Console.WriteLine("Device ID is: " + deviceID)
                    Console.WriteLine("Attach again the device and press 'Enter' key.")
                    Console.ReadLine()
                    bAttached = Find_Device_By_ID(deviceID)
                    Console.WriteLine("Now on if you attach/remove it'll be detected. Press any key to exit.")
                    Do
                        Dim nowAttached As Boolean = Find_Device_By_ID(deviceID)
                        If nowAttached <> bAttached Then
                            bAttached = nowAttached
                            If bAttached Then
                                Console.WriteLine("Attached")
                            Else
                                Console.WriteLine("Removed")
                            End If
                        End If
                        System.Threading.Thread.Sleep(500)
                    Loop While Not Console.KeyAvailable
                    bDsp = True
                Case "4"
                    If Find_Device_By_ID(deviceID) Then
                        Console.WriteLine("Connected!")
                    End If
                Case "5"
                    Console.Write("Device's name is?: ")
                    Dim …
xrjf 230 Posting Whiz

I imagine you'll want to know if the mouse is attached or removed. Here is another version where this task is done (in option 3).

Imports System.Management

Module Module1

    Dim vIDs() As String, iv As Int32 = 0
    Dim VID_PID_device = "VID_0461&PID_4E22" ' Change to your's 
    Dim bDsp As Boolean = True
    Dim bAttached As Boolean = False
    Sub Main()
        Do
            Console.WriteLine("1. List All Devices")
            Console.WriteLine("2. List USB Devices")
            Console.WriteLine("3. Find out the VID and the PID of the mouse.")
            Console.WriteLine("4. Find if Device " + VID_PID_device + " is connected.")
            Console.WriteLine("5. Exit")
            Select Case Console.ReadLine
                Case "1" : ListDevices_VID_PID()
                Case "2" : ListDevices_VID_PID("USB" + Chr(92))
                Case "3"
                    Console.Clear()
                    Console.WriteLine("Press 'Enter' key when the mouse is attached.")
                    Console.ReadLine()
                    bDsp = False
                    iv = 0
                    ListDevices_VID_PID("USB" + Chr(92))
                    Console.WriteLine("Detach the mouse and press 'Enter' key.")
                    Console.ReadLine()
                    ListDevices_VID_PID("USB" + Chr(92))
                    Console.WriteLine("Mouse VID and PID is: " + VID_PID_device)
                    Console.WriteLine("Attach again the mouse and press 'Enter' key.")
                    Console.ReadLine()
                    bAttached = Find_Device_By_VID_PID(VID_PID_device)
                    Console.WriteLine("Now on if you attach/remove it'll be detected. Press any key to exit.")
                    Do
                        Dim nowAttached As Boolean = Find_Device_By_VID_PID(VID_PID_device)
                        If nowAttached <> bAttached Then
                            bAttached = nowAttached
                            If bAttached Then
                                Console.WriteLine("Attached")
                            Else
                                Console.WriteLine("Removed")
                            End If
                        End If
                        System.Threading.Thread.Sleep(500)
                    Loop While Not Console.KeyAvailable
                    bDsp = True
                Case "4"
                    If Find_Device_By_VID_PID(VID_PID_device) Then
                        Console.WriteLine("Connected!")
                    End If
                Case "5" : Exit Do
            End Select
        Loop
    End Sub
    Sub ListDevices_VID_PID(Optional sFilter As String = "")
        Try
            Dim bCompare As Boolean = IIf(iv = 0, False, True)
            Dim info As Management.ManagementObject
            Dim search As System.Management.ManagementObjectSearcher
            Dim Name …
xrjf 230 Posting Whiz

If you want to list only USB devices, you may do:

    Function DetectDevice(DeviceName 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
            Dim Name As String
            search = New System.Management.ManagementObjectSearcher("SELECT * From Win32_PnPEntity")
            For Each info In search.Get()
                ' Go through each device detected.'
                Name = CType(info("Caption"), String) ' Get the name of the device.'
                Dim ID As String = CType(info("DeviceID"), String)
                If InStr(info.Path.ToString, "USB\\") Then
                    Console.WriteLine(Name + " " + ID)
                    If InStr(Name, DeviceName, CompareMethod.Text) > 0 Then
                        Return True
                    End If
                End If
            Next
        Catch ex As Exception

        End Try
        'We did not find the device we were looking for'
        Return False
    End Function
xrjf 230 Posting Whiz

Click Here
You should add a reference to System.Management dll

    Function DetectDevice(DeviceName 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
            Dim Name As String
            search = New System.Management.ManagementObjectSearcher("SELECT * From Win32_PnPEntity")
            For Each info In search.Get()
                ' Go through each device detected.'
                Name = CType(info("Caption"), String) ' Get the name of the device.'
                If InStr(Name, DeviceName, CompareMethod.Text) > 0 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
xrjf 230 Posting Whiz

You must add a condition because the columns are being added twice: in design-time and in run time. (DesignMode property from Windows Forms components not 100% reliable, so use this other):

    Public Sub New()
        Width = 500
        Height = 200
        If System.ComponentModel.LicenseManager.UsageMode = System.ComponentModel.LicenseUsageMode.Designtime Then
            Dim Col1 = New DataGridViewTextBoxColumn With {.HeaderText = "AAA", .Name = "A", .Width = 100}
            Dim Col2 = New DataGridViewTextBoxColumn With {.HeaderText = "BBB", .Name = "B", .Width = 200}
            Dim Col3 = New DataGridViewTextBoxColumn With {.HeaderText = "CCC", .Name = "C", .Width = 100}
            Dim Col4 = New DataGridViewTextBoxColumn With {.HeaderText = "DDD", .Name = "D", .Width = 100}
            Dim Col5 = New DataGridViewTextBoxColumn With {.HeaderText = "EEE", .Name = "E", .Width = 100}
            Me.Columns.AddRange({Col1, Col2, Col3, Col4, Col5})
        End If

    End Sub
xrjf 230 Posting Whiz

Just split the fields inside each row:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        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
                End If
            Next
        Catch ex As Exception

        End Try
    End Sub

TableCSV.PNG

xrjf 230 Posting Whiz

I've made several improvents to the code, so here is another version.

xrjf 230 Posting Whiz

You may want to add a user control, with 4 or 6 textboxes depending on IPv4 or IPv6. For example:

Public Class IP_Textbox
    Const nBytes As Int32 = 4 ' IPv4 (change to =6 if IPv6)
    Dim vTextbox(nBytes - 1) As TextBox
    Dim vLabel(nBytes - 2) As Label
    Private Sub IP_Textbox_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            Me.BackColor = Color.White
            Dim left As Int32 = 4
            For i As Int32 = 0 To nBytes - 1
                vTextbox(i) = New TextBox
                With vTextbox(i)
                    .Width = 25
                    .TextAlign = HorizontalAlignment.Center
                    .BorderStyle = BorderStyle.None
                    .BackColor = Color.White
                    .MaxLength = 3
                    .Location =
                        New Point(left, 3 + (Me.Height - vTextbox(i).Height) / 2)
                    AddHandler .Validating, AddressOf vTextChanged
                    left += 25
                End With
                Me.Controls.Add(vTextbox(i))
                If i < nBytes - 1 Then
                    vLabel(i) = New Label
                    With vLabel(i)
                        .AutoSize = True
                        .Text = ","
                        .BorderStyle = BorderStyle.None
                        .BackColor = Color.White
                        .Location = New Point(left, 7)
                        left += 10
                    End With
                    Me.Controls.Add(vLabel(i))
                End If
            Next
            Me.Width = left + 6
            Me.Height += 2
        Catch ex As Exception

        End Try
    End Sub
    Public ReadOnly Property IP As String()
        Get
            Dim vText(vTextbox.Length - 1) As String
            Try
                For i As Int32 = 0 To vText.Length - 1
                    vText(i) = vTextbox(i).Text
                Next
            Catch ex As Exception

            End Try
            Return vText
        End Get
    End Property
    Private Sub vTextChanged(sender As Object, e As System.ComponentModel.CancelEventArgs)
        Try
            Dim tb As TextBox = CType(sender, TextBox)
            tb.Text = Trim(tb.Text)
            If Len(tb.Text) = 0 Then tb.Text = "0"
            Dim ip As Int32
            If Int32.TryParse(tb.Text, ip) AndAlso …
xrjf 230 Posting Whiz

Coding like the following you get the attached image:

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ListView1.View = View.Details
        For i As Int32 = 0 To 3
            Dim ch As ColumnHeader = ListView1.Columns.Add("Column " + (i + 1).ToString)
            ch.Width = 100
        Next

        With ListView1
            Dim vDates() As String = {"2019/01/01", "2019/01/01", "2019/01/01", "2019/01/02", "2019/01/02"}
            Dim lastID As Int32 = -1
            For id = 1 To 5
                Dim lastD As String = ""
                For Each d In vDates
                    Dim vFields() As String = {
                    " field A",
                    " field B"
                        }
                    Dim li As ListViewItem
                    If id <> lastID Then
                        li = .Items.Add(id.ToString)
                        lastID = id
                    Else
                        li = .Items.Add("")
                    End If
                    If d <> lastD Then
                        li.SubItems.Add(d)
                        lastD = d
                    Else
                        li.SubItems.Add("")
                    End If
                    For iRow As Int32 = 0 To vFields.Length - 1
                        Dim str As String = "ID:" + id.ToString + " date:" + d
                        li.SubItems.Add(str + vFields(iRow))
                    Next
                Next
            Next
        End With
    End Sub
End Class

ListView.PNG

xrjf 230 Posting Whiz

Why not launch a modal pop-up from client side or server side using Ajax Toolkit? See Here

xrjf 230 Posting Whiz

Looks like there is a comparison between a numeric value (PROPID) and a string ('%" & Textbox2.Text & "%' ). The solution is to convert both to same type by means of CAST or CONVERT:
Syntax for CAST:
CAST ( expression AS data_type [ (length ) ])
or
Syntax for CONVERT:
CONVERT ( data_type [ ( length ) ] , expression [ , style ] )

xrjf 230 Posting Whiz

Assuming you correct the XML file and you know the name of the fields, you could do something like the following:

Imports System.IO

Public Class XMLreader
    Private Sub Populate_Click(sender As Object, e As EventArgs) Handles Populate.Click
        extractFields()
    End Sub
    Sub extractFields()
        Try
            Dim svFields() As String = {"code", "codeSystemName"}
            Dim vFieldType() As Type = {GetType(Int32), GetType(String)}
            Dim dt As New DataTable
            For i As Int32 = 0 To svFields.Length - 1
                dt.Columns.Add(New DataColumn(svFields(i), vFieldType(i)))
            Next
            Dim _assembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly
            Dim sr As Stream = _assembly.GetManifestResourceStream("XMLreader.XMLreader.xml")
            Using xtr As System.Xml.XmlReader = System.Xml.XmlReader.Create(sr)
                Do While xtr.Read
                    If xtr.IsStartElement Then
                        If xtr.HasAttributes Then
                            Dim nFields As Int32 = 0
                            Dim vRow(svFields.Length - 1)
                            While xtr.MoveToNextAttribute
                                Dim pos As Int32 = Array.IndexOf(svFields, xtr.Name)
                                If pos > -1 Then
                                    vRow(pos) = xtr.Value
                                    nFields += 1
                                    If nFields = svFields.Length Then
                                        Dim dr As DataRow = dt.NewRow
                                        dr.ItemArray = vRow
                                        dt.Rows.Add(dr)
                                    End If
                                End If
                            End While
                        End If
                    End If
                Loop
            End Using
            With DataGridView1
                .DataSource = dt
                .AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells)
            End With
        Catch ex As Exception

        End Try
    End Sub
End Class
xrjf 230 Posting Whiz

What do you mean by a "slow" machine? Anyway verify the path of the images. If the images are not found there will not be no message unless you add a line after line number 95, for example `If i = -1 AndAlso not IO.File.Exists(path) Then msgbox("file not found: "+path)

xrjf 230 Posting Whiz

You just have to proceed similarly as for the "+" and "-" operators. Now, the code is:

import java.util.ArrayList;
import java.util.Scanner;
import static java.lang.Integer.*;
import static java.lang.System.*;

public class ExpressionSolver
{
    int answer;
    String expString;
    ArrayList<String> exp;
    public ExpressionSolver(String s)
    {
        setExpression(s);
    }

    public void setExpression(String s)
    {
        expString = s;
        exp = new ArrayList<String>();

        for(String temp: s.split(" "))
        {
         exp.add(temp);
        }
    }

    public void solveExpression()
    { 
       int index1, index2, num1, num2;        

      while(exp.contains("*") || exp.contains("/"))
      {
           index1 = exp.indexOf("*");
           index2 = 0;
           if(index1 <= 0)
           {
             index1 = exp.indexOf("/");
             index2 = 1;
           }
         num1 = Integer.parseInt(exp.get(index1-1));
         num2 = Integer.parseInt(exp.get(index1+1));
        if(index2 == 0)
         {
            answer = num1 * num2;
         }
         else
         {
            answer = num1 / num2;
         }
         exp.remove(index1 - 1);
         exp.remove(index1 - 1);
         exp.set(index1 - 1, Integer.toString(answer));
      }
      while(exp.contains("+") || exp.contains("-"))
      {
           index1 = exp.indexOf("+");
        index2 = 0;
           if(index1 <= 0)
           {
             index1 = exp.indexOf("-");
          index2 = 1;
           }
         num1 = Integer.parseInt(exp.get(index1-1));
         num2 = Integer.parseInt(exp.get(index1+1));
        if(index2 == 0)
         {
            answer = num1 + num2;
         }
         else
         {
            answer = num1 - num2;
         }

         exp.remove(index1 - 1);
         exp.remove(index1 - 1);
         exp.set(index1 - 1, Integer.toString(answer));

      }
}

  public String toString()   
  {
   return expString + " = " + answer;
  }
}
xrjf 230 Posting Whiz

I've only take a look to addition and substraction and made some modifications. I hope you understand it and leave up to you the other operators.

import java.util.ArrayList;
import java.util.Scanner;
import static java.lang.Integer.*;
import static java.lang.System.*;

public class ExpressionSolver
{
    int answer;
    String expString;
    ArrayList<String> exp;
    public ExpressionSolver(String s)
    {
        setExpression(s);
    }

    public void setExpression(String s)
    {
        expString = s;
        exp = new ArrayList<String>();

        for(String temp: s.split(" "))
        {
         exp.add(temp);
        }
    }

    public void solveExpression()
    { 
       int index1, index2, num1, num2;        

       while(exp.contains("*") || exp.contains("/"))
       {
         index1 = exp.indexOf("*");
         index2 = exp.indexOf("/");

         if(index1 <= 0)
         {
          index1 = 100;
         }
         if (index2 <= 0)
         {
          index2 = 100;
         }

          if(index1 < index2)
         {   
          num1 = Integer.parseInt(exp.get(index1-1));
          num2 = Integer.parseInt(exp.get(index1+1));
          answer = num1 * num2;

          exp.remove(index1 - 1);
          exp.remove(index1 - 1);
          exp.set(index1 - 1, Integer.toString(answer));
         }
         else if(index2 < index1)
         {
           num1 = Integer.parseInt(exp.get(index2 - 1));
           num2 = Integer.parseInt(exp.get(index2 + 1));
           answer = num1 / num2;

           exp.remove(index2 -1);
           exp.remove(index2 - 1);
           exp.set(index1 -1 ,Integer.toString(answer));
          }
      }
      while(exp.contains("+") || exp.contains("-"))
      {
           index1 = exp.indexOf("+");
        index2 = 0;
           if(index1 <= 0)
           {
             index1 = exp.indexOf("-");
          index2 = 1;
           }
         num1 = Integer.parseInt(exp.get(index1-1));
         num2 = Integer.parseInt(exp.get(index1+1));
        if(index2 == 0)
         {
            answer = num1 + num2;
         }
         else
         {
            answer = num1 - num2;
         }

         exp.remove(index1 - 1);
         exp.remove(index1 - 1);
         exp.set(index1 - 1, Integer.toString(answer));

      }
}

  public String toString()   
  {
   return expString + " = " + answer;
  }
}
xrjf 230 Posting Whiz

Of course if you're not coding in VBasic like me, most probably you'll have to escape the slash /. So the pattern becomes collections\/(?!\/|shirts|tea|[\w]+\/products)

xrjf 230 Posting Whiz

Assuming products (if present) is after the second / character like in
collections/shirts/products/tee-shirt,
collections(/(?!/|shirts|tea|[\w]+/products)) seems to work.

EvolutionFallen commented: Perfect! Just what I was looking for. +9
xrjf 230 Posting Whiz

Type in Google:

w3schools customers.php
The first link appeared to have:

{ "records":[ {"Name":"Alfreds Futterkiste","City":"Berlin","Country":"Germany"}, {"Name":"Ana Trujillo Emparedados y helados","City":"México D.F.","Country":"Mexico"}, {"Name":"Antonio Moreno Taquería","City":"México D.F.","Country":"Mexico"}, {"Name":"Around the Horn","City":"London","Country":"UK"}, {"Name":"B's Beverages","City":"London","Country":"UK"}, {"Name":"Berglunds snabbköp","City":"Luleå","Country":"Sweden"}, {"Name":"Blauer See Delikatessen","City":"Mannheim","Country":"Germany"}, {"Name":"Blondel père et fils","City":"Strasbourg","Country":"France"}, {"Name":"Bólido Comidas preparadas","City":"Madrid","Country":"Spain"}, {"Name":"Bon app'","City":"Marseille","Country":"France"}, {"Name":"Bottom-Dollar Marketse","City":"Tsawassen","Country":"Canada"}, {"Name":"Cactus Comidas para llevar","City":"Buenos Aires","Country":"Argentina"}, {"Name":"Centro comercial Moctezuma","City":"México D.F.","Country":"Mexico"}, {"Name":"Chop-suey Chinese","City":"Bern","Country":"Switzerland"}, {"Name":"Comércio Mineiro","City":"São Paulo","Country":"Brazil"} ] } 
xrjf 230 Posting Whiz

Your language uses "," as decimal separator and "." as thousand separator and that is why instead of retrieving 1/4 (=0.25), CDbl is getting 25. Use double.parse instead, setting the NumberFormat you need:

        Dim ni As Globalization.NumberFormatInfo = Globalization.CultureInfo.CurrentCulture.NumberFormat.Clone
        ni.NumberDecimalSeparator = "."
        tara = Double.Parse(lblindicador2.Text, ni)
        PB = Double.Parse(lblindicador.Text, ni)
xrjf 230 Posting Whiz

What an old thread, isn't it?

xrjf 230 Posting Whiz

In this other way the code seems to work:

x = [16.7, 16.5, 16.1, 15, 13.5,14.2, 14.9, 13.7] # an example
D = [0, 1, 4, 7, 16, 31, 64, 127] # example
n_H = 0.9
Sec_nucli = 0

## I defined the function like this:
def Fragmentation(D,x):
    s_nucli = n_H * D * x
    return s_nucli

for xi in x: 
    for Dj in D:
      print(xi, Dj)
      Sec_nucli += Fragmentation(xi,Dj)
      print(Sec_nucli)