如何在 VB.NET 中读取用户输入的数组?

发布于 2024-10-17 05:10:46 字数 504 浏览 8 评论 0原文

好的,所以我尝试使用 Visual Basic 制作一个程序,该程序将允许用户将网页链接(例如 www.google.ca)添加到程序中的列表中,并使其成为这样一旦程序关闭,它们就不会消失。

为了了解更多细节,我有一个文本框、一个列表视图和一个按钮。当用户在文本框中键入链接时,需要将其放入数组中(称为“addlink”),然后当用户按下按钮时,链接将作为对象键入到列表视图中。

然后,如果用户单击列表视图中的该对象,它将使用 WebBrowser 命令打开浏览器。单击按钮后如何将文本框中的文本设置为数组?

该程序与大多数 Internet 浏览器的书签功能非常相似。 :D

规格:

  • 操作系统:Windows 7 Ultimate Edition
  • 软件:Microsoft Visual Basic 2010 Express
  • Visual Basic 体验:一般

OK, so I am trying to make a program using Visual Basic that will allow the user to add links to web pages (such as www.google.ca) to a list in the program and make it so that they do not dissapear once the program is closed.

So to get into more detail, I have a text box, a listview, and a button. When the user types a link into the text box it needs to be put into an array (called "addlink") and then when the user presses the button, the link is typed into the listview as an object.

Then if the user clicks on that object in the listview, it will open up the browser using the WebBrowser command. How do I set the text in the textbox to an array once the button is clicked?

This program greatly resembles most Internet browser's bookmarking feature. :D

Specifications:

  • OS: Windows 7 Ultimate Edition
  • Software: Microsoft Visual Basic 2010 Express
  • Experience with Visual Basic: Average

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

向日葵 2024-10-24 05:10:46

回答有关添加到数组的问题。你可以做这样的事情。

Dim addlink() As String

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If IsNothing(addlink) Then
        ReDim addlink(0)
    Else
        ReDim Preserve addlink(addlink.Count)
    End If

    addlink(UBound(addlink)) = TextBox1.Text
    TextBox1.Text = Nothing
End Sub  

或者使用像 @Cody Gray 建议的集合

Dim addlink As New List(Of String)

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    addlink.Add(TextBox1.Text)
    TextBox1.Text = Nothing
End Sub

To answer your question about adding to an array. You could do something like this.

Dim addlink() As String

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If IsNothing(addlink) Then
        ReDim addlink(0)
    Else
        ReDim Preserve addlink(addlink.Count)
    End If

    addlink(UBound(addlink)) = TextBox1.Text
    TextBox1.Text = Nothing
End Sub  

Or to use a collection like @Cody Gray suggested

Dim addlink As New List(Of String)

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    addlink.Add(TextBox1.Text)
    TextBox1.Text = Nothing
End Sub
倚栏听风 2024-10-24 05:10:46

编辑:我已经删除了我的答案,这是特定于VB6的,但留下了我的答案中提出建议的部分:

您将需要一个编辑书签和删除书签功能。

您可以使文本框成为多行,并允许用户一次输入多个链接......或者您可以一次输入一个。唯一的区别是,每次出现 chr(13) & 时,您都必须剪切文本。 chr(10),使用 Mid(进行实际剪切)和 inStr(确定剪切位置)。

逻辑上将书签的“标题”与 URL 分开将是理想的。例如,您可能有 3 个指向不同 Cook.com 食谱的链接(我们会说鸡肉、羊肉和炒菜),但 URL 可能类似于 http://www.cook.com/recipes/ 2389047291,如果用户想要特定的食谱,它并不能准确告知他们想要哪个链接。使用两个文本框,您可以允许用户在逻辑上分隔标题和 URL,例如列表 1:Cook.com Stir Fry... 列表 2:http://www.cook.com/recipes/2389047291(或者,您可以只需完全隐藏 URL,仅向用户显示页面标题。)

edit: I have removed my answer, which was specific to VB6, but left the portion of my answer that made suggestions:

You will need an edit bookmark and remove bookmark feature.

You could make the textbox multi-line and allow the user to input multiple links at once... or you can do one at a time. The only difference is that you would have to cut the text up every time there was a chr(13) & chr(10), using Mid (to do the actually cutting) and inStr (to figure out where to cut.)

Logically separating the "titles" of the bookmarks from the URLs would be ideal. For example, you might have 3 links to different cook.com recipes (we'll say chicken, lamb, and stir fry), but the URLs might resemble something like http://www.cook.com/recipes/2389047291, which doesn't exactly inform the user which link they want if they want a specific recipe. Using two text boxes, you could allow the user to logical separate the titles and the URL, e.g. List1: Cook.com Stir Fry... List2: http://www.cook.com/recipes/2389047291 (Alternatively, you could just hide the URL altogether, displaying only the page titles to the user.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文