VB中的记事本数据库 [英] Notepad database in VB

查看:27
本文介绍了VB中的记事本数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 VB.net 完全陌生,只学习了几周我正在做一个项目,我需要使用记事本作为数据库制作 EPOS 系统.我能够使按钮的值出现在列表框中,但是我有许多按钮都具有不同的值,但是每次按下不同的按钮时只会出现文本框中的第一个值.例如当 Heineken 按钮按下时显示Heineken €5.00"当按下吉尼斯按钮时显示Heineken €5.00"

I am completely new to VB.net and have only been learning in for a few weeks I am doing a project where i need to make an EPOS systems using notepad as a data base. I am able to make the values of the buttons appear in the list box, however I have numerous buttons all with different values but only the first value in the text box is appearing each time a different button is pressed. E.G When Heineken button pressed "Heineken €5.00" is displayed when Guiness button pressed "Heineken €5.00" is displayed

非常感谢任何帮助!

导入 System.IO公开课表1

Imports System.IO Public Class Form1

Private Sub btnHeineken_Click(sender As Object, e As EventArgs) Handles btnHeineken.Click
    Dim sr As IO.StreamReader = IO.File.OpenText("DATABASE.txt")
    'File DATABASE.TXT is the the debug folder

    Dim name As String

    Dim stock, price As Double
    name = sr.ReadLine

    stock = CDbl(sr.ReadLine)

    price = CDbl(sr.ReadLine)

    lstBox.Items.Add(name & "" & FormatCurrency(price))
    name = sr.ReadLine



End Sub

Private Sub BtnGuiness_Click(sender As Object, e As EventArgs) Handles BtnGuiness.Click
    Dim sr As IO.StreamReader = IO.File.OpenText("DATABASE.txt")
    'File DATABASE.TXT is the the debug folder

    Dim name As String

    Dim stock, price As Double
    name = sr.ReadLine

    stock = CDbl(sr.ReadLine)

    price = CDbl(sr.ReadLine)

    lstBox.Items.Add(name & "" & FormatCurrency(price))
    name = sr.ReadLine
End Sub

数据库.txt

Heineken
5.00
20
Guiness
4.50
50
Bulmers
5.00
25

推荐答案

您的两种方法具有完全相同的代码.因此,它们完全相同:它们显示文本文件中第一个条目的内容.

Both your methods have exactly the same code. Thus, they do exactly the same thing: They show the contents of the first entry in your text file.

如果你想让你的方法做不同的事情,你需要在它们中放入不同的代码.

If you want your methods to do different things, you need to put different code in them.

不幸的是,在您的方法中放入任意代码不会使它们执行您想要的操作.看起来你已经发现了.所以下一步是采取更结构化的方法:

Unfortunately, putting arbitrary code in your methods won't make them do what you want. It looks like you already discovered that. So the next step is to take a more structured approach:

  1. 决定你的按钮点击应该做什么.看起来您已经这样做了:您想在单击Guiness"按钮时显示Guiness €4.50".

  1. Decide what your button click should do. It looks like you already did that: You want to display "Guiness €4.50" when the "Guiness" button is clicked.

接下来,考虑如何您的程序可以做到这一点.显然,这就是你被卡住的地方.您有一个包含条目列表的文本文件,如何获得您想要的条目?

Next, think about how your program can do that. Apparently, that's where you are stuck. You have a text file with a list of entries, how do you get the one you want?

在代码中翻译第 2 步的结果(算法").

Translate the result of step 2 (the "algorithm") in code.

您尝试在第 2 步之前执行第 3 步.这不起作用,这就是您的代码不起作用的原因.

You tried to do step 3 before step 2. That won't work, and that's the reason why your code doesn't work.

我建议您认真考虑第 2 步(如何在文本文件中查找数据?如果我将文件打印在我面前并亲自搜索数据,我该怎么做?),想出一个算法,然后返回这里并提出一个新问题,如果您需要帮助将其转换为代码.

I suggest that you think really hard about step 2 (How do I find data in a text file? How would I do it if I had the file printed out in front of me and were searching for the data personally?), come up with an algorithm and then return here and ask a new question if you need help translating it to code.

这篇关于VB中的记事本数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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