VB.net Danna ekekgen help ekak

Tharakadj

Well-known member
  • May 11, 2009
    3,902
    316
    83
    machan mata podi wadak ona

    vb.jpg

    oya yata tiyena Item name ekai price ekai dala add button eka click karama
    uda tina combo box eke name eka + price penana ona.

    eka man haduwa.

    ita passe api add karapu Item wala price eka add wela tina count eken average price eka ena widiyata average price kiyana label eke penana ona.

    aluthen Item add karama average price eka auto update wena ona
     

    Tharakadj

    Well-known member
  • May 11, 2009
    3,902
    316
    83
    Private Sub addbut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addbut.Click
    itmname = nametxt.Text
    itmprice = pricetxt.Text
    totprice = pricetxt.Text.ToString

    ComboBox1.Items.Add(itmname + " - Rs. " + itmprice.ToString)

    If ComboBox1.Items.Count > 0 Then
    avgprice = totprice / ComboBox1.Items.Count
    avgpricelbl.Text = "Rs. " & avgprice

    Else
    avgpricelbl.Text = "Rs. 0"
    End If

    End Sub

    machan man meka damma average eka waradi ne penanawa
     

    Mr.Tom

    Well-known member
  • Mar 1, 2013
    18,349
    3,725
    113
    EK Automobile
    ලොකු ප්‍රයිස් ලිස්ට් එකක් ගන්නව නම් ඩේටා බේස් එකක් ලිංක් කරලා ඒකේ ටේබල් එකට ඩේටා ටික අප්ලෝඩ් කරලා ගන්න. නැත්තං ඇරේ එකක හරි වේරියබල්ස් වල හරි ප්‍රයිසස් ටික තියාගෙන පස්සේ ඇවරේජ් එක ගන්න.
     

    DjSpK

    Well-known member
  • Nov 4, 2008
    5,298
    1,005
    113
    I'm Looking for Me !
    Private Sub addbut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addbut.Click
    itmname = nametxt.Text
    itmprice = pricetxt.Text
    totprice = pricetxt.Text.ToString

    ComboBox1.Items.Add(itmname + " - Rs. " + itmprice.ToString)

    If ComboBox1.Items.Count > 0 Then
    avgprice = totprice / ComboBox1.Items.Count
    avgpricelbl.Text = "Rs. " & avgprice

    Else
    avgpricelbl.Text = "Rs. 0"
    End If

    End Sub

    machan man meka damma average eka waradi ne penanawa
    combo box ekakata add unata passe eka string ekak venava eka aye parse karala ganna eka bad coding style ekak
    tuple ekak hari array list ekak hari use karanna venava
    wait
     
    • Like
    Reactions: Rated_R

    Tharakadj

    Well-known member
  • May 11, 2009
    3,902
    316
    83
    ලොකු ප්‍රයිස් ලිස්ට් එකක් ගන්නව නම් ඩේටා බේස් එකක් ලිංක් කරලා ඒකේ ටේබල් එකට ඩේටා ටික අප්ලෝඩ් කරලා ගන්න. නැත්තං ඇරේ එකක හරි වේරියබල්ස් වල හරි ප්‍රයිසස් ටික තියාගෙන පස්සේ ඇවරේජ් එක ගන්න.

    lokuwata nemei machan class eke wadak. variable walin tamai karana ona
     

    Mr.Tom

    Well-known member
  • Mar 1, 2013
    18,349
    3,725
    113
    EK Automobile
    ආ මෙන්න රතුපාට කරලා තියන ටික දැම්මම සියලු දොස් නිවාරණයි

    Public Class Form1
    Dim itmname As String
    Dim itmprice As Single
    Dim totprice As Single
    Dim avgprice As Single


    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    itmname = nametxt.Text
    itmprice = pricetxt.Text
    totprice = totprice + pricetxt.Text.ToString


    ComboBox1.Items.Add(itmname + " - Rs. " + itmprice.ToString)

    If ComboBox1.Items.Count > 0 Then
    avgprice = totprice / ComboBox1.Items.Count
    avgpricelbl.Text = "Rs. " & avgprice

    Else
    avgpricelbl.Text = "Rs. 0"
    End If

    End Sub
    End Class

    උඹට වැරදිලා තියන තැන පැහැදිලි නේද. වේරියබල් එක ට වැලිව් එක එකතු කරන්නේ නැතුව උඹ කෙලින්ම ඒකට අගය ආදේශ කරලා.
     
    • Like
    Reactions: Tharakadj

    Tharakadj

    Well-known member
  • May 11, 2009
    3,902
    316
    83
    ආ මෙන්න රතුපාට කරලා තියන ටික දැම්මම සියලු දොස් නිවාරණයි

    Public Class Form1
    Dim itmname As String
    Dim itmprice As Single
    Dim totprice As Single
    Dim avgprice As Single


    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    itmname = nametxt.Text
    itmprice = pricetxt.Text
    totprice = totprice + pricetxt.Text.ToString


    ComboBox1.Items.Add(itmname + " - Rs. " + itmprice.ToString)

    If ComboBox1.Items.Count > 0 Then
    avgprice = totprice / ComboBox1.Items.Count
    avgpricelbl.Text = "Rs. " & avgprice

    Else
    avgpricelbl.Text = "Rs. 0"
    End If

    End Sub
    End Class

    උඹට වැරදිලා තියන තැන පැහැදිලි නේද. වේරියබල් එක ට වැලිව් එක එකතු කරන්නේ නැතුව උඹ කෙලින්ම ඒකට අගය ආදේශ කරලා.

    Thanx machan help ekata
    rep+
     

    DjSpK

    Well-known member
  • Nov 4, 2008
    5,298
    1,005
    113
    I'm Looking for Me !
    Code:
    Public Class Form1
        Dim DataList As Dictionary(Of String, Integer) = New Dictionary(Of String, Integer)
        Dim AvgPrice As Integer = 0
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If Not DataList.ContainsKey(TextBox1.Text) Then
                DataList.Add(TextBox1.Text, Int(TextBox2.Text))
            Else
                If Not DataList(TextBox1.Text).Equals(Int(TextBox2.Text)) Then
                    DataList(TextBox1.Text) = Int(TextBox2.Text)
                End If
            End If
            UpdateList()
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            DataList.Remove(DataList.ToArray(ComboBox1.SelectedIndex).Key)
            UpdateList()
        End Sub
        Private Sub UpdateList()
            ComboBox1.Items.Clear()
            AvgPrice = 0
            For Each ListItem As KeyValuePair(Of String, Integer) In DataList
                ComboBox1.Items.Add(ListItem.Key & " | Price : " & ListItem.Value)
                AvgPrice = AvgPrice + ListItem.Value
            Next
            Label4.Text = AvgPrice / DataList.Count
        End Sub
    End Class
    Source : https://dl.dropboxusercontent.com/u/24436775/ComboTest.zip
     

    Tharakadj

    Well-known member
  • May 11, 2009
    3,902
    316
    83
    Code:
    Public Class Form1
        Dim DataList As Dictionary(Of String, Integer) = New Dictionary(Of String, Integer)
        Dim AvgPrice As Integer = 0
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If Not DataList.ContainsKey(TextBox1.Text) Then
                DataList.Add(TextBox1.Text, Int(TextBox2.Text))
            Else
                If Not DataList(TextBox1.Text).Equals(Int(TextBox2.Text)) Then
                    DataList(TextBox1.Text) = Int(TextBox2.Text)
                End If
            End If
            UpdateList()
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            DataList.Remove(DataList.ToArray(ComboBox1.SelectedIndex).Key)
            UpdateList()
        End Sub
        Private Sub UpdateList()
            ComboBox1.Items.Clear()
            AvgPrice = 0
            For Each ListItem As KeyValuePair(Of String, Integer) In DataList
                ComboBox1.Items.Add(ListItem.Key & " | Price : " & ListItem.Value)
                AvgPrice = AvgPrice + ListItem.Value
            Next
            Label4.Text = AvgPrice / DataList.Count
        End Sub
    End Class
    Source : https://dl.dropboxusercontent.com/u/24436775/ComboTest.zip

    Thanx machan very much
    rep+