|
Hello,
I'm having some problems saving the state of a textbox in VB.Net. Here's the scenario, I have a textbox with it's properties set to Multiline to True, and several lines of text in the Lines properties, so the string array has 5 lines. These properties to the textbox were set with the editor not prgrammically.
When the application is running I want to be able to add or delete from the textbox, and make the changes permanent. So, when I close the application and come back I want the modified values to be shown inside the textbox.
Any ideas would be helpful. Thanks!
P.S. No database is being used.
|
|
|
|
|
You have to save the information to a file yourself. The IDE saves the property values you set in the code your writing. See the Windows Forms Designer generated code Region to see what I'm talking about.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks a million I'll take a look at the generated code.
lxhan
|
|
|
|
|
You could also try saving the textbox.text property by making it a dynamic property. That way it is saved automatically. The text is saved in the app.config of your application.
|
|
|
|
|
Thanks a lot I'll give it a shot.
lxhan
|
|
|
|
|
I been playing with the dynamic property of the textbox to see if it save the new entered text in the app.config file. It only save the hard code values that were defined in the IDE at design time.
I set the dynamic property of the textbox field. Did I forget to set anything else or do I need to write the logic in the source code?
lxhan
|
|
|
|
|
I forgot to mention. You have to write code to save the text when you exit. It's just XML parsing and saving. What it does provide however is automatic reading of that property when you run it again.
|
|
|
|
|
|
I have a piece of code which lists the available SQL servers(or any server for that fact) with in a given domain. The problem is, this requires me to enter the domain name manually. Can anybody please provide me with the code or point me in the right direction to find a solution; which obtains the current users domain name.
|
|
|
|
|
Have you checked out the UserDomainName property of the Environment class?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi,
I am trying to use the cdlOpen to open text files but when I click on open the txt file i have selected does not open.
Below is the code i am using
Private Sub mnuOpen_Click()
cdlOpen.Filter = "Text (*.txt)|*.txt"
cdlOpen.ShowOpen
End Sub
|
|
|
|
|
The common dialog control is only there for the user to SELECT a file. It does not actually open the file. It is up to you, the developer to supply code to actually open the file and do something useful. The selected file's filename is returned in the FileName property of the Commondialog Control.
|
|
|
|
|
Hi, thanks for ur reply. But, I found an information as below,
" To write data to LPT1, use the following code:
Success = WriteFile(hParallelPort, Buffer, Buffer.Length, BytesWritten, IntPtr.Zero)"
In this statement, the author didn't mention about the read operation. Do sir know it?
As sir reply,
is there compatible to implement in visual basic.net?
The dll file can use in vb.net?
All the code in that site can use in vb.net?
Thanks for your help, thank you very much!!!
|
|
|
|
|
The line you found is written in VB.NET. It's not a native function of VB.NET or the .NET Framework. It's actually a call into the Win32 API. You'll also need to use the API function CreateFile to get a valid handle to the parallel port. The API function ReadFile will let you read from he handle. But I wouldn't expect it to work with the parallel port. You'll need a special cable to connect to computers together to transfer data. You won't be able to read any data back from a printer.
If you are transferring data between two computers, you'll find that there is very little help available on the subject simply because it's a technology that wasn't used very much to begin with and was replaced by networks a long time ago.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I have a couple of multiple queries that I have to perform that exist in 2 seperate methods. These methods are called within another method, where a SQLconnection is created and passed in to each of the queryMethods.
For some reason when I obtain the SQLDataReader ( = sqlCommand.ExecuteReader)
throws an error in the second method.
As soon as I use a seperate connection everything works, is there something that I don't understand here with using connections?
|
|
|
|
|
No, theres nothing special there. But without seeing your code and knowing EXACTLY what exception was thrown and the error message with it, we can only guess at what your problem is.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
here is the sub that is calling on the other methods
Private Sub RefreshData()<br />
<br />
While bRun<br />
<br />
Dim SqlConn As New SqlConnection(ModDb.ConnStr)<br />
Try<br />
SqlConn.Open()<br />
<br />
GetCourseList(SqlConn)<br />
If SelectedCourse Is Nothing = False Then<br />
GetFileList(SqlConn)<br />
End If<br />
<br />
SqlConn.Close()<br />
Catch ex As Exception<br />
If SqlConn.State = ConnectionState.Open Then<br />
SqlConn.Close()<br />
End If<br />
End Try<br />
<br />
Try<br />
trdQueryThread.Sleep(REFRESH_PERIOD)<br />
Catch ex As ThreadInterruptedException<br />
'do nothing<br />
Catch ex As Exception<br />
MessageBox.Show(ex.Message)<br />
End Try<br />
<br />
End While<br />
End Sub
Here is the first method that works fine
Private Sub GetCourseList(ByRef sqlConn As SqlConnection)<br />
<br />
Try<br />
Dim sqlCmd As New SqlCommand("dbo.LookupErrByCourseCode_npr", sqlConn)<br />
sqlCmd.CommandType = CommandType.StoredProcedure<br />
<br />
LstCourseCode.Items.Clear()<br />
LstCourseCode.Refresh()<br />
<br />
Dim sqlDR As SqlDataReader = sqlCmd.ExecuteReader<br />
<br />
While sqlDR.Read<br />
Dim course As New CourseDetails<br />
course.CourseCode = sqlDR.Item("Course Code")<br />
course.BoxNumber = sqlDR.Item("Box Number")<br />
course.ErrorCount = sqlDR.Item("Errors")<br />
LstCourseCode.Items.Add(course)<br />
End While<br />
<br />
Catch ex As Exception<br />
Dim myE As New MyException(ex, MyException.SeverityLevel.High)<br />
myE.WhatHappened = "GetCourseList: Error when obtaining Course Details"<br />
Throw myE<br />
End Try<br />
<br />
End Sub
Here is the second method that throws the exception on the SQLDataReader
Private Sub GetFileList(ByRef sqlConn As SqlConnection)<br />
<br />
lstTests.Items.Clear()<br />
<br />
Dim sqlCmd As New SqlCommand("dbo.CourseImage_npr", sqlConn)<br />
sqlCmd.CommandType = CommandType.StoredProcedure<br />
<br />
'reset the params due to selection of new course<br />
sqlCmd.Parameters.Add("@coursecode", SelectedCourse.CourseCode)<br />
sqlCmd.Parameters.Add("@boxnumber", SelectedCourse.BoxNumber)<br />
Try<br />
'====Right here is where it crashes when using the same connection<br />
Dim sqlDR As SqlDataReader = sqlCmd.ExecuteReader<br />
<br />
While sqlDR.Read<br />
'validate that the image exists<br />
Dim fileName As String = sqlDR.Item("image_path") & sqlDR.Item("image_name") & EXTENSION<br />
If IO.File.Exists(fileName) Then<br />
Dim image As New ImageDetails<br />
image.countSRE = sqlDR.Item("countSRE")<br />
image.imageId = sqlDR.Item("image_id")<br />
image.imageName = sqlDR.Item("image_name")<br />
image.imagePath = sqlDR.Item("image_path")<br />
lstTests.Items.Add(image)<br />
End If<br />
End While<br />
<br />
lstTests.Refresh()<br />
Catch ex As Exception<br />
Dim myE As New MyException(ex, MyException.SeverityLevel.High)<br />
myE.WhatHappened = "GetFileList: Error after sleeping"<br />
MessageBox.Show(myE.Message)<br />
'Throw myE<br />
End Try<br />
'End While<br />
<br />
End Sub
|
|
|
|
|
Your Connection code is a bit messed up. If anything fails inside that try block, the connection is never closed. On top of that, it's never disposed either. THis would result is a slow time for the garbage collector to get around freeing it. Also, put the connection close code in a Finally block so that it runs no matter what happens. And, when you check for the connection being opened, don't check for ConnectionState.Open. The connection state can be a combination of values that would no longer result in it being equal to ConnectionState.Open, even though it is. Instead, check for Not Equal to ConnectionState.Closed. The new code looks something like this:
Private Sub RefreshData()
While bRun
Dim SqlConn As New SqlConnection(ModDb.ConnStr)
Try
SqlConn.Open()
GetCourseList(SqlConn)
If SelectedCourse Is Nothing = False Then
GetFileList(SqlConn)
End If
Catch ex As Exception
' You might want to do something to report the error here.
Finally
If Not SqlConn.State = ConnectionState.Closed Then
SqlConn.Close()
End If
SqlConn.Dispose() ' Saves the GC a step in collecting this object.
SqlConn = Nothing ' Drop the reference so the GC collects it on the next pass.
End Try
Try
trdQueryThread.Sleep(REFRESH_PERIOD)
Catch ex As ThreadInterruptedException
'do nothing
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End While
End Sub
Also, in your MyException class, you might want to include the underlying Exception and error Message that was originally thrown. The exception your throwing isn't very descriptive as to what the real problem was.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
using threading with C# and ManagementObjectSearcher Object , i get a "random" COM Exception scanning XP and NT.. Any one have a clue??
|
|
|
|
|
Not without seeing your code. BTW: This is the VB.NET Forum, not C#...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
oh soz didn't realize.. but maybe u can still help me? Ive been battling with this prob for a LONG time now..
Basically- i use: private ManagementObjectSearcher m_MOSearcher;
private ManagementScope m_ManScope;
private ConnectionOptions m_ConnectOptions;
m_ConnectOptions = new ConnectionOptions ();
m_ConnectOptions.Username = "user";
m_ConnectOptions.Password = "pass";
m_ConnectOptions.Authentication = AuthenticationLevel.Call;
m_ConnectOptions.Impersonation = ImpersonationLevel.Impersonate;
m_ConnectOptions.EnablePrivileges = true;
m_ConnectOptions.Locale = "MS_409";
m_ConnectOptions.Timeout = new TimeSpan (0,0,0,0,5);
string strConnection = "\\\\"+ "192.168.0.88" + "\\root\\cimv2";
m_ManScope = new ManagementScope(strConnection, m_ConnectOptions);
ObjectQuery Temp = new ObjectQuery("SELECT " + "Size" + " FROM Win32_" + "DiskDrive");
m_MOSearcher = new ManagementObjectSearcher (m_ManScope, Temp);
foreach(ManagementObject mo in m_MOSearcher.Get())
{
Console.WriteLine("Size: " +mo["Size"].ToString ());
}
Temp = new ObjectQuery("SELECT " + "Model" + " FROM Win32_" + "DiskDrive");
m_MOSearcher = new ManagementObjectSearcher (m_ManScope, Temp);
foreach(ManagementObject mo in m_MOSearcher.Get())
{
Console.WriteLine("Model: " +mo["Model"].ToString ());
}
And thread it with:
for (int i=0; i< 250; i++)
{
Thread a = new Thread(new ThreadStart(Function));
a.Start();
}
i get a rpc error or COm exception sometimes?
maybe deadlock?
|
|
|
|
|
Your code never connects to the management source on the target machine. You need
m_ConnectOptions.Locale = "MS_409";
m_ConnectOptions.Timeout = new TimeSpan (0,0,0,0,5);
string strConnection = "\\\\"+ "192.168.0.88" + "\\root\\cimv2";
m_ManScope = new ManagementScope(strConnection, m_ConnectOptions);
m_ManScope.Connect();
ObjectQuery Temp = new ObjectQuery("SELECT " + "Size" + " FROM Win32_" + "DiskDrive");
m_MOSearcher = new ManagementObjectSearcher (m_ManScope, Temp);
Also, you don't have to perform two queries to get the result you want. One will suffice:
ObjectQuery Temp = new ObjectQuery("SELECT Size, Model FROM Win32_DiskDrive");
m_MOSearcher = new ManagementObjectSearcher (m_ManScope, Temp);
foreach(ManagementObject mo in m_MOSearcher.Get())
{
Console.WriteLine("Size: " +mo["Size"].ToString ());
Console.WriteLine("Model: " +mo["Model"].ToString ());
}
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hey thanks for the timely response!!
ah soz i forgot to paste that in!!(manscope.connect) sorry!
plz if u could try-> just request a whole lot of values from different tables.. and use threads (a lot).. and if u dont get an error maybe i can send u my program
2) Is there any windows setting(using XP) that can affect the WMI? I am unable to connect to some computers??
Thanks so much!
|
|
|
|
|
There are no settings that can affect WMI. I can't get the ManagementObjectSearcher class to work properly at all, either quering the local machine or a remote WMI namespace. The .Get() method works and returns, but the results are unreadable. I get a "COM object that has been separated from its underlying RCW can not be used." error in a Unhandled exception of type 'System.Management.ManagementException' occurred in system.windows.forms.dll when I try to get an enumerator for the returned object collection (ManagementObjectCollection.) But the entire WMI search code is wrapped in a Try/Catch block.
This error is getting back to the message pump unhandled for some reason. It looks like a bug in the .NET Framework, but I can't find any information on it. I also can't get a complete list of bug fixes in the upcomming Service Pack 1 for the .NET Framework 1.1 and SP3 for the .NET Framework 1.0. There are a LOT of bug fixes that don't have Knowledge Base articles for them yet...
Until the service pack comes out, I don't have a way around this problem.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Here's my code.. works for me..
Excuse the repertition, i just do this for complexities sake some RPC should occur if u use the threads...
using System;
using System.Threading;
using System.Management;
namespace SimpleTRY
{
public class Class1
{
private ManagementObjectSearcher m_MOSearcher;
private ManagementScope m_ManScope;
private ConnectionOptions m_ConnectOptions;
public Class1()
{
for (int i=0; i< 250; i++)
{
/*Thread a = new Thread(new ThreadStart(this.connect));
a.Start();*/
this.connect();
}
}
public void connect()
{
string ipAddress = "192.168.0.88";
m_ConnectOptions = new ConnectionOptions ();
m_ConnectOptions.Username = "Gorilla";
m_ConnectOptions.Password = "rock";
m_ConnectOptions.Authentication = AuthenticationLevel.Call;
m_ConnectOptions.Impersonation = ImpersonationLevel.Impersonate;
m_ConnectOptions.EnablePrivileges = true;
m_ConnectOptions.Locale = "MS_409";
m_ConnectOptions.Timeout = new TimeSpan (0,0,0,30);
string strConnection = "\\\\"+ ipAddress + "\\root\\cimv2";
m_ManScope = new ManagementScope(strConnection, m_ConnectOptions);
m_ManScope.Connect();
{
ObjectQuery Temp = new ObjectQuery("SELECT " + "Size" + " FROM Win32_" + "DiskDrive");
m_MOSearcher = new ManagementObjectSearcher (m_ManScope, Temp);
foreach(ManagementObject mo in m_MOSearcher.Get())
{
Console.WriteLine("Size: " +mo["Size"].ToString ());
}
Temp = new ObjectQuery("SELECT " + "Model" + " FROM Win32_" + "DiskDrive");
m_MOSearcher = new ManagementObjectSearcher (m_ManScope, Temp);
foreach(ManagementObject mo in m_MOSearcher.Get())
{
Console.WriteLine("Model: " +mo["Model"].ToString ());
}
Temp = new ObjectQuery("SELECT " + "SystemName" + " FROM Win32_" + "DiskDrive");
m_MOSearcher = new ManagementObjectSearcher (m_ManScope, Temp);
foreach(ManagementObject mo in m_MOSearcher.Get())
{
Console.WriteLine("SystemName: " +mo["SystemName"].ToString ());
}
Temp = new ObjectQuery("SELECT " + "AdapterRAM" + " FROM Win32_" + "VideoController");
m_MOSearcher = new ManagementObjectSearcher (m_ManScope, Temp);
foreach(ManagementObject mo in m_MOSearcher.Get())
{
Console.WriteLine("AdapterRAM: " +mo["AdapterRAM"].ToString ());
}
Temp = new ObjectQuery("SELECT " + "CurrentRefreshRate" + " FROM Win32_" + "VideoController");
m_MOSearcher = new ManagementObjectSearcher (m_ManScope, Temp);
foreach(ManagementObject mo in m_MOSearcher.Get())
{
Console.WriteLine("CurrentRefreshRate: " +mo["CurrentRefreshRate"].ToString ());
}
Temp = new ObjectQuery("SELECT " + "Name" + " FROM Win32_" + "VideoController");
m_MOSearcher = new ManagementObjectSearcher (m_ManScope, Temp);
foreach(ManagementObject mo in m_MOSearcher.Get())
{
Console.WriteLine("Name: " +mo["Name"].ToString ());
}
Console.WriteLine("--------------------------------------");
}
}
}
}
|
|
|
|