I need some help with Arrays and Loops. (Visual Basic) I need to create a program that will store up to 5 numbers entered by the user into the Array, and then retrieve it.
1) The user has to enter one number at the time into the Text Box called (txtData.Text)
2) When the user will click on the ?Show Values? button, the numbers should then be displayed inside a Message Box.
Question
k2storm
Can some one PLEASEEEE HELPPPP MEEEEE?????
I need some help with Arrays and Loops. (Visual Basic) I need to create a program that will store up to 5 numbers entered by the user into the Array, and then retrieve it.
1) The user has to enter one number at the time into the Text Box called (txtData.Text)
2) When the user will click on the ?Show Values? button, the numbers should then be displayed inside a Message Box.
Small screenshot:
(if the image won't load click HERE! )
Here is the code:
'Declaring Variables
Dim strNumber As String
Dim intArray(1 To 5) As Integer
Dim i As Integer
Dim j As Integer
Dim intIndex As Integer
Private Sub cmdNumber_Click()
'Click here to set the number.
Select Case cboNumber
Case ""
MsgBox "You must select the number of Entries First!", vbOKOnly, "Error Message!"
Case 1
strNumber = 1
Case 2
strNumber = 2
Case 3
strNumber = 3
Case 4
strNumber = 4
Case 5
strNumber = 5
End Select
End Sub
Private Sub cmdOk_Click()
'Arrays with Numbers
intIndex = 0
If txtData.Text = "" Or strNumber = "" Then
MsgBox "You have either not set the allowed number of entries or the array is full!", vbOKOnly, "Error Message!"
Else
For i = 1 To strNumber
? Here is the code to store the data into the array but it doesn?:no:rk :no:
intIndex = (intIndex + 1)
intArray(intIndex) = Val(txtData.Text)
txtData.Text = ""
Next i
j = j + 1
End If
End Sub
Private Sub mnuAllowed_Click()
'Displays an Message Box This Code Works
If strNumber = "" Then
MsgBox "0", vbOKOnly, "Entries Allowed:"
Else
MsgBox strNumber, vbOKOnly, "Entries Allowed:"
End If
End Sub
Private Sub mnuMade_Click()
'Displays the number of user entries made This Code Works
If j = "0" Then
MsgBox "0", vbOKOnly, "Entries Made:"
Else
MsgBox j, vbOKOnly, "Entries Made:"
End If
End Sub
Private Sub mnuValues_Click()
'Displays user entries in a Message Box
intIndex = 1
For i = 1 To j
? Here is the code to show the numbers entered by the user inside a Message Box, but it?s n:no:orking :no:
MsgBox intArray(i), vbOKOnly, "User Input:"
Next i
End Sub
Edited by k2stormLink to comment
Share on other sites
25 answers to this question
Recommended Posts