Solved

vb.net form won't save value

Posted on 2006-07-18
3
190 Views
Last Modified: 2010-04-23
I have a form that I open up to get a file name to save to.
Pretty much, it is just a text box with a few buttons.

On the form, I have a variable

    Public saveName As String

I have a save button which puts the textbox.text into the variable above

    Private Sub BtnSaveAs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSaveAs.Click
        If Trim(txtSaveAs.Text) = "" Then
            MsgBox("You must enter a name first")
            txtSaveAs.Focus()
            Exit Sub
        Else
            saveName = txtSaveAs.Text
        End If

        canceled = False
        Me.Visible = False
        'Me.Hide()

    End Sub

The main form that calls the second form, then asks the value of the textbox.

    Public Function getText() As String
        getText = Trim(saveName)
    End Function

For some reason, when the main function calls getText, the value of saveName is nothing.
I got rid of the me.hide because I though that was the reason.
0
Comment
Question by:jackjohnson44
3 Comments
 
LVL 5

Accepted Solution

by:
mydasx earned 500 total points
ID: 17134379
after you instantiate form2, do a form2.showdialog() instead of show.  Make sure you set up your settings in form 2 to be a dialog and set your button press to be the OK button in your dialog.
0
 
LVL 34

Expert Comment

by:Sancler
ID: 17136694
What version of VB.NET?  2002/3 or 2005?  In the former, you will have to reference the specific instance of Form2, which would have to have been declared with New, to get any value from it.  In the latter, you can use a generic reference to the default instance of the form - which would not have been declared with New.  So how is the second form declared/called?  And how is the first form referencing it when it seeks to get the value from it?

Roger
0
 
LVL 3

Expert Comment

by:HouseMusic
ID: 17138167
To make the above comments more clear.

You issue is that you are getting multiple instances of your form for each variable you are using to reference the form.
So the second time you are dealing with a new instance of the form, which does not have the value that was set in your first instance.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now