-
Variables
I am not sure I can even do this! But i want to check with you guys before i decide for myself.
I am writing a program where the user loads some files, and the content of the file is loaded into variables. The problem is that when the program is done reading the first file the contents of the second file should be read into different variables. But the number of files loaded everytime you run the program could be different.
So say if the user loaded 2 files. I have:
Public Sub ReadFiles()
Dim a As Integer, i As Integer, b As Integer, j As Integer, k As Integer
Dim Ix1(75), Xm1(75), Ym1(75), Zm1(75), Ad1(75), Bd1(75), Cd1(75)
Dim Ix2(75), Xm2(75), Ym2(75), Zm2(75), Ad2(75), Bd2(75), Cd2(75)
b = FreeFile
j = 0
For i = 1 To FileNbr
Open NwFiles(i) For Input As b
Do While Not EOF(b)
j = j + 1
Input #b, Ix & i & (j), Xm & i & (j), Ym & i & (j), Zm & i & (j), Ad & i & (j), Bd & i & (j), Cd & i & (j)
Loop
Close
Next
Close b
End Sub
It gives me error at:
Input #b, Ix & i & (j), Xm & i & (j), Ym & i & (j), Zm & i & (j), Ad & i & (j), Bd & i & (j), Cd & i & (j)
How would i put the info in different variables depending on the file number? I hope I am making sense. Thanks!
~svn
-
The second parameter of the Input statement must be a list of variables, therefore "Ix & i & (j)" will not work. You can't put the name of a variable and use it as the variable itself...
What you have to do is create a multi-dimensional array (like dim iX(2,75) as ...), or put your arrays in a UDT and defines an array of those UDT, or put them in a class and create a collection (or array) of them. It really depends on the application.
For example, using a multi-dimensional array will go like:
Input #b, Ix(i,j), Xm(i,j), Ym(i,j), Zm(i,j), Ad(i,j), Bd(i,j), Cd(i,j)
Marco
"There are two ways to write error-free programs. Only the third one works."
Unknown
-
I forgot: you have to set j=0 before the j loop, not before the i loop. and close the b file inside the i loop
Marco
"There are two ways to write error-free programs. Only the third one works."
Unknown
-
Thank you very much! I dont know why i didnt think of multi-dimensional array myself. I will blame it on getting old AND long day...
Similar Threads
-
Replies: 9
Last Post: 09-19-2005, 08:54 AM
-
By Paul Clapham in forum Java
Replies: 0
Last Post: 06-15-2001, 11:27 AM
-
Replies: 0
Last Post: 06-14-2001, 06:16 PM
-
By Patrick Ireland in forum .NET
Replies: 0
Last Post: 04-26-2001, 10:01 PM
-
By Patrick Ireland in forum .NET
Replies: 3
Last Post: 04-26-2001, 02:50 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks