Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
681 views
in Technique[技术] by (71.8m points)

vb.net - How to close parent form and open child?

Hey guys before I was just hiding the parent form, but now when I try to read from the parent file it says it can't because it's already running in a process. I followed some tutorial and it said to go to the project properties and have the application stop running when all the forms are closed.

But now since I did that it says the directory can't be found probably because I am reading the input from the parent form. Anyways here is my code

Dim writeFile1 As StreamWriter = New StreamWriter(File.OpenWrite("C:UsersNickDocumentsVisual Studio 2010ProjectsLoginFixedAccounts" + frmLogin.txtUser.Text))

How should I go about doing this?

Edit:

    Private Sub btnHunter_Click(sender As System.Object, e As System.EventArgs) Handles btnHunter.Click
    selection = "Hunter"
    writeData.classSelection()
End Sub

This is what I have when the button is clicked.

Here is the classSelection sub:

    Public Sub classSelection()
    If frmClass.selection = "Hunter" Then
        writeFile1.WriteLine(frmClass.selection)
    End If
    If frmClass.selection = "Gatherer" Then
        writeFile1.WriteLine(frmClass.selection)
    End If
    If frmClass.selection = "Farmer" Then
        writeFile1.WriteLine(frmClass.selection)
    End If
    writeFile1.Close()
End Sub

The error points to this line:

If frmClass.selection = "Hunter" Then

Saying part of the file path cannot be found.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you want to read input textbox in closed parent form, you have to declare public var

Make a new module in your project .. and add this

public sLogin as String

And before you hide or close frmLogin .. add this

sLogin =  txtUser.Text

So, you could change your code with

Dim writeFile1 As StreamWriter = New StreamWriter(File.OpenWrite("C:UsersNickDocumentsVisual Studio 2010ProjectsLoginFixedAccounts" & sLogin))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...