xrjf 230 Posting Whiz

The default device is DeviceNumber = -1.

xrjf 230 Posting Whiz

Remember to dispose the audio objects, otherwise there could be leaks of memory.
Also, could you mark as solved if you think so? Many thanks.

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

You are welcome. I can change the audio file, click the Play button again and it works for me.
Also, I found that BtnStop_Click() should test for Nothing:

    Private Sub BtnStop_Click(sender As Object, e As EventArgs) Handles btnStop.Click
        If outDev IsNot Nothing Then
            outDev.Stop()
        End If
    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

Basically, it would go like this:

    Dim devNum As Int32
    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
        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
xrjf 230 Posting Whiz

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

xrjf 230 Posting Whiz

Perhaps this link may help you.
Click 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

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

Are you asking for this?:

            For Each prop As System.Configuration.SettingsProperty In My.Settings.Properties
                prop.DefaultValue = ""
            Next
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

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

BTW you may cast from one type to another by means of DirectCast() or CType().

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

As you may know, each device has a unique Vendor Identifier (VID) and a Product Identifier (PID). If, for example, I want to know if the mouse is connected, what shall I do? I can list all the devices with their VID and PID. Then unplug the mouse, list again all the devices and compare with the former list and see which device is missing: the missing device will tell me the mouse's VID and PID.
Once I know the VID and PID, it will be possible to detect if the mouse is connected or not.

Imports System.Management

Module Module1

    Sub Main()
        Dim VID_PID_device = "VID_0461&PID_4E22" ' Change to your's 
        Console.WriteLine("1. List All Devices")
        Console.WriteLine("2. List USB Devices")
        Console.WriteLine("3. Find if Device " + VID_PID_device + " is connected.")
        Select Case Console.ReadLine
            Case "1" : ListDevices_VID_PID()
            Case "2" : ListDevices_VID_PID("USB"+Chr(92))
            Case "3" 
                If Find_Device_By_VID_PID(VID_PID_device) Then
                    Console.WriteLine("Connected!")
                End If
        End Select
        Console.Write("Press Enter Key to exit.")
        Console.ReadLine()
    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 …
xrjf 230 Posting Whiz

You should know by now or take a programming course: call the function passing the name of the device as argument.

xrjf 230 Posting Whiz

In Visual Studio go to the Solution Explorer and right click over "References". It will look something like this:

ListDevices0.PNG

A dialog window will be opened. Select "Framework" on the left pane, and click the check box for System.Management.

ListDevices.PNG

Accept and the error should disappear.

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

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

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

Try collections\/col(\d{2,}|[^23])(?!\/products), because (\d{2,}|[^23]) will allow 2 or more numbers (as in col22, col21) or 1 number other than 2 or 3 (col1, col4, col5 but not col2 nor col3).

xrjf 230 Posting Whiz

I'm not sure if each time can be a withdraw of 1 unit, but in that case, calling anotherTransct() from menu(), then menu() from anotherTransact() and repeating this same process enough times, there could be a stack overflow.

xrjf 230 Posting Whiz
            Dim vplaats() As String = Split(Replace(TextBox1.Text, "'", "''"), " ")
            vplaats(0) = StrConv(vplaats(0), VbStrConv.ProperCase)
            vplaats(vplaats.Length - 1) = StrConv(vplaats(vplaats.Length - 1), VbStrConv.ProperCase)
            Dim platts As String = Join(vplaats, " ")
xrjf 230 Posting Whiz

The message is telling that field pr.invno on line 1 should also figure in the Group By clause, or in a function like sum(pr.invno) or count(pr.invno) .

xrjf 230 Posting Whiz

Is it possible for you to change lines 58 and 59 from:

ra1 =  rap[j-1];
ra1 = ra1/100.0;

to:

ra1 =  rap[j-1];
printf("DEBUG: ra1 is %lf\n", ra1);
ra1 = ra1/100.0;
printf("DEBUG: ra1 is %lf\n", ra1);

