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

How to get a progress bar changes from its previous step?

$
0
0
Hi all :wave:

Consider a progress bar which supposed to indicate a quality for instance.

How can I get a three state thing which states that this progress bar is fixed, increasing or decreasing?
In mathematics there's a way in which you calculate differences between current x(t) and its one step retard x(t-1). I wasn't successful to get my previous progress bar value due to "value change" event is not available for this control.

If anyone know a trick to rectify this matter I will be so much appreciated. ♥ Thanks in advanced

VS 2019 Just a visual thing (names in Properties Window(Box))

$
0
0
Hi,

I have some Style-members as Integer()
And a private member myStyle as integer
Code:

    Public ExpandAll() As Integer = New Integer() {Expand, Expand, Expand, Expand}
    Public FloatAll() As Integer = New Integer() {Float, Float, Float, Float}
    Public LockAll() As Integer = New Integer() {Lock, Lock, Lock, Lock}
    Public RigidAl() As Integer = New Integer() {Rigid, Rigid, Rigid, Rigid}
    Public DLeft() As Integer = New Integer() {Expand, Rigid, Rigid, Rigid}
    Private myStyle() As Integer = DLeft

There is a Property to show in the PropertiesBox
Code:

  Public Property Style As Integer()
        Get
            Return myStyle
        End Get
        Set(value As Integer())
            myStyle = value
        End Set
    End Property

In the PropertiesBox my Property appears as:

Style_________Int32[]Array
[0]__________ 0
[1]__________ 3
[2]__________ 3
[3]__________ 3


I would like it to be shown as, for instance, the Padding Property.
So with meaningful names like: All, Left,Top, etc.Anybody knows if, and if so, how this can be done?

[RESOLVED] How to get a progress bar changes from its previous step?

$
0
0
Hi all :wave:

Consider a progress bar which supposed to indicate a quality for instance.

How can I get a three state thing which states that this progress bar is fixed, increasing or decreasing?
In mathematics there's a way in which you calculate differences between current x(t) and its one step retard x(t-1). I wasn't successful to get my previous progress bar value due to "value change" event is not available for this control.

If anyone know a trick to rectify this matter I will be so much appreciated. ♥ Thanks in advanced

Can Someone help me to correct the following code for SelectedItems and its Subitems

$
0
0
Hello
Can Someone help me to correct the following code for SelectedItems and its Subitems in Listview as per proper columns


Code:

My listview1 is Displayed as from Excel range
     
      Product      Name  Qty
CHKBOX Fruits    Apple  20
CHKBOX Fruits    Banana 40
CHKBOX Fruits    Kiwi  60
CHKBOX Fruits    Oranges30
CHKBOX Fruits    Mangoes40

Code:

Private Sub CmdAddFruits_Click(sender As Object, e As EventArgs) Handles CmdAddFruits.Click

ListView1.Items.Clear()

For selItemsCount As Integer = 0 To ListView1.Items.Count - 1
      If ListView1.Items(selItemsCount).Checked = True Then
                ListView1.Items.Add(ListView1.Items(selItemsCount).Text.ToString())

              For selSubitems As Integer = 0 To ListView1.Items(selItemsCount).SubItems.Count - 1
                  ListView1.Items.Add(ListView1.Items(selItemsCount).SubItems(selSubitems).ToString())
                Next
            End If
        Next

End Sub

After Selecting any of the Fruits or
for eg. i selected only Banana and Kiwi and pressed CmdAddFruits i get

Code:


My listview1 is Displayed as
     
      Product      Name  Qty
CHKBOX Fruits    Apple  20
CHKBOX Fruits    Banana 40
CHKBOX Fruits    Kiwi  60
CHKBOX Fruits    Oranges30
CHKBOX Fruits    Mangoes40
CHKBOX Fruits
CHKBOX ListViewSubitem:{Fruits}
CHKBOX ListViewSubitem:{Banana}
CHKBOX ListViewSubitem:{40}
CHKBOX Fruits
CHKBOX ListViewSubitem:{Fruits}
CHKBOX ListViewSubitem:{Kiwi}
CHKBOX ListViewSubitem:{60}
     

