Solved

vb.net form won't save value

Posted on 2006-07-18
3
189 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

763 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

14 Experts available now in Live!

Get 1:1 Help Now