Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

vb.net form won't save value

Posted on 2006-07-18
3
Medium Priority
?
198 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Accepted Solution

by:
mydasx earned 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

705 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