Actaully Wanted Display as
     
      Product      Name  Qty
CHKBOX Fruits    Banana 40
CHKBOX Fruits    Kiwi  60

Also Listview1.Items.Clear() Clears the full list view and when above items added it does not display anything
Thanks

SamD
Thread 10 892479
50

Recording voice from specific position in file

$
0
0
Hi all,

Is it possible to resume recording voice via microphone from specific position in file?
Example.
Im starting recording and after 5min I made mistake, now I want to record again last 20sec and still operating on one file

Read XML file and insert into ListBox

$
0
0
Hello,

I'm trying to read an xml file and then put it in a ListBox in VB.net.
I just need the "Country" and "Name" columns.
But I only manage to read the entire XML file.

Does anyone have a tip on how I can read these 2 columns and get them into the ListBox?

Thanks in advance!



The XML file:

<Wines>
<Wine Name="Canapi Grillo" Country="Italie" Region="Sicilie" Soort="Wit" Druif="Grillo" AlcoholPrct="12"/>
<Wine Name="Miopasso Fiano" Country="Italie" Region="Sicilie" Soort="Wit" Druif="Fiano" AlcoholPrct="13"/>
<Wine Name="Elegance Sauvignon Blanc" Country= "Frankrijk" Region="Pays d'Oc" Soort="Wit" Druif="Sauvignon Blanc" AlcoholPrct="11,5"/>
</Wines>



The code:

Code:

Private Sub WijnLijstBarButton_Click(sender As Object, e As RoutedEventArgs)
Dim xdocument As XDocument = XDocument.Load("..\..\wine.xml")
Dim wines As IEnumerable(Of XElement) = xdocument.Elements()
For Each wine In wine
      Listbox1.Items.Add(wine)
Next wine

[RESOLVED] Can Someone help me to correct the following code for SelectedItems and its Subitems

$
0
0
Hello
Can Someone help me to correct the following code for SelectedItems and its Subitems in Listview as per proper columns


Code:

My listview1 is Displayed as from Excel range
     
      Product      Name  Qty
CHKBOX Fruits    Apple  20
CHKBOX Fruits    Banana 40
CHKBOX Fruits    Kiwi  60
CHKBOX Fruits    Oranges30
CHKBOX Fruits    Mangoes40

Code:

Private Sub CmdAddFruits_Click(sender As Object, e As EventArgs) Handles CmdAddFruits.Click

ListView1.Items.Clear()

For selItemsCount As Integer = 0 To ListView1.Items.Count - 1
      If ListView1.Items(selItemsCount).Checked = True Then
                ListView1.Items.Add(ListView1.Items(selItemsCount).Text.ToString())

              For selSubitems As Integer = 0 To ListView1.Items(selItemsCount).SubItems.Count - 1
                  ListView1.Items.Add(ListView1.Items(selItemsCount).SubItems(selSubitems).ToString())
                Next
            End If
        Next

End Sub

After Selecting any of the Fruits or
for eg. i selected only Banana and Kiwi and pressed CmdAddFruits i get

Code:


My listview1 is Displayed as
     
      Product      Name  Qty
CHKBOX Fruits    Apple  20
CHKBOX Fruits    Banana 40
CHKBOX Fruits    Kiwi  60
CHKBOX Fruits    Oranges30
CHKBOX Fruits    Mangoes40
CHKBOX Fruits
CHKBOX ListViewSubitem:{Fruits}
CHKBOX ListViewSubitem:{Banana}
CHKBOX ListViewSubitem:{40}
CHKBOX Fruits
CHKBOX ListViewSubitem:{Fruits}
CHKBOX ListViewSubitem:{Kiwi}
CHKBOX ListViewSubitem:{60}
     

Actaully Wanted Display as
     
      Product      Name  Qty
CHKBOX Fruits    Banana 40
CHKBOX Fruits    Kiwi  60

Also Listview1.Items.Clear() Clears the full list view and when above items added it does not display anything
Thanks

SamD
Thread 10 892479
50

[RESOLVED] Recording voice from specific position in file

$
0
0
Hi all,