and debug again?

xrjf 230 Posting Whiz

Another possibility is to assure the operation in line 59: ra1 = ra1/100.0; maybe double precision in 32 and 64 bit machines do not match the same.

xrjf 230 Posting Whiz

Where is rap[ ] assigned a value? You should look there because the value of ra1comes from rap[ ], so if the values in ra1differ it's that rap[ ]values are already coming different from some other code, not the one you show.

xrjf 230 Posting Whiz

Setting a session variable in javascript is not possible. Javascript executes on client side while php (php session variable) executes on server side, i.e. generaly on different machines.

xrjf 230 Posting Whiz

Then call by means of XMLHttpRequest another php that grabs the phone number and any other data to record what is necessary.

<script>

      function checkmax(element) {

          if(element.value.length == 9){

             var xhr = new XMLHttpRequest();
             xhr.open('POST', '/server/getPhone.php', true);
             //Send the header 
             xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

             xhr.onreadystatechange = function() {//Call a function when the state changes.
             if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
             // Request finished. Do processing here.
             }
             xhr.send("phone="+urlencode(element.value)+"&foo=bar");

          }
      }

</script>
xrjf 230 Posting Whiz

One way could be to assign the value to a hidden input label. For example:

<?php
 $_SESSION['num']='4567890123';
?>

<!DOCTYPE html>

<html>

<body>

<script>

      function checkmax(element) {

          if(element.value.length == 9){

              var vvc = element.value;

              element.value =document.forms['myForm'].elements['h1'].value;

//alert(vvc);
          }
      }

</script>

<form name="myForm" onsubmit="myPhp.php">

<input  type="text" id="dCell" 

    value="Cellphone Number"
    maxlength="10"
    onkeypress="checkmax(this)"
    name="CellphoneNumber2"
    id="cCell"
    onblur="checkmax(this)"
    onfocus="if (this.value = '') {this.value = 'Cellphone Number';}" required>

<input name="h1" type="hidden" value="<?php echo $_SESSION['num'] ?>">
</form>
</body>
</html>
xrjf 230 Posting Whiz

I agree in that the only way I can see is to submit the form back to the server. Something like:

<!DOCTYPE html>
<html>
<body>
<script>
  function chkLen() {
  if(document.getElementById("dCell").value.length =10)
    document.getElementById("myForm").submit(); 
}
</script>
<form name="myForm" onsubmit="myPhp.php">
<input id="dCell" type="text" onChange="chkLen();" value="<?php echo $_SESSION['mySessionIDHere'];?>" />
</form>
</body>
</html>
xrjf 230 Posting Whiz

I'm not gonna give a neg. rep. point, not even discuss what does lambda syntax look like in any specific language. Just that if this is a vb.net thread it's not a c# or not even asp.net. Isn't it?

ddanbe commented: Completely right, and well said! +15
xrjf 230 Posting Whiz

Six thousand rows doesn't seem so much, unless having constant calls to the function.

Imports System.Linq

Public Class Properties
    Private Sub Properties_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            Dim A1() As A = {New A(1, "name1", "address1", "email1@email.com", "1234", "NY"),
                            New A(2, "name2", "address2", "email2@email.com", "5678", "LA"),
                            New A(3, "name3", "address3", "email3@email.com", "9012", "XX")}
            Dim q = (From p In A1 Select ID = p.ID,
                    value = p.Name + "|" + p.Address + "|" + p.email + "|" + p.phone + "|" + p.city).ToDictionary(
                    Function(x) x.ID, Function(x) x.value)
            Dim g = q
        Catch ex As Exception

        End Try
    End Sub
End Class
Class A
    Public ID As Int32
    Public Name As String
    Public Address As String
    Public email As String
    Public phone As String
    Public city As String
    Public Sub New(Id As Int32,
                   Name As String,
                   Address As String,
                   email As String,
                   phone As String,
                   city As String)
        Me.ID = Id
        Me.Name = Name
        Me.Address = Address
        Me.email = email
        Me.phone = phone
        Me.city = city
    End Sub
