Solved

vb.net form won't save value

Posted on 2006-07-18
3
193 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net Report Printing Issue 3 34
VB.NET (2008) - Refactoring Question 2 21
HTML - Color not displaying correctly in EMAIL. 6 38
Expression Evaluater 3 26
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 …
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

778 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