Is it possible to resume recording voice via microphone from specific position in file?
Example.
Im starting recording and after 5min I made mistake, now I want to record again last 20sec and still operating on one file

Extract value from ListBox to TextBox

$
0
0
Hello,

I might have a "noobie" question. Sorry about that.
I have a function that reads an xml file and puts it in a ListBox.
I now want to create a function that moves the selected item from the ListBox to a textbox.

I can't find an example anywhere (or maybe I'm not looking properly) but can someone give me an example of how I can best approach this?

For example, of the selected items, I only want to move the value of "Country" of the selected item to a Textbox.

Sorry for the "noobie" question, but I realy appreciate the advice/help!



The XML file:

<Wines>
<Wine Name="Canapi Grillo" Country="Italie" Region="Sicilie" Soort="Wit" Druif="Grillo" AlcoholPrct="12"/>
<Wine Name="Miopasso Fiano" Country="Italie" Region="Sicilie" Soort="Wit" Druif="Fiano" AlcoholPrct="13"/>
<Wine Name="Elegance Sauvignon Blanc" Country= "Frankrijk" Region="Pays d'Oc" Soort="Wit" Druif="Sauvignon Blanc" AlcoholPrct="11,5"/>
</Wines>


The code:

Code:

Private Sub WijnLijstBarButton_Click(sender As Object, e As RoutedEventArgs)


        'The XML file has been readed
        Dim xelement As XElement = XElement.Load("Assets/Wijnen.xml")
        Dim xWines As IEnumerable(Of XElement) = xelement.Elements()
        ' The Country and the name are read into the  ListBox
        For Each xWine In xWines
            WijnListBox.Items.Add(xWine.@Country.PadRight(37, " ") & xWine.@Name.PadRight(30, " "))

        Next xWine
    End Sub

How to get a unique chrome ID in vb?

$
0
0
I know how to get all the names of the Chrome tabs and the URL of the current active tab in VB I want to get a unique ID for each tab, because there are tabs with the same name and URL
Code:

Public Function GetBrowserUrlActivaChrome() As string
    Dim procsChrome As Process() = Process.GetProcessesByName("chrome")
    For Each chrome As Process In procsChrome
        If chrome.MainWindowHandle = IntPtr.Zero Then Continue For
        Dim element As UIAutomationClient.CUIAutomation = New UIAutomationClient.CUIAutomation()
        Dim root As UIAutomationClient.IUIAutomationElement = element.ElementFromHandle(chrome.MainWindowHandle)
        If element Is Nothing Then Return ""
        Dim condition1 As UIAutomationClient.IUIAutomationCondition = element.CreatePropertyCondition(UIAutomationClient.UIA_PropertyIds.UIA_ProcessIdPropertyId, chrome.Id)
        Dim condition2 As UIAutomationClient.IUIAutomationCondition = element.CreatePropertyCondition(UIAutomationClient.UIA_PropertyIds.UIA_IsControlElementPropertyId, True)
        Dim condition3 As UIAutomationClient.IUIAutomationCondition = element.CreatePropertyCondition(UIAutomationClient.UIA_PropertyIds.UIA_IsContentElementPropertyId, True)
        Dim condition4 As UIAutomationClient.IUIAutomationCondition = element.CreatePropertyCondition(UIAutomationClient.UIA_PropertyIds.UIA_ControlTypePropertyId, UIAutomationClient.UIA_ControlTypeIds.UIA_EditControlTypeId)
        Dim conditions As UIAutomationClient.IUIAutomationCondition() = New UIAutomationClient.IUIAutomationCondition(3) {}
        conditions(0) = condition1
        conditions(1) = condition2
        conditions(2) = condition3
        conditions(3) = condition4
        Dim andCondition As UIAutomationClient.IUIAutomationCondition = element.CreateAndConditionFromArray(conditions)
        Dim elementx As IUIAutomationElement = root.FindFirst(UIAutomationClient.TreeScope.TreeScope_Descendants, andCondition)
        If elementx IsNot Nothing Then
          return (CType(elementx.GetCurrentPattern(UIAutomationClient.UIA_PatternIds.UIA_ValuePatternId), UIAutomationClient.IUIAutomationValuePattern)).CurrentValue.ToString()
        End If
    Next
    Return String.Empty
