First of all, I am far from experienced so if there are any obvious mistakes, it's because I don't know any better.
I have a text file in this format:
Code:
A B
1 356 234
2 275 597
3 365 674
4 286 375
5 256 752
6 674 465
On the form, I have a text box where a user can enter a number. How can I make it so that when a user enters 2 and clicks a button, it will store 275 as variable x and 597 as variable y?
I've got some code that I've been playing with, but I just can't put it together. I don't think it's even worth putting up because it doesn't really do anything. Here's part of it, the rest is just a mess that I don't understand.
Code:
Private Sub Command_Click()
Dim varCount As Integer
Dim varTemp As String
Open "C:\MyFile.txt" For Input As #1
Do Until EOF(1)
varCount = varCount + 1
Line Input #1, varTemp
Loop
Close #1
End Sub
I know I need to use the Split() function somewhere, and that the actual lines have to be stored in a array. I just can't figure out how to incorporate that. I would actually like something like jumping to a line in the text file or something because I think it would be quicker and easier. The text file will contain around 400 lines, but something about bad programming practice? The text file actually originated from Excel, but I figured it would be easier to just use a text file. If it isn't, then that would be even better. If someone could help me out, thanks.
Last edited by Wander; Dec 13th, 2004 at 09:14 PM.
to split the line, use arr=split(varTemp," ")
the arr(0) will be the number.
if you want an array for num, x, and y,
Code:
Dim arr()
Dim n(5)
Dim x(5)
Dim y(5)
varCount=0
Do Until EOF(1)
Line Input #1, varTemp
arr=split(varTemp," ")
arr(0) = n(varCount)
arr(1) = x(varCount)
arr(2) = y(varCount)
varCount = varCount + 1
Loop
...etc
then, you can get the second item by using the value - 1, or x(1)
you could make the arrays dynamic, by redim'ing them while you read them to be one bigger than the array is. to find out how big it is, use
size=Ubound(x)
it will give you the size or the array. then
redim preserve n(size) + 1
do it after you fill the current item.
where do you want to save the selected information?
Last edited by dglienna; Dec 13th, 2004 at 07:24 PM.
Would that be easier? I've never used them . There's actually more than 2 variables that I'm going to need to be displaying, more like 8, but I'm hoping if I can get 2 working, then it will be good. I'll look at this "listbox"
Do you mean just use a listbox to store the data and call it from there?
Last edited by Wander; Dec 13th, 2004 at 07:37 PM.
I think a listbox would work for my purposes until I can figure out the flexgrid. The only thing I need is to be able to call the data. Say I add an item on the list through .additem. How do I call that item back?
you have to loop through them one at a time. do you want to just find the item? there was some code that would do that for you automatically. search the forum for Sendmessage() by martinliss.
Right, I got the looping part. I'm actually still going to use the text files since that's where all the data is. I'm just going to format the text files so that there's only one column. When the form loads, I have a loop that goes through the file and adds each line to the listbox (so the index goes in that order, which is fine). I want to be able to recall that information without the user having to click anything on the listbox (it's invisible). I'm just using it for a storage place. I thought it was List1.Item(Index) but that doesn't seem to be working.
That works when the listbox is visible and a user clicks on a item on the listbox. I don't intend for it to be visible. Is there a way to simulate a click or just an internal command to access a certain item (index) on the listbox?
Hey, thanks a lot Tec-Nico. This should come in handy. It will take me a while to look at everything. I think there's a problem though. I'm not sure if I'm able to use the FlexGrid. I get errors trying to load the form.
From the error log
Line 34: Class MSFlexGridLib.MSFlexGrid of control gridShow was not a loaded control class.
Line 40: The property name _ExtentX in gridShow is invalid.
Line 41: The property name _ExtentY in gridShow is invalid.
Line 42: The property name _Version in gridShow is invalid.
David's code works even if the ListBox is not visible... You just have to change the "List1.ListIndex" to the number you would need.
Example:
Code:
Dim strLineTwo As String
strLineTwo = List1.List(1)
In the example we are getting the second line of the ListBox. Why do we use 1 instead of 2? Well, because the ListIndex begins from 0... So 0 = 1, 1 = 2, and so on.
We miss you, friend... Rest in Peace, we will take care of the rest of it.
[vbcode]
On Error Me.Fault = False
[/vbcode]
- Silence is the human way to share ignorance
Tec-Nico
You say you have the MSFlexGrid? Then you shouldn't have any problem at all...
Anyway... If it fails again then just remove the FlexGrid I named gridShow and add another FlexGrid with the name "gridShow" and that should do the trick.
(Just remember you must have it checked so it is loaded in the ToolBox)
We miss you, friend... Rest in Peace, we will take care of the rest of it.
[vbcode]
On Error Me.Fault = False
[/vbcode]
- Silence is the human way to share ignorance
Tec-Nico