vb.net school project help

wanderer17

Member
Joined
Jul 7, 2007
Messages
7
Programming Experience
Beginner
hi i am a new beginner in the vb.net language, i am doing a school project, i have been creating a windows form which calculates how much carpet, paint,wallpaper etc would be needed for rooms and then the total for the whole house.


Looking at the Diagram - How can i transfer the name of of the Room and the Costs (i.e. Carpet needed for Room and its Costs) to be displayed into the listbox on the Right hand side?


- As i add new Rooms, i want the Overall total to add up the costs automatically below the listbox. How can i do this?


- I want to be able to Remove Room's from the listbox (on the Right hand side.) - after the Room is removed, the cost of the Room would be removed from the Overall Total cost also. How can i do this?



Thankyou.



wallbw1.png
 
This code may help you. It works unfortunately im having trouble uploading a screenshot. But that is the code that makes it work on my pc. You will definitely add some error handling and extra validation but it should work for you.

VB.NET:
Public Class Form1

    Public Total As Decimal = 0.0

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        If Not IsNumeric(txtNum.Text) Then
            MsgBox("Please enter numeric data only.")
        Else
            Dim decAdd As Decimal = CDec(txtNum.Text)
            lbNums.Items.Add(decAdd)
            Total = Total + decAdd
            lblTotal.Text = Total
        End If
    End Sub

    Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click
        Dim selIndex As Integer = lbNums.SelectedIndex
        If selIndex = -1 Then
            MsgBox("Please select an item.")
        Else

            Total = Total - CDec(lbNums.Items(selIndex))
            lbNums.Items.RemoveAt(selIndex)
            lblTotal.Text = Total
        End If
    End Sub
End Class
 
sorry for replying so late :eek:

thankyou your coding worked:)

could you also tell me i think you have only added 1 item (eg cost of carpet) but what if i want to add the room name, cost of carpet and carpet required on one row in the listbox and then do what your code does above for each item eg cost of carpet and carpet required. can this be done?.:confused:


thankyou
 
Last edited:
could you also tell me i think you have only added 1 item (eg cost of carpet) but what if i want to add the room name, cost of carpet and carpet required on one row in the listbox and then do what your code does above for each item eg cost of carpet and carpet required. can this be done?

thankyou
 
This can be done as long as you format the string you are entering properly. There are many ways in which you can parse the string to pull out the number and still subtract it.

That was something I came up with in thirty seconds to illustrate what you wanted to know. You must customize this for your use specifically.
 
or you could use a ListView for this, with it set to "Details View" just add your columns then basically tread it like a ListBox except it displays more info on each line.
 
thankyou for your reply JuggaloBrotha, as you probably can see i am a beginner but i tryed what you said, i made three columns, roomname, carpet needed, cost carpet and i used the following code

Dim costcar As Decimal = CDec(costcarpetbox.Text)
Dim carneeded As Decimal = CDec(carpetrequiredbox.Text)


ListView2.Items.Add(carpetroomnamebox.Text)
ListView2.Items.Add(carneeded)
ListView2.Items.Add(costcar)

totalcostcarpetlabel.Text = Val(totalcostcarpetlabel.Text) + costcarpet
totalareacarpetlabel.Text = Val(totalareacarpetlabel.Text) + carneeded

but all the three answers i get in my textboxes go under one column, when i actually want each textbox to go under seperate columns, i hope you can check my coding and tell me what i am doing wrong.

i would appreciate any help

thankyou
 
with ListViews you need to use ListView items to store the data in the columns, which does take a tiny bit of work:
VB.NET:
Dim lvItem As New ListViewItem(New String() {carpetroomnamebox.Text, carneeded.ToString, costcar.ToString}, -1)
ListView2.Items.Add(lvItem)
 
Your code Worked Perfectly Thanks !!!!:)

hopefully this is the last time:eek:

I have created a button to remove the selected row from the list but it does not remove the row it only removes from the labels. I know ive probably done something stupid i would appreciate it if you could check the coding.

Dim costcar As Decimal = CDec(costcarpetbox.Text)
Dim carneeded As Decimal = CDec(carpetrequiredbox.Text)
Dim lvItem As New ListViewItem(New String() {carpetroomnamebox.Text, carneeded.ToString, costcar.ToString}, -1)


totalcostcarpetlabel.Text = Val(totalcostcarpetlabel.Text) - Val(costcar)
totalareacarpetlabel.Text = Val(totalareacarpetlabel.Text) - Val(carneeded)
ListView2.Items.Remove(lvItem)



thankyou
 
I believe this code would work, it actually removes all the selected items (even if there's only one item selected)

VB.NET:
        For Each lvItem As ListViewItem In lvHistory.SelectedItems
            lvHistory.Items.Remove(lvitem)
        Next lvItem

I don't have the VS IDE on this computer to test this right now, I will be able to double check it in a couple of hours
 
hi i tried the coding and it worked :D the thing is i need to make a button (remove all) that removes all the items in the listview without removing the column headings can this happen, (which deletes everything in the listview even without selecting anything in the listview)

for some reason when i do listview.clear (which i thought would work) deletes the columns aswell

thanks
 
listview.items.clear()
 
thanks johnH :)

hi john as you can see from above i am using a listview with three columns (column1 =name, column2=carpetneeded, column3=costcarpet) when i have have selected a whole row i want to get the item value (eg 54) i have selected in column 2 to be calculted with some like the value in a textbox.

what command would i use

eg calculation

totalcostcarpetlabel.Text = Val(totalcostcarpetlabel.Text) - (selected item in the column)

i hope you understand what i mean
 
Back
Top