End Function

Public Sub AllTabsNames()
    Dim procsChrome As Process() = Process.GetProcessesByName("chrome")
    For Each chrome As Process In procsChrome
        If chrome.MainWindowHandle = IntPtr.Zero Then Continue For
        Dim winName As String = chrome.MainWindowTitle
        Dim q As Integer = InStr(winName, " - Google Chrome")
        If q > 0 Then winName = Mid(winName, 1, q - 1)
        Dim root As AutomationElement = AutomationElement.FromHandle(chrome.MainWindowHandle)
        Dim condNewTab As Condition = New PropertyCondition(AutomationElement.NameProperty, winName)
        Dim elmNewTab As AutomationElement = root.FindFirst(TreeScope.Descendants, condNewTab)
        Dim treewalker As TreeWalker = TreeWalker.ControlViewWalker
        Dim elmTabStrip As AutomationElement = treewalker.GetParent(elmNewTab)
        Dim condTabItem As Condition = New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TabItem)
        For Each tabitem As AutomationElement In elmTabStrip.FindAll(TreeScope.Children, condTabItem)
            Debug.Print(tabitem.Current.Name )
        Next
    Next
end sub

VS 2008 problem in adding data

$
0
0
pls need guide sir,

heres my code; thank you in advance


ineed result like this..
Code:

room    subject
a          mathe
a          english
not like this
room    subject
a          mathe
a          mathe


Code:

cmd = con.CreateCommand()
            cmd.CommandType = CommandType.Text
            cmd = New SqlCommand("Select * from tblschedule where room like '%" & TextBox2.Text & "%'", con)
            cmd.ExecuteNonQuery()


         
            Dim sda As SqlDataReader = cmd.ExecuteReader
            Dim ds As New DataSet
            sda.Read()
            If Val(TextBox3.Text = ds.Tables("tblschedule").Rows(0)("subject").count) > 1 Then
                MsgBox("subject Already Exist", MessageBoxIcon.Error, "Error")



            Else

                cmd = con.CreateCommand()
                cmd.CommandType = CommandType.Text
                cmd = New SqlCommand("schedule_class", con)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.AddWithValue("@room", TextBox2.Text.ToUpper.Trim)
                cmd.Parameters.AddWithValue("@yearlevel", TextBox1.Text.ToUpper.Trim)
                cmd.Parameters.AddWithValue("@time", ComboBox2.Text.ToUpper.Trim)
                cmd.Parameters.AddWithValue("@subject", TextBox3.Text.ToUpper.Trim)
                cmd.Parameters.AddWithValue("@teacher", TextBox4.Text.ToUpper.Trim)

                cmd.ExecuteNonQuery()
                MsgBox("Save Sucessfully!", MessageBoxIcon.Information, "Success")

How to hide cursor?

$
0
0
Hi all. :wave:

Is there any specific code to hide cursor in middle of running VB.NET project? The reason is just for AFK and make UI readable and being more user-friendly.

And if so, How to re-show the cursor (for instance by moving mouse).
Thanks in advanced.

Basic variable problem

$
0
0
Hi all. :wave:

There is a byte variable as follow
Code:

Dim Sendcmd() As Byte = { 0, 0, 0, 0 }
which need to be called in
Code:

SerialPort1.Write(Sendcmd, 0, Sendcmd.Lenght - 1)
The question is how to change "0"s with a set of TrackBar controls changeable values?

What I tried and failed:
Code:

Dim Sendcmd() As Byte = {CByte(TrackBar1.Value), CByte(TrackBar2.Value), CByte(TrackBar3.Value), CByte(TrackBar4.Value)}
Code:

Dim Sendcmd() As Byte = {(TrackBar1.Value).ToString, (TrackBar2.Value).ToString, (TrackBar3.Value).ToString, (TrackBar4.Value).ToString}

[RESOLVED] Parse date to correct format

$
0
0
Hi

I have the following code to save file info in a data table to a mysql database table via an adapter:
Code:

With cmd2.Parameters
    .Add("@Name", MySqlDbType.VarChar, 50, "Name")
    .Add("@LastWriteTime", MySqlDbType.DateTime, "LastWriteTime")
