Help Stuck area of a multiroom building

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2007
Posts: 58
Reputation: bpacheco1227 is an unknown quantity at this point 
Solved Threads: 0
bpacheco1227 bpacheco1227 is offline Offline
Junior Poster in Training

Help Stuck area of a multiroom building

 
0
  #1
Oct 1st, 2008
I am very stuck. I need to write a prog that uses arrays and receives the length and the width of a multiroom building and find the area needed for for the carpet or wood flooring. This is just the first part and thisis as far as I am able to go/understand. Any help would greatly appreciated, Thank You.

  1. Public Class Form1
  2. Dim dimensions() As Integer
  3. Dim rooms As Integer
  4.  
  5. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  6. Dim prompt1, prompt2, title As String
  7. Dim i As Short
  8. prompt1 = "Enter the length of the room"
  9. prompt2 = "Enter the width of the room"
  10. rooms = InputBox("How many rooms?", "Create Array")
  11.  
  12. If rooms > 0 Then ReDim dimensions(rooms - 1)
  13. For i = 0 To UBound(dimensions)
  14. title = "Room " & (i + 1)
  15. dimensions(i) = InputBox(prompt1, title)
  16. Next
  17. End Sub
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 306
Reputation: timothybard is an unknown quantity at this point 
Solved Threads: 26
timothybard's Avatar
timothybard timothybard is offline Offline
Posting Whiz

Re: Help Stuck area of a multiroom building

 
0
  #2
Oct 2nd, 2008
Do you know how to use classes? I would recommend created a class of "room" that has the following properties:
Length
Width
Dimension (readonly)

You can then make an array of the class and loop through the array for input and output.

Let me know if you need code.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 58
Reputation: bpacheco1227 is an unknown quantity at this point 
Solved Threads: 0
bpacheco1227 bpacheco1227 is offline Offline
Junior Poster in Training

Re: Help Stuck area of a multiroom building

 
0
  #3
Oct 2nd, 2008
we just learned classes last week and in this assignment we can just use an array. This is the assignment.

Write a program that uses arrays and receives the length and the width of a multi room building
and find the area needed for carpet or wood flooring. After finding the total area, give total
price suggestion for both carpet and wood flooring. Use comboBox to list price of carpets ranging
from $5 to $25 with $2 dollars increment and wood flooring from $10 to $15 range of $1.00 increment.


No classes are mentioned. I'm sorry I normally don't need this much assistance, but this one has me stumped. I have a good idea how to do the the increments using a for loop, but not how to insert them into a combo box. Our professor actually didn't show us combo boxes, but he did assign them and the book isn't much help. My main problem is coding the arrays for the multi room building prompting for length and width, from there I know how to get the area.
Hopefully I get partial credit even if it's not complete. Any help would be appreciated, thank you.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 306
Reputation: timothybard is an unknown quantity at this point 
Solved Threads: 26
timothybard's Avatar
timothybard timothybard is offline Offline
Posting Whiz

Re: Help Stuck area of a multiroom building

 
1
  #4
Oct 2nd, 2008
Well, if you don't want to use a class but instead only use an array, I recommend using a multidimensional array. A multidimensional array will allow you to store the lengths and widths of each room in the same array; the usage of a multidimensional array should be straight forward by looking at some code. Below is updated code showing how to use a multidimensional array:

  1. Dim dimensions(0, 0) As Integer
  2. Dim rooms As Integer
  3.  
  4. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  5. Dim prompt1, prompt2, title As String
  6. Dim i As Short
  7. prompt1 = "Enter the length of the room"
  8. prompt2 = "Enter the width of the room"
  9. rooms = InputBox("How many rooms?", "Create Array")
  10.  
  11. If rooms > 0 Then ReDim dimensions(rooms - 1, 1)
  12.  
  13. For i = 0 To UBound(dimensions)
  14. title = "Room " & (i + 1)
  15. dimensions(i, 0) = InputBox(prompt1, title)
  16. dimensions(i, 1) = InputBox(prompt2, title)
  17. Next
  18. End Sub

Also, here are some usful properties of the ComboBox object:

  1. ComboBox1.Items.Add("Item 1")
  2. Dim selectedItemIndex As Integer
  3. Dim selectedItem As String
  4. selectedItemIndex = ComboBox1.SelectedIndex
  5. selectedItem = ComboBox1.SelectedItem

Let me know if you have any questions.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 58
Reputation: bpacheco1227 is an unknown quantity at this point 
Solved Threads: 0
bpacheco1227 bpacheco1227 is offline Offline
Junior Poster in Training

Re: Help Stuck area of a multiroom building

 
0
  #5
Oct 2nd, 2008
thanks that helped tremendously at least I was somewhat on the right track, more like just one wheel on the track. I will now work on the combo box, thank you.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 58
Reputation: bpacheco1227 is an unknown quantity at this point 
Solved Threads: 0
bpacheco1227 bpacheco1227 is offline Offline
Junior Poster in Training

Re: Help Stuck area of a multiroom building

 
0
  #6
Oct 2nd, 2008
Can't figure how to populate the combobox correctly it stays blank, I think I'm completely off track. Please Help.

  1. Public Class Form1
  2. Dim dimensions(0, 0) As Integer
  3. Dim rooms As Integer
  4.  
  5. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  6. Dim prompt1, prompt2, title As String
  7. Dim i As Short
  8. prompt1 = "Enter the length of the room"
  9. prompt2 = "Enter the width of the room"
  10. rooms = InputBox("How many rooms?", "Create Array")
  11.  
  12. If rooms > 0 Then ReDim dimensions(rooms - 1, 1)
  13. For i = 0 To UBound(dimensions)
  14. title = "Room " & (i + 1)
  15. dimensions(i, 0) = InputBox(prompt1, title)
  16. dimensions(i, 1) = InputBox(prompt2, title)
  17. Next
  18. End Sub
  19.  
  20.  
  21. Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
  22.  
  23. Dim listPrices As Integer()
  24.  
  25. ' ComboBox1.Items.Add("Item 2")
  26. listPrices = New Integer() {5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25}
  27.  
  28. Dim selectedItemIndex As Integer
  29. Dim selectedItem As String
  30. ComboBox1.Items.Add(listPrices)
  31. selectedItemIndex = ComboBox1.SelectedIndex
  32. selectedItem = ComboBox1.SelectedItem
  33.  
  34. End Sub
  35. End Class
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 306
Reputation: timothybard is an unknown quantity at this point 
Solved Threads: 26
timothybard's Avatar
timothybard timothybard is offline Offline
Posting Whiz

Re: Help Stuck area of a multiroom building

 
0
  #7
Oct 2nd, 2008
There are two issue you are having:

1) You can the code to add items to the combobox within the SelectedIndexChanged event. Since there are no items in the combobox, no items can be selected and, therefore, the selected index will never change and the code is never run.

2) To populate the combobox with an array, you need to loop through array and add each item to the combobox individually.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC