Variables in Different Forms

I have a variable that's declared as a result of a dialog. This variable has a specific value after the dialog, but then I need to refer to that variable from another form. How can I do that

My.Computer.FileSystem.WriteAllText("textfile1.txt", variable, False)

That is the code in which I refer to a variable called variable. Variable is declared when a guy types in soemthing in a text box and presses okay in another form. How can I use the variable in the above code without changing its value

Another problem that I have is here:

        Dim variable As String = My.Computer.FileSystem.ReadAllText("TextFile1.txt")
        WebBrowser1.Navigate(variable)

That is where I declare the variable. This is located on form1 load, and form1 is the inital page of my application, so when the program opens it SHOULD go to the URL variable..

but it DOESNT...

can anyone help




Answer this question

Variables in Different Forms

  • Humpty

    Although not neccesarily the most efficient means, but definatley the easiest in VB is to declare a mdule level variable which by default has a global scope throughout the application life time:

    Module MyModule

    Public MyGlobalVariable as String= My.Computer.FileSystem.ReadAllText("TextFile1.txt")

    End Module

    Now as far as navigating to the site...you must make sure it is a valid url



  • Liston

    Well thats not really necessary because if you enter a invalid URl its your problem, no page will load...


  • Variables in Different Forms