| | |
Field flashes when assigned value then disappears
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2008
Posts: 42
Reputation:
Solved Threads: 1
Okay, someone explain this one. I retrieve the environment variable USERNAME and assign it to a string variable. I can even show it in a MSGBOX and it shows "Owner". In my code I want to assign the value to a text box when it gets focus. It does it, but it flashes blue and then disappears and the text box appears blank, but if I save the record and go back to it? The value is there.
Help?
Help?
VB.NET Syntax (Toggle Plain Text)
Dim strUserName As String strUserName = Environment.GetEnvironmentVariable("USERNAME") MsgBox(strUserName) LogInNameTextBox.Text = Convert.ToString(strUserName)
You didn't post the actual code you're using, right?
You're probably doing something like this
Change it to
and remove Convert.ToString(). You're converting a string to a string, no need to do that.
You're probably doing something like this
VB.NET Syntax (Toggle Plain Text)
Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus ' Dim strUserName As String strUserName = Environment.GetEnvironmentVariable("USERNAME") TextBox1.Text = Convert.ToString(strUserName) End Sub
VB.NET Syntax (Toggle Plain Text)
Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus ' Dim strUserName As String strUserName = Environment.GetEnvironmentVariable("USERNAME") TextBox1.Text = strUserName TextBox1.SelectionStart = 0 TextBox1.SelectionLength = 0 End Sub
Teme64 @ Windows Developer Blog
Ok. How's
Environment.GetEnvironmentVariable("USERNAME") related to the db table? Do you read some value to the textbox, then change it in GotFocus and save back to DB? Teme64 @ Windows Developer Blog
•
•
Join Date: Dec 2008
Posts: 27
Reputation:
Solved Threads: 2
I've had a similar problem and it ended up a variable scope situation. Try this as a test...
Create a global variable (I'm note sure where would be appropriate in your code, if the is a generic Form put it in):
Then, in the sub where you retrieve USERNAME, instead of using a pointer to it (assigning it to a string), make a copy of it in the Public StringBuilder:
Then use userName.ToString when you want this data. There are some problems with re-using StringBuilder Class as there is no Clear method (it is easy to write your own). If this solves the problem let us know!
Create a global variable (I'm note sure where would be appropriate in your code, if the is a generic Form put it in):
Public Class Form1
Public userName As New StringBuilderThen, in the sub where you retrieve USERNAME, instead of using a pointer to it (assigning it to a string), make a copy of it in the Public StringBuilder:
userName = userName.Append(Environment.GetEnvironmentVariable("USERNAME")) Then use userName.ToString when you want this data. There are some problems with re-using StringBuilder Class as there is no Clear method (it is easy to write your own). If this solves the problem let us know!
-Ed
MS Vista Ultimate 64-bit; Visual Studio 2008 & 2010 beta; Visual Basic; Visual C++
Asus P5E3 Deluxe w/ Intel E6850, 8 GB OCZ DDR3 PC3-12800, SAPPHIRE HD3870 GPU
MS Vista Ultimate 64-bit; Visual Studio 2008 & 2010 beta; Visual Basic; Visual C++
Asus P5E3 Deluxe w/ Intel E6850, 8 GB OCZ DDR3 PC3-12800, SAPPHIRE HD3870 GPU
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: How to move a SQL Server Database from One Server to another server
- Next Thread: Insert Image + ListView Subitem
| Thread Tools | Search this Thread |
.net .net2005 30minutes 2005 2008 access account arithmetic array basic binary bing button buttons c# center check code combobox component connectionstring convert crystalreport data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dropdownlist excel file-dialog folder ftp generatetags google gridview hardcopy image images inline insert intel internet listview mobile monitor ms net networking output passingparameters peertopeervideostreaming picturebox picturebox1 plugin port print printing problem problemwithinstallation project reports" save savedialog searchbox searchvb.net select serial server soap sql table tcp text textbox timer toolbox trim update updown user usercontrol vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web wpf





