Variables


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Variables

  1. #1
    Join Date
    Mar 2005
    Posts
    96

    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

  2. #2
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    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

  3. #3
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    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

  4. #4
    Join Date
    Mar 2005
    Posts
    96
    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

  1. Use Session variables in Global.aspx
    By kero in forum ASP.NET
    Replies: 9
    Last Post: 09-19-2005, 09:54 AM
  2. Replies: 0
    Last Post: 06-15-2001, 12:27 PM
  3. Replies: 0
    Last Post: 06-14-2001, 07:16 PM
  4. Replies: 0
    Last Post: 04-26-2001, 11:01 PM
  5. How To Do It - Shared Class Variables Part II
    By Patrick Ireland in forum .NET
    Replies: 3
    Last Post: 04-26-2001, 03: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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center