End With

My issue is with LastWriteTime. The format in the datatable is dd/MM/yyyy HH :mm:ss (eg. 02/07/2021 14:51:57). I know Mysql accepts date in yyyy-MM-dd format. I obviously have to Parse or TryParse in the above. After a lot of searching, I just cannot figure out how to apply it.

Any help would be much appreciated.

VS 2019 Updating a rich text box fast the first time slow after that....

$
0
0
Morning all,

I'm head scratching here, I can't work out why my richtextbox displays text quickly the first time but if i clear it and refill its much slower...
Its basically pulling notes from a SQL table and displaying them in a rich text box, data is returned from SQL very quickly and it appears to be the text box thats is slow... Code is as follows:

Code:

Private Sub UpdateNotes()
        Console.WriteLine("notes update start: " & Now.ToLongTimeString)
        NewNotesTB.Clear()
        S_NotesRTB.Clear()
        Dim NotesDT As New DataTable
        Dim NewLine As String = Environment.NewLine
        Dim CurrentSQLNotes As New cDetails
        NotesDT = CurrentSQLNotes.Notes_Get(S_SIDTB.Text.ToString)
        Console.WriteLine("notes data returned, display start: " & Now.ToLongTimeString)
        Console.WriteLine("Data table rows: " & NotesDT.Rows.Count)
        For Each Row As DataRow In NotesDT.Rows
            S_NotesRTB.Text += "Created On: " & Row.Item("SN_DateTime").ToString()
            S_NotesRTB.Text += " by " & Row.Item("SN_UserID").ToString()
            S_NotesRTB.Text += " :- " & Row.Item("SN_Notes").ToString()
            S_NotesRTB.Text += NewLine
            S_NotesRTB.Text += NewLine
        Next Row
        NotesDT.Dispose()
        Console.WriteLine("notes display complete: " & Now.ToLongTimeString)
    End Sub


The first time it runs the time stamps are:

notes update start: 10:36:11
notes data returned, display start: 10:36:12
Data table rows: 580
notes display complete: 10:36:12

The next time it runs there is a 14 second delay to display the same data????

notes update start: 10:36:54
notes data returned, display start: 10:36:54
Data table rows: 580
notes display complete: 10:37:08

Any ideas what is going on???

Thanks

[RESOLVED] Basic variable problem

$
0
0
Hi all. :wave:

There is a byte variable as follow
Code:

Dim Sendcmd() As Byte = { 0, 0, 0, 0 }
which need to be called in
Code:

SerialPort1.Write(Sendcmd, 0, Sendcmd.Lenght - 1)
The question is how to change "0"s with a set of TrackBar controls changeable values?

What I tried and failed:
Code:

Dim Sendcmd() As Byte = {CByte(TrackBar1.Value), CByte(TrackBar2.Value), CByte(TrackBar3.Value), CByte(TrackBar4.Value)}
Code:

Dim Sendcmd() As Byte = {(TrackBar1.Value).ToString, (TrackBar2.Value).ToString, (TrackBar3.Value).ToString, (TrackBar4.Value).ToString}

VS 2019 [RESOLVED] Updating a rich text box fast the first time slow after that....

$
0
0
Morning all,

I'm head scratching here, I can't work out why my richtextbox displays text quickly the first time but if i clear it and refill its much slower...
Its basically pulling notes from a SQL table and displaying them in a rich text box, data is returned from SQL very quickly and it appears to be the text box thats is slow... Code is as follows:

Code:

Private Sub UpdateNotes()
        Console.WriteLine("notes update start: " & Now.ToLongTimeString)
        NewNotesTB.Clear()
        S_NotesRTB.Clear()
        Dim NotesDT As New DataTable
        Dim NewLine As String = Environment.NewLine
        Dim CurrentSQLNotes As New cDetails
        NotesDT = CurrentSQLNotes.Notes_Get(S_SIDTB.Text.ToString)
        Console.WriteLine("notes data returned, display start: " & Now.ToLongTimeString)
        Console.WriteLine("Data table rows: " & NotesDT.Rows.Count)
        For Each Row As DataRow In NotesDT.Rows
            S_NotesRTB.Text += "Created On: " & Row.Item("SN_DateTime").ToString()
            S_NotesRTB.Text += " by " & Row.Item("SN_UserID").ToString()
            S_NotesRTB.Text += " :- " & Row.Item("SN_Notes").ToString()
            S_NotesRTB.Text += NewLine
            S_NotesRTB.Text += NewLine
        Next Row
        NotesDT.Dispose()
        Console.WriteLine("notes display complete: " & Now.ToLongTimeString)
    End Sub


