954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

user input and arrays

I would like to know how to take input from a user and populate an array?

I know how to do an array normally. I know how to have a user input information into a file that I create. But, I don't know how to put the two together.

Any help would be appreciated!

funriderrj
Newbie Poster
1 post since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

First Dimension an array with the required number of elements. Design a form with textbox or something to accept input.
Form a loop to run up to the size of the array. Inside the loop get the imput from the user, and the assign stright to the array element with the index.

If you are using a file. Try to write it from the input each line output.
(Otherwise you have to seperate two data with some delimiters.)

open this file in input mode
Run a loop either to EOF or to the size of your dimensioned array.
inside the loop
read the first line from the file
just assign to each elements of the array.
End loop
OVER

AV Manoharan
Junior Poster
166 posts since Jun 2007
Reputation Points: 10
Solved Threads: 9
 

'hope this code snippet can serve your purpose

Dim n(4), s As String, i As Integer

'populating the string array
For i = 0 To 4 Step 1
begin:
s = InputBox("Demo of populating an array by accepting name of 5 students." & Chr(10) & "Enter name of student" & i + 1 & " :", "Populating Array")
If s <> "" Then
n(i) = s
Else
MsgBox "No student has null in name."
GoTo begin
End If
Next i

'creating and writing array values into file
Open App.Path & "\name.txt" For Output As #1
For i = 0 To 4 Step 1
Print #1, "Information About Student"
Print #1, "---------------------------------"
Print #1, "Name : " & n(i)
Print #1, "Position in array : " & i
Print #1, "Holding rank : " & i + 1
Print #1, "---------------------------------"
Print #1, ""
Next i
Close #1

choudhuryshouvi
Posting Pro
553 posts since May 2007
Reputation Points: 30
Solved Threads: 49
 

Dim arr() As String

Private Sub Command1_Click()[INDENT]Static i As Integer[/INDENT][INDENT]ReDim Preserve arr(i)[/INDENT][INDENT]arr(i) = Me.Text1[/INDENT][INDENT]i = i + 1[/INDENT]End Sub

Private Sub Command2_Click()[INDENT]Dim i As Integer[/INDENT][INDENT]Me.Cls[/INDENT][INDENT]For i = 0 To UBound(arr)[INDENT]Me.Print arr(i)[/INDENT]Next i

[/INDENT]End Sub

'Hope it will help

AirtsuaLiera
Newbie Poster
6 posts since Jun 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You