I'am a little board today, so you get luckey, and I write your code for you! Have Fun!
Code:
Type walltype
Length As Double
Width As Double
End Type
Sub GetWallInfo()
On Error GoTo Er
Const SubTitle = "Get Wall Info"
Dim I As Long
Dim cntWalls As Long
Dim Walls() As walltype
Dim Size() As String
Dim str As String
'Get number of walls
cntWalls = InputBox("How Many Walls?", SubTitle, 0)
If cntWalls = 0 Then Exit Sub
'Resize Dynamic Array to wall count
ReDim Walls(1 To cntWalls)
For I = 1 To cntWalls
'Simpler code but alot more input for the user
'Walls(I).Length = InputBox("Length in Inches Wall " & I & " :", "Wall " & I & " Get Length", 0.5)
'Walls(I).Width = InputBox("Width in Inches Wall " & I & " :", "Wall " & I & " Get Width", 0.5)
'More complex code but stops more errors and uses less inputs for the user
str = Trim(InputBox("Enter Length;Width for Wall " & I & ":", "Wall " & I, "0.5;0.5"))
'Give them a way to cancel
If str = "" Or InStr(str, ";") = 0 Then Goto Ex
'Seperate length from width
Size = Split(str, ";")
'Store in array
Walls(I).Length = Val(Size(0))
Walls(I).Width = Val(Size(1))
'Reset size for next wall
Erase Size
Next I
'...do other stuff with wall info
str = ""
For I = 1 To cntWalls
str = str & "Wall " & I & " Length:" & Walls(I).Length & " & Width:" & Walls(I).Width & vbCrLf
Next I
MsgBox str, vbInformation, "Results"
'...
Ex:
'All done So Release Memory used to store wall info
Erase Walls
Exit Sub
Er:
MsgBox "Error# " & Err.Number & " - " & Err.Description, vbCritical, SubTitle
Resume Ex
Resume
End Sub
Bookmarks