信息检索帮助

编程入门 行业动态 更新时间:2024-10-12 12:22:33
本文介绍了信息检索帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试制作一个小程序来对我拥有的一些库存进行分类.我需要程序执行的操作是能够基于扫描的条形码返回信息.我正在使用条形码阅读器,并且正在想将数据输入到顺序 文件,但是我在解决如何获取特定信息方面遇到困难. 例如,我的顺序文件可能看起来像这样

I am trying to make a small program to catalog some inventory I have. What I need the program to do is to be able to return information based off of a scanned in barcode. I have the bar code reader working, and am amble to input the data to a sequential file, but I am having trouble working out how to get back the specific information. For example, my sequential file might look something like this

(条形码),书名,作者,页面,价格

(BarCode),BookName,Author,Pages,Price

(条形码),书名,作者,页面,价格

(BarCode),BookName,Author,Pages,Price

(条形码),书名,作者,页面,价格

(BarCode),BookName,Author,Pages,Price

以此类推... 我可以毫无问题地解析文件,并使用以下代码进行设置:

and so on... I can parse through the file no problem, and get things set up using the following code:

Dim query = From data In IO.File.ReadAllLines("[FileLocationHere]") Let barcode As String = data.Split(",")(0) Let title As Integer = CInt(data.Split(",")(1)) Let author As Integer = CInt(data.Split(",")(2)) Let pages As String = data.Split(",")(3) Let price As Integer = CInt(data.Split(",")(4)) Select barcode & "," & title & "," & author & "," & pages & "," & price

然后使用类似Textbox.text(query(i)),我是行号.

Then use something like Textbox.text(query(i)), I being the line number.

我想不出来的是如何按文件的单个元素进行搜索并仅返回该行.

What I cant figure out is how to search by a single element of the file and return only that line.

谢谢.

推荐答案

如果文件具有多个匹配元素(例如Price或Pages甚至Author),该怎么办?

What if the file has more than one matching element like Price or Pages or even Author?

无论如何,您都应该能够使用如何:从Visual Basic中读取逗号分隔的文本文件.

Anyhow you should be able to useHow to: Read From Comma-Delimited Text Files in Visual Basic.

以下代码来自链接.与其显示MessageBox,不如使用If语句查找"currentfield"是否存在.包含您要查找的内容?

The below code is from link. Rather than showing a MessageBox perhaps use an If Statement to find out if the"currentfield" contains what you want to find?

或者,如果您仅按列搜索,那么我怀疑文件的"currentRow"将包含5个索引,尽管我没有尝试过.因此,也许使用If语句"If currentRow(1)= TextBox1.Text Then".并让整行 搜索"BookName";我认为它在索引1处.

Or if you are searching by column only then I suspect "currentRow", for your file, would contain5 indexes although I haven't tried that. So perhaps use an If statement "If currentRow(1) = TextBox1.Text Then" and get entire row doing search for "BookName" which would be at index 1 I figure.

但是对于Author和其他人,您可能会获得多个结果,因此也许您希望将所有结果显示在某种类型的控件中.

But for Author and other you could get multiple results so perhaps you would want to display all the results in a control of some type.

另一方面,不断从磁盘读取整个文件非常耗时.也许将整个文件加载到DataTable中,然后遍历DataTable以获取结果.由于DataTable支持带有列的行,因此您可以根据哪一列进行搜索 您要检索的信息在其中.

On the other hand constantly reading an entire file from disk is time consuming. Perhaps load the entire file into a DataTable and iterate through a DataTable to get results. As a DataTable supports rows with columns and you could search based on which column the information you want to retrieve is in.

我想条形码将是一个数字序列?

I suppose BarCode would be a sequence of digits?

Using MyReader As New Microsoft.VisualBasic. FileIO.TextFieldParser( "C:\TestFolder\test.txt") MyReader.TextFieldType = FileIO.FieldType.Delimited MyReader.SetDelimiters(",") Dim currentRow As String() While Not MyReader.EndOfData Try currentRow = MyReader.ReadFields() Dim currentField As String For Each currentField In currentRow MsgBox(currentField) Next Catch ex As Microsoft.VisualBasic. FileIO.MalformedLineException MsgBox("Line " & ex.Message & "is not valid and will be skipped.") End Try End While End Using

更多推荐

信息检索帮助

本文发布于:2023-11-06 08:26:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563186.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:信息检索

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!