Solved

vb.net form won't save value

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access Schema 6 58
ASP.NET Complete Life Cycle for all the controls 2 46
Whice version VisualStudio for new Dev Laptop? 10 43
VB Catch Statement in Event Viewer. 2 20
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 …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

752 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