The first time it runs the time stamps are:

notes update start: 10:36:11
notes data returned, display start: 10:36:12
Data table rows: 580
notes display complete: 10:36:12

The next time it runs there is a 14 second delay to display the same data????

notes update start: 10:36:54
notes data returned, display start: 10:36:54
Data table rows: 580
notes display complete: 10:37:08

Any ideas what is going on???

Thanks

VS 2010 mciSendString - get length of wave

$
0
0
Hi all,

I spent couple of hours trying to get length of wave file. I have simple code

Code:

   
Dim lengthBuf(256) As Char
        mciSendString("open ""C:\Users\Michadzia\Desktop\ggg.wav"" Type waveaudio Alias recsound", 0, 0, 0)
        mciSendString("status recsound length", lengthBuf, Len(lengthBuf), 0)
        MsgBox(lengthBuf)

the message box show nothing, what I do wrong? I need some feedback during playing, recording etc but I can't get any status of my alias

VS 2017 Return Minimum Date from SQL db

$
0
0
Hello:

A bit old school with great intentionality. Can someone please tell me how I would return the MinDate in this function?

Code:

    Private Function GetEarliestStartDate(ByVal _opcheck As String) As Date
        Dim cn As New ADODB.Connection
        Dim rs As New ADODB.Recordset

        Dim sql As String = "SELECT MIN(StartDate) AS MinDate FROM Schedule " &
                            "WHERE WorkCenterID = '" & _opcheck.Trim & "' " &
                            "AND ScheduleID = '" & cboNewScheduleNo.Text & "' "

        cn.Open(connectionString_Read)
        rs.Open(sql, cn, CursorTypeEnum.adOpenKeyset, LockTypeEnum.adLockReadOnly)

        rs.MoveFirst()
        Return (rs.Fields("MinDate"))

        rs.Close()
        rs = Nothing

        cn.Close()
        cn = Nothing

    End Function

Thank you!

VS 2013 Combobox change based on a different combobox

$
0
0
Hi everyone,

So I have made a userform using VBA in excel and I have decided to make it an app for my colleagues, thing is, I've never actually worked with VB.net, but I do like to learn, long story short:

I managed to make a combobox values dependant from a different combobox in VBA but I'm unable to achieve this in VB.NET,

This is how I did it in VBA:

Code:

Private Sub ComboBox2_Change()

        Application.EnableEvents = False
        ComboBox3.Clear
        Application.EnableEvents = True
       
            Select Case ComboBox2.Value
                Case "Bodyshell"
                    ComboBox3.Enabled = False
                    ComboBox3.Value = "N/A"
                Case "Underbody"
                    ComboBox3.Enabled = False
                    ComboBox3.Value = "N/A"
                Case "Bodyside Assembly"
                    ComboBox3.Enabled = True
                    ComboBox3.AddItem "LH"
                    ComboBox3.AddItem "RH"
                Case "Bodyside Inner"
                    ComboBox3.Enabled = True
                    ComboBox3.AddItem "LH"
                    ComboBox3.AddItem "RH"
....etc.
End Select


End Sub

And it works perfectly, I tried the same in VB.net but apparently that's not the correct way as it seems:

Code:

    Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.SelectedIndexChanged

        Select Case ComboBox2.SelectedValue
            Case "Bodyshell"
                ComboBox3.Enabled = False
                ComboBox3.Items.Clear()
                ComboBox3.ValueMember = "N/A"
        End Select

    End Sub

So far that's the only part I'm stuck on, so if anyone could please help I'd be grateful,

Thank you
Viewing all 28383 articles
Browse latest View live


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