用于将.txt的选定字段解析为新表的代码 [英] Code to parse out selected fields of .txt to new table

查看:83
本文介绍了用于将.txt的选定字段解析为新表的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文 -

我有一个逗号分隔的文本文件(.txt),每个文本字段都包含在??中。它不包含列标题。


我需要导入300行中的50行,因此使用代码而不是链接或导入(通过获取外部数据),因为它超过了255+限制。我正在Access 2007中建立一个关闭此文件的数据库。


我有一个表格,显示文本文件中的每个字段编号和字段名称。我添加了一个Y / N框,其中我标记了要导入的字段,并构建了一个查询以仅显示那些字段(QRY_IMPORT)。列[FieldID]是位置,[FieldName]是名称。有50条记录,所以我需要[FieldID] = 1,2,61,115,154,155,166,167等?


我想在将来允许灵活添加字段这就是为什么我是计划每次建立一个新表格,选择[FieldName]作为列标题。


问题 -

最好的方法是什么?


第一步,我认为是在QRY_IMPORT的[FieldName]中选择字段来构建一个新表


第二步,将解析每一行,为它所在的字段创建一个计数,查看该计数是否与我正在寻找的字段之一匹配,然后将其写入表中。我编写了使用.MoveNext遍历查询的每一行的过程,并且可以查看查询中的50条记录中的每条记录,然后遍历代码直到它到达该字段,将该字段写入表中,然后移至查询中的下一行等,但它必须循环遍历50个字段或查询和可能有4000行的文本。


我会很感激任何指针,任何详细程度的例子,如何做到这一点(专业,有效)。如果答案涉及数组,我从来没有使用它们,也不知道它们是如何工作的(是时候我学习了吗?):)

Context-
I have a text file (.txt) that is comma delimited and has each text field surrounded in ??. It does not contain column headers.

I need to import 50 of the 300 rows so am using code instead of linking or importing (via ''get external data'') since it exceeds the 255+ limit. I am building a database in Access 2007 off this file.

I have a table that shows every field number and field name in the text file. I added a Y/N box where I marked the fields I want to import and built a query to show only those fields (QRY_IMPORT). Column [FieldID] is the location and [FieldName] is the name. There are 50 records, so I need [FieldID] = 1,2,61,115,154,155,166,167, etc?

I would like to allow the flexibility to add fields in the future which is why I am planning on building a new table each time with the selected [FieldName] being the column headers.

Question-
What is the best way to go about this?

Step one, I would think is to build a new table with fields selected in the [FieldName] of QRY_IMPORT

Step two, would be to parse out each line, create a count for what field it?s on, see if that count matches one of the fields that I?m looking for and it so, write it to the table. I have written procedures that go though each line of a query using .MoveNext and could go through each of the 50 records in the query, then loop through the code until it gets to that field, write that field to a table, then move to the next line in the query, etc, but then it would have to cycle through 50 fields or query and text of potentially 4000 rows.

I would appreciate any pointers, examples in any level of detail for how this would be done (expertly, efficiently). If the answer involves arrays, I have never used them and don?t really know how they work (is it time I learn?) :)

推荐答案

它''你学习使用数组的时间。


由于它是用逗号分隔的,你可以读取该行,然后使用Split()函数来获取数组。然后,如果您需要第一列,则可以使用arrayVariable(0)访问该列。如果你需要第8列,那么arrayVariable(7)。等等。另外,您可以遍历包含所需列的数组或记录集,而不是手动编码。
It''s time you learned to use arrays.

Since it''s delimited by a comma, you can read the row, and then use the Split() function to get an array. Then, if you need the first column, you can access that using arrayVariable(0). If you need the 8th column, then arrayVariable(7). And so on. Plus, you can just loop through an array or recordset containing the columns you want instead of coding it out manually.


当您开始讨论数组时,我会迷路。我很难将(模糊的)概念付诸实践,以实现我想要完成的目标。我想我需要更多的手握。


为了练习我的解析,我从网上抓取了一些代码并用count和if / then语句更新它以随机拉出字段1和93.而不是使用变量在代码中(在本例中为1和93)我想在[QRY_IMPORT]中拉出所有的整数![FieldID]。这就是你在回答中所说的,但我不知道如何实现它。你可以帮我更新我的代码吗?

See, when you start talking about arrays I get lost. I''m having a hard time getting the (fuzzy to me) concept into practice for what I''m trying to accomplish. I think I need more hand holding.

To practice my parsing, I had grabbed some code from the web and updated it with a count and an if/then statement to randomly pull fields 1 and 93. Instead of having the variables in the code (in this case 1 and 93) I would want to pull all the intergers in [QRY_IMPORT]![FieldID]. That''s what you said in your response, but I don''t know how to make it happen. Could you please help me update my code?

展开 | 选择 | Wrap | 行号


好的,现在我有[FieldID]的内容]从QRY_IMPORT保存为动态数组。我仍然不知道如何使用我的新数组(arrFieldID)来查看我所在的文本字段是否存在于该数组中。因为我不知道阵列。 (但我正在学习)
OK, now I have the contents of [FieldID] from QRY_IMPORT saved as a dynamic array. I still don''t know how to use my new array (arrFieldID) to see if the text field I am on exists within that array. Because I don''t know arrays. (But I''m learning)


这篇关于用于将.txt的选定字段解析为新表的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