Jump to content

How can find in a file (C S V) with VBA?


Recommended Posts

Posted

I have one big rectangle and a lots of little rectangle.

 

I want to find in .csv file, those one little rectangles filenames, which to be in the Big rectangle (Lower Left point -> Upper right point coordinates Range).

 

exapmle:

 

Big rectangle:

 

lower left point: 848235.6561,446578.4652

upper right point: 849267.9715,447056.4045

 

 

CSV file:

 

columns:

1. filename of little rectangle

2. little rectangle lower left point X coord

3. little rectangle lower left point Y coord

4. little rectangle lower right point X coord

5. little rectangle lower right point Y coord

6. little rectangle upper right point X coord

7. little rectangle upper right point Y coord

8. little rectangle upper left point X coord

9. little rectangle upper left point Y coord

 

file1;848375.0000;446750.0000;848750.0000;446750.0000;848750.0000;447000.0000;848375.0000;447000.0000;

file2;848375.0000;446500.0000;848750.0000;446500.0000;848750.0000;446750.0000;848375.0000;446750.0000;

file3;848750.0000;447000.0000;849125.0000;447000.0000;849125.0000;447250.0000;848750.0000;447250.0000;

file4;848375.0000;446250.0000;848750.0000;446250.0000;848750.0000;446500.0000;848375.0000;446500.0000;

file5;848750.0000;446500.0000;849125.0000;446500.0000;849125.0000;446750.0000;848750.0000;446750.0000;

file6;848750.0000;446250.0000;849125.0000;446250.0000;849125.0000;446500.0000;848750.0000;446500.0000;

etc....

 

Can somebody help me?

Posted

There appears to be several aspects to this task: Which are you investigating?

 

If the question is about retrieving the information contained within the CVS then look into the “FileSystemObject”. It can be used to open the file and read it line by line.

 

Another aspect to the task would be parsing each line of text to sort individual elements. The VBA functions InStr, Split, Trim, etc. should help.

 

A remaining task would be determining if the smaller is contained within the larger. The important information here, as with the large rectangle, is the lower left and upper right. So if:

 

If smallLL(0) > largeLL(0) And _

smallLL(1) > largeLL(1) And _

smallUR(0)

smallUR(1)

 

small contained within large.

Posted
There appears to be several aspects to this task: Which are you investigating?

 

If the question is about retrieving the information contained within the CVS then look into the “FileSystemObject”. It can be used to open the file and read it line by line.

 

Another aspect to the task would be parsing each line of text to sort individual elements. The VBA functions InStr, Split, Trim, etc. should help.

 

A remaining task would be determining if the smaller is contained within the larger. The important information here, as with the large rectangle, is the lower left and upper right. So if:

 

If smallLL(0) > largeLL(0) And _

smallLL(1) > largeLL(1) And _

smallUR(0)

smallUR(1)

 

small contained within large.

 

Thx, IF condition is good.

 

Could You tell me some exapmles about my CSV problem?

Posted
What CSV problem is that exactly?

 

This is the CSV file:

 

Filename; smallLL(0); smallLL(1); smallUR(0); smallUR(1);

 

file1;848375.0000;446750.0000;848750.0000;447000.0000;

file2;848375.0000;446500.0000;848750.0000;446750.0000;

file3;848750.0000;447000.0000;849125.0000;447250.0000;

file4;848375.0000;446250.0000;848750.0000;446500.0000;

file5;848750.0000;446500.0000;849125.0000;446750.0000;

file6;848750.0000;446250.0000;849125.0000;446500.0000;

...

...

 

I want to read smallLL(0); smallLL(1); smallUR(0); and smallUR(1) from CSV file.

 

 

AND:

 

If smallLL(0) > largeLL(0) And _

smallLL(1) > largeLL(1) And _

smallUR(0)

smallUR(1)

 

THEN:

 

I want to get those one filenames (1st column) from csv, where on the IF condition is true.

 

That is the question.

Posted

Problem is done'

 

   file_name = "D:\items.csv"

   fnum = FreeFile
   Open file_name For Input As fnum
   whole_file = Input$(LOF(fnum), #fnum)
   Close fnum
   lines = Split(whole_file, vbCrLf)
   num_rows = UBound(lines) - 1

   For R = 0 To num_rows
            one_line = Split(lines(R), ";")
                         
            If one_line(1) > largeLL(0) And one_line(2) > largeLL(1) And one_line(3) < largeUR(0) And one_line(4) < largeUR(1) Then
           Msgbox one_line(0)       
           Else
     
           End If
   Next R

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...