| | |
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 |
"crystal .net .net2005 2008 access add advanced application array assignment basic beginner box button buttons center click code combo convert cpu data database datagrid datagridview designer dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists firewall forms html image images isnumericfuntioncall listview login map math memory mobile module msaccess mssqlbackend mysql navigate net number opacity open pan pdf picturebox picturebox2 port print printpreview record regex reports" reuse right-to-left save savedialog search serial socket sorting sql sqldatbase sqlserver storedprocedure string temp textbox timer txttoxmlconverter upload useraccounts usercontol usercontrol vb vb.net vb.nettoolboxvisualbasic2008sidebar vba vbnet vista visual visualbasic visualbasic.net visualstudio.net web wpf wrapingcode xml





