| | |
Help Stuck area of a multiroom building
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2007
Posts: 58
Reputation:
Solved Threads: 0
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.
VB Syntax (Toggle Plain Text)
Public Class Form1 Dim dimensions() As Integer Dim rooms As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim prompt1, prompt2, title As String Dim i As Short prompt1 = "Enter the length of the room" prompt2 = "Enter the width of the room" rooms = InputBox("How many rooms?", "Create Array") If rooms > 0 Then ReDim dimensions(rooms - 1) For i = 0 To UBound(dimensions) title = "Room " & (i + 1) dimensions(i) = InputBox(prompt1, title) Next End Sub
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.
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.
•
•
Join Date: Jul 2007
Posts: 58
Reputation:
Solved Threads: 0
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.
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.
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:
Also, here are some usful properties of the ComboBox object:
Let me know if you have any questions.
vb Syntax (Toggle Plain Text)
Dim dimensions(0, 0) As Integer Dim rooms As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim prompt1, prompt2, title As String Dim i As Short prompt1 = "Enter the length of the room" prompt2 = "Enter the width of the room" rooms = InputBox("How many rooms?", "Create Array") If rooms > 0 Then ReDim dimensions(rooms - 1, 1) For i = 0 To UBound(dimensions) title = "Room " & (i + 1) dimensions(i, 0) = InputBox(prompt1, title) dimensions(i, 1) = InputBox(prompt2, title) Next End Sub
Also, here are some usful properties of the ComboBox object:
vb Syntax (Toggle Plain Text)
ComboBox1.Items.Add("Item 1") Dim selectedItemIndex As Integer Dim selectedItem As String selectedItemIndex = ComboBox1.SelectedIndex selectedItem = ComboBox1.SelectedItem
Let me know if you have any questions.
•
•
Join Date: Jul 2007
Posts: 58
Reputation:
Solved Threads: 0
Can't figure how to populate the combobox correctly it stays blank, I think I'm completely off track. Please Help.
VB Syntax (Toggle Plain Text)
Public Class Form1 Dim dimensions(0, 0) As Integer Dim rooms As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim prompt1, prompt2, title As String Dim i As Short prompt1 = "Enter the length of the room" prompt2 = "Enter the width of the room" rooms = InputBox("How many rooms?", "Create Array") If rooms > 0 Then ReDim dimensions(rooms - 1, 1) For i = 0 To UBound(dimensions) title = "Room " & (i + 1) dimensions(i, 0) = InputBox(prompt1, title) dimensions(i, 1) = InputBox(prompt2, title) Next End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Dim listPrices As Integer() ' ComboBox1.Items.Add("Item 2") listPrices = New Integer() {5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25} Dim selectedItemIndex As Integer Dim selectedItem As String ComboBox1.Items.Add(listPrices) selectedItemIndex = ComboBox1.SelectedIndex selectedItem = ComboBox1.SelectedItem End Sub End Class
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.
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.
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: Deployment in vb.net
- Next Thread: Image in TITLE BAR?
| Thread Tools | Search this Thread |
.net 30minutes 2005 2008 access account arithmetic array arrays basic binary bing button buttons c# center check checkbox code combobox component connectionstring convert crystalreport data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dropdownlist excel file-dialog folder ftp generatetags google gridview hardcopy image images inline insert intel internet listview mobile monitor ms net networking output passingparameters peertopeervideostreaming picturebox picturebox1 plugin port print printing problem problemwithinstallation project reports" save searchbox searchvb.net select serial server soap sorting table tcp text textbox timer toolbox trim update updown user usercontrol vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web wpf