End Class
xrjf 230 Posting Whiz

@ddanbe why don't express lambda expressions in VB.NET instead of c#?

xrjf 230 Posting Whiz

Do you mean somewhat like this?:

Imports System.Linq

Public Class Properties
    Private Sub Properties_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            Dim A1() As A = {New A(1, "name1", "address1"),
                            New A(2, "name2", "address2"),
                            New A(3, "name3", "address3")}
            Dim q = (From p In A1 Select p.ID, p.Address).ToDictionary(Function(x) x.ID, Function(x) x.Address)
        Catch ex As Exception

        End Try
    End Sub
End Class
Class A
    Public ID As Int32
    Public Name As String
    Public Address As String
    Public Sub New(Id As Int32, Name As String, Address As String)
        Me.ID = Id
        Me.Name = Name
        Me.Address = Address
    End Sub
End Class
xrjf 230 Posting Whiz

@Shark purinvid seems to be the table's key, so if it does not exist resultwill be 0 out from executeScalarand the row will be added. In the other case the row will be updated.

xrjf 230 Posting Whiz

The code had severall errors. Maybe this other way you can make it work:

        Dim sql = "select Count(*) from pur_invdet where purinvid=@purinvid"
        Dim cmd = New OleDb.OleDbCommand(sql, cn)
        cmd.Parameters.AddWithValue("@purinvid", TextBox1.Text)
        Dim result As Integer = Convert.ToInt32(cmd.ExecuteScalar())
        cmd.Parameters.Clear()

        Try
            If result > 0 Then

                For Each x As ListViewItem In ListView1.Items
                    Dim sln As Integer = x.SubItems(0).Text
                    Dim qty As Integer = Convert.ToDecimal(x.SubItems(4).Text)
                    Dim itmid As Integer = x.SubItems(12).Text
                Next
                sql = "Update pur_invdet set [slno] = @slno, [ItemIDpur]=@ItemIDpur  where purinvid=@purinvid"
                cmd = New OleDb.OleDbCommand(sql, cn)
                cmd.Parameters.AddWithValue("@slno", Val(txtitemsl.Text))
                cmd.Parameters.AddWithValue("@ItemIDpur", txtitemid.Text)
                cmd.Parameters.AddWithValue("@purinvid", txtpurinvid.text)
                Dim n As Int32 = cmd.ExecuteNonQuery()
                If n Then
                    MsgBox("Updated ")
                End If
            Else

                sql = "Insert into pur_invdet (slno, ItemIDpur,purinvid) values (@slno, @ItemIDpur, @purinvid)"
                cmd = New OleDb.OleDbCommand(sql, cn)
                cmd.Parameters.AddWithValue("@slno", Val(txtitemsl.Text))
                cmd.Parameters.AddWithValue("@ItemIDpur", txtitemid.Text)
                cmd.Parameters.AddWithValue("@purinvid", txtpurinvid.text)
                Dim n As Int32 = cmd.ExecuteNonQuery()
                If n Then
                    MsgBox("Saved")
                End If
            End If
            cmd.Dispose()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
xrjf 230 Posting Whiz

You are setting just one parameter in the Update statement while adding later 3 parameters. Can't you include the execute cmd.executeNonQuerys inside a try - catch to see if there is any error message?

xrjf 230 Posting Whiz

Change lines #21 and 22 into the following to see how many registers are really updated:

           dim n as int32 = cmd.ExecuteNonQuery() 'n=The number of rows affected'
           MsgBox("Updated "+n.tostring+" rows")

Change lines #30 and 31 into the following and see how many registers are really saved:

           dim n as int32= cmd.ExecuteNonQuery() 'n=The number of rows affected'
           MsgBox("Saved " + n.tostring + " rows")