【问题标题】:Read line from text and submit information?从文本中读取行并提交信息?
【发布时间】:2013-03-26 02:48:33
【问题描述】:

我想知道是否有可能有一个包含一堆单词的 .txt 文件,例如:

Gaming  
Programs  
Home  
Select  

并让这些单词通过此处的值一一运行:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

    If Not number_of_ticks > NumericUpDown1.Value Then
        number_of_ticks += 1
        If ((WebBrowser1.IsBusy)) Then
        Else
            If WebBrowser1.Url.ToString = "https://live.xbox.com/en-US/ChangeGamertag" Then


                WebBrowser1.Document.GetElementById("NewGamertag").SetAttribute("value", txtTurbo.Text)

                WebBrowser1.Document.GetElementById("claimIt").InvokeMember("Click")
            Else

                WebBrowser1.Navigate("https://live.xbox.com/en-US/ChangeGamertag")

            End If
        End If

    Else
        'number_of_ticks has exceed the maximum amount of allowed ticks
        Timer1.Enabled = False
        WebBrowser1.Refresh()

        number_of_ticks = 0
        Timer1.Enabled = True

    End If

End Sub

所以第一行的值是“Gaming”,而不是文本框的值 (txtTurbo.text)

   WebBrowser1.Document.GetElementById("NewGamertag").SetAttribute("value", txtTurbo.Text)

然后通过这个提交后:

   WebBrowser1.Navigate("https://live.xbox.com/en-US/ChangeGamertag") 

将值更改为“程序”,依此类推,直到它到达 .txt 文件中所有行的末尾。由于我从未使用过从 Visual Basic 读取 .txt 文件,我将如何处理。

【问题讨论】:

  • 这是客户端脚本吗?
  • 你的代码读起来很混乱

标签: vb.net click notepad


【解决方案1】:

要读取文本文件,您将需要此代码

 Imports System.IO
Imports System.Text
Public Class Form2

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim line As String

        ' Create new StreamReader instance.
        Dim reader As StreamReader = New StreamReader("c:\\temp\cid.txt")
        ' Read one line from file
        line = reader.ReadLine
        ' Write the line we read from "cid.txt"
        MessageBox.Show(line)
    End Sub
End Class

但是,为了逐行阅读,我必须再试一次,导致您的代码难以阅读。

更新

因为你的问题不清楚,所以我猜是这样的

Dim FILE_NAME As String = "path.txt"

Dim TextLine As String

If System.IO.File.Exists( path ) = True Then

Dim objReader As New System.IO.StreamReader(path)

Do While objReader.Peek() <> -1

TextLine = TextLine & objReader.ReadLine() & vbNewLine

Loop

txtturbo.Text = TextLine

Else

MsgBox("File Does Not Exist")

End If

下面改成你想要的

WebBrowser1.Navigate("https://live.xbox.com/en-US/" & txtturbo.text) 

【讨论】:

    猜你喜欢
    • 2013-04-06
    • 1970-01-01
    • 1970-01-01
    • 2018-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多