PDA

View Full Version : Code Hell!


DA Master
03-15-04, 08:22 AM
Private Sub cmdEnter_Click()
' Dimension Our Variables
Dim strGroup1 As String
Dim strGroup2 As String
Dim strGroup3 As String
Dim strGroup4 As String
Dim strGroup5 As String
Dim strIsCorrect As String

' Populate Variables
Do While strIsCorrect <> "Yes"
For i = 1 To 5
strGroup = InputBox("Enter your number most favourite group", "Group")
Next i

' Print Variable Results
Print "Thank you for entering your 5 most favourite"
Print "groups which are as follows:-"
Print strGroup

strIsCorrect = InputBox("Is this correct?", "List Correct?")

If strIsCorrect = "Yes" Then
MsgBox "Thank You", vbInformation, "Thank You"
End
End If
Loop
End Sub

I have this code, that brings up five input boxes and allows the user to input their five favoruite groups. However, I cannot figure out how to assign strGroup[Number] (Dimensioned at top) into this line of code...

strGroup = InputBox("Enter your number most favourite group", "Group")

Which is in a For Next loop to save writing out the code over again.

Any help is greatly appriciated.

AutoObsession87
03-23-04, 09:35 PM
What if you use an array? In other words, you'd have strGroup[i] where 'i' is 1 through 5. So you'd have an array of size 5.

code:
Dim strGroup(5) As String

Then, you can access each member of the array by the following: strGroup[i] in your "For" loop. The i in brackets indicates the index number of each member of the array.

Just remember that array indexes start at 0, so the array will actually go from 0-4.

Was this of any help? Need me to clarify?

Yours,
Scott Petricig

DA Master
03-24-04, 01:04 PM
Thanks but I solved it now, I used a if function.