473,387 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Importing txt into an array

kadghar
1,295 Expert 1GB
Hi, what i need is to import a txt file or a text box with numeric values, separated by tabs, into an array.

I dont want to do it by searching chr(9) and chr(10) cause this will be slow for a big matix.

I want it to run under VBA 2002 since i need to share it in the office. I've found that is quite fast to copy the text and paste it into an excel worksheet, then asign the range into a Variants Array. This will take less than one second for huge matrixes.

Anyway I don like using the clipboard or using an array of variants when a singles' or a doubles' one would do.

Any suggestion will be apreciated.
Kad
Aug 23 '07 #1
4 1778
Killer42
8,435 Expert 8TB
The Split() function will easily chop up the lines at the tabs, but presumably that will produce a string array, and a 1D one, at that. Not sure how you'd go about getting it into your "matrix", which I assume is 2D.
Aug 24 '07 #2
kadghar
1,295 Expert 1GB
The Split() function will easily chop up the lines at the tabs, but presumably that will produce a string array, and a 1D one, at that. Not sure how you'd go about getting it into your "matrix", which I assume is 2D.
Actually it worked great. I used split twice, with chr(10) and then with chr(9). The only problem is that i still have strings, but nothing CDbl couldnt fix, It was something like:

Expand|Select|Wrap|Line Numbers
  1. Dim mTemp() As String
  2. Dim mEmi2() as String
  3. mTemp = Split(Controls(k).Text, Chr(10))
  4. For i = LBound(mTemp) To UBound(mTemp)
  5.     ReDim Preserve mEmi2(0 To i)
  6.     mEmi2(i) = Split(mTemp(i), Chr(9))
  7. Next
Thank you very much Killer
Aug 24 '07 #3
Killer42
8,435 Expert 8TB
Cool!

Just out of curiosity, what happens if you make mEmi2 Double instead of String? (Probably an error, but it's worth a try.)
Aug 25 '07 #4
kadghar
1,295 Expert 1GB
Cool!

Just out of curiosity, what happens if you make mEmi2 Double instead of String? (Probably an error, but it's worth a try.)
Mmm, actually that code didnt work in VBA, i had to change mEmi2 to Variant, i dont know why VBA works different for jagged arrays. You aren't even able to define them with

dim array()()

That's sad, but at least i get rid of the clipboard
Aug 25 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: J. Kenney | last post by:
Good Morning, Is there a way for a function called within an _imported_ library to call back to _calling_ python program to run a function? (Shown below) Also can you overload the print...
2
by: Michael Gooding | last post by:
I've been working on some coursework that requires the use of an excel spreadsheet and a CSV file to be read into an ASP page and worked with. What I have done is set up an array to store the...
7
by: nizar.jouini | last post by:
Hello. I have long text file whitch is formatted like this: nextrow4 asdf asdf
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
0
by: Ivan Lam | last post by:
Hi All, Thanks for reading my question. I am a newbie of VC .Net, and I am facing a problem about importing DLL. I have searched from the web and I download a simple sample. And the code...
5
by: BeruthialsCat | last post by:
First go with trying to import xml to a database and whilst i have managed to do what i want i find that the xml files we have here at work are gonna cause me problems. I have a function that...
4
toxicpaint
by: toxicpaint | last post by:
Hi there. I'm doing a job in a content management system and the controlling buggers censer anything after <script so, for example, if I want to import a js file and type <script...
1
by: rgtidwell | last post by:
I know this code is wrong, and I am paying the price now for focusing on Linear last semester during the first half of C++, but I am trying to figure this out. Can anyone help? I want to make sure:...
28
by: kkadakia | last post by:
I get a daily excel file for a entire month which I want to transfer into Access at the end of the month. So, there are around 20-25 excel files I get by the end of the month, and I would like to...
1
by: Rahul | last post by:
What's a good way of importing a csv text file of floats into a Numeric array? I tried the csv module and it seems to work well so long as I've ints. Does anyone have any suggestions / snippets...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.