• 0

[VB] Saving a Listbox as an Array


Question

Basically, I'm trying to read the information shown in a listbox into an array, which is then printed into a text file.

Private Sub cmd_input_Click()


arrayhold(0) = InputBox("Enter a value")
arrayhold(1) = InputBox("Enter a value")
arrayhold(2) = InputBox("Enter a value")
arrayhold(3) = InputBox("Enter a value")
arrayhold(4) = InputBox("Enter a value")

End Sub

Private Sub cmd_save_Click()

Dim i As Integer

Open "F:\Event Programming\Assignment 2\Task 3\array.dat" For Output As #1
For i = 0 To 4
	Write #1, arrayhold(i)
Next i

Close #1

End Sub

See, where the InputBoxes are, I'm looking to enter the listbox's information, but is there a specific way to define a row in a listbox? Say I have 10 rows in a listbox;

arrayhold(0) = Listbox Row 1
arrayhold(1) = Listbox Row 2
arrayhold(2) = 
arrayhold(3) = 
arrayhold(4) = 
arrayhold(5) = 
arrayhold(6) =
arrayhold(7) = 
arrayhold(8) = 
arrayhold(9) =

I suck at explaining, but you see what I mean. Any help is appreciated.

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0
Basically, I'm trying to read the information shown in a listbox into an array, which is then printed into a text file.

Private Sub cmd_input_Click()


arrayhold(0) = InputBox("Enter a value")
arrayhold(1) = InputBox("Enter a value")
arrayhold(2) = InputBox("Enter a value")
arrayhold(3) = InputBox("Enter a value")
arrayhold(4) = InputBox("Enter a value")

End Sub

Private Sub cmd_save_Click()

Dim i As Integer

Open "F:\Event Programming\Assignment 2\Task 3\array.dat" For Output As #1
For i = 0 To 4
	Write #1, arrayhold(i)
Next i

Close #1

End Sub

See, where the InputBoxes are, I'm looking to enter the listbox's information, but is there a specific way to define a row in a listbox? Say I have 10 rows in a listbox;

arrayhold(0) = Listbox Row 1
arrayhold(1) = Listbox Row 2
arrayhold(2) = 
arrayhold(3) = 
arrayhold(4) = 
arrayhold(5) = 
arrayhold(6) =
arrayhold(7) = 
arrayhold(8) = 
arrayhold(9) =

I suck at explaining, but you see what I mean. Any help is appreciated.

Well doesnt get you:blink: from what u tried to explain us....

But let me sum up....

1. You are inputting into the ten arrays(i m assuming) from the same number of inputbox()

2. And you are looking into inputting this each array values into the textpad

Now getting straight..... u need to put this information stored into the listbox

I think you can directly place your information...from inputbox to listbox

using

listbox1.items.add(InputBox("Enter a value");

Then add this data in listbox into textpad

Dim file as new System.IO.StreamReader("c:\test.txt")
Dim strFile as string
while file.Peek() >= 0 do
  strFile = file.ReadLine()
  combo.Items.Add(strFile)
end while

Hope it helps

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.