简体   繁体   English

Visual Basic button.click 如何返回到 If

[英]Visual Basic button.click how to return to If

I have a problem, I want the program after pressing the button to check if there are files in different locations (I used if), and if this file not exists, I would download them (else) and that after downloading I would go back to if and continue the rest of the code.我有问题,我希望程序在按下按钮后检查不同位置是否有文件(我使用 if),如果此文件不存在,我会下载它们(否则),下载后我会返回if 并继续其余的代码。

If ComboBox2.SelectedItem = "1.12.2 Release" Then
    If My.Computer.FileSystem.DirectoryExists(natives & "\1.12.2\natives") Then
        launch = ("START CODE")
        Shell("cmd.exe @echo off /c" & launch)
        Me.Close()
    Else
        My.Computer.Network.DownloadFile("MY URL/natives.zip", natives & "\1.12.2\natives.zip")
        System.IO.Compression.ZipFile.ExtractToDirectory(natives & "\1.12.2\natives.zip", natives & "\1.12.2")
        My.Computer.FileSystem.DeleteFile(natives & "\1.12.2\natives.zip")
        Return

I want to add much more to this code, and I want first do this and I stayed here.我想在这段代码中添加更多内容,我想先做这件事,然后就留在这里了。 In code I can see just one of maybe 5-7 folders to check在代码中,我只能看到 5-7 个文件夹中的一个进行检查

Create following logic创建以下逻辑

sub Main()
    if not CheckFolders() then
        if not DownloadFolders() then
            MessageBox.Show("Can't start program")
            Return
        end if
    end if

    ' Start your program here
end sub


function CheckFolders() as boolean
    ' check your folders here
end function

function DownloadFolders() as boolean
    ' download your folders here
end function

This way you separate logic of checking for files/folders from downloading and startup logic.通过这种方式,您可以将检查文件/文件夹的逻辑与下载和启动逻辑分开。 And you can manipulate each separate component the way you want您可以按照自己的方式操作每个单独的组件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM