输入框未声明

问题描述

输入框“未声明”。 不确定为什么会发生这种情况,我无法弄清楚。

   Private Sub Form1_Load(sender As Object,e As EventArgs) Handles MyBase.Load
        Do
            f = InputBox("Inputs","Enter The name Of the File.")
            If f = nothing Or f = "" Then
                MessageBox.Show("Ooops!! No file name entered.")
            Else
                Exit Do
            End If
        Loop
    End Sub

解决方法

您似乎没有初始化 f 变量:

  Private Sub Form1_Load(sender As Object,e As EventArgs) Handles MyBase.Load
    Do
        Dim f As String = InputBox("Inputs","Enter The name Of the File.")
        ...
    Loop
End Sub
,

您是否在构造函数中使用 InitializeComponent() 初始化表单?

除此之外,这个(更简洁的)代码对我来说按预期工作:

Private Sub Form1_Load(sender As Object,e As EventArgs) Handles MyBase.Load
    Do
        If Not String.IsNullOrEmpty(InputBox("Inputs","Enter the name of the file.")) Then Exit Do
        MessageBox.Show("Oops!! No file name entered.")
    Loop
End Sub

我会检查您的参考资料。并在任何情况下打开 Option Strict On 以突出显示任何类型/声明问题。