| | |
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: 28
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
Views: 479 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
.net .net2008 2005 2008 access account application array arrays basic bing browser button buttons c# center check checkbox code convert crystalreport cuesent data database datagrid datagridview date datetimepicker dissertation dissertations dissertationtopic dropdownlist eclipse excel fade file-dialog filter ftp generatetags gridview images inline input insert intel internet lib listview mobile monitor net objects output panel passingparameters pdf picturebox port position print printing problem read remove save searchbox searchvb.net select serial settings shutdown soap sorting survey table tcp temperature text textbox timer timespan transparency trim update user validation vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet visual visualbasic visualbasic.net visualstudio2008 web webbrowser winforms wpf year





