|
FWIW, I think you mean "expression".
The problem is simple. While every other control mode is a right-to-left reading order, simply make that TextBox read from left-to-right by setting TextBox.RightToLeft (inherited from Control ) to RightToLeft.No . If you read the documentation for the RightToLeft enumeration, you'll see the "rules" for how the RightToLeft property is resolved. By setting this property to "No", it will always read from left-to-right.
If the TextBox could have other text besides a mathematical expression, then you'll need to do some checking. You could handle the TextChanged event and parse the text to see if it contains a methematical expression. If it does, then change the RightToLeft property accordingly.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Is MS Access "Transaction Aware"?
|
|
|
|
|
You can make transactions in access DB..
in classic ADO :
con.BeginTrans<br />
..if things go right :<br />
con.CommitTrans<br />
..else<br />
con.RollbackTrans
where con is a connetion object.
|
|
|
|
|
so, I assume it can participate in a COM+ transaction?
|
|
|
|
|
I meant to say, can it participate in a COM+ transaction in following manner:
[Transaction(TransactionOption.Required)]
... other stuff ...
public class AccessDbManager
{
...
public void UpdateClientProfile(...);
public void UpdatePosition(...);
public void GetPosition(...);
...
}
I'm asking this because there's a piece of code that worked perfectly fine in a C# console app, but failed mysteriously when I embed it inside one method of a Transaction enabled serviced component... Here's the code. I tested it many times. It worked in a C# console app.
int count = -1;
string db_username;
string db_passwd;
int db_numlogin;
string connString;
OleDbConnection connUsers;
OleDbDataAdapter daUsers;
DataSet dsUsers;
EventLog log = new EventLog("Application");
log.Source = "AccessDbMaster";
try
{ //try block
retcode = -1;
connString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Program Files\SomeDir\datasource\users.mdb; User ID=Admin; Password=";
Trace.WriteLine(connString);
connUsers = new OleDbConnection(connString);
daUsers = new OleDbDataAdapter("SELECT * FROM Users WHERE username='"+ username + "' AND passwd='" + passwd + "'", connUsers);
dsUsers = new DataSet();
**********************************************************************
daUsers.Fill(dsUsers, "Users"); //BOOM. Failed here. "No error information available: E_NOINTERFACE(0x80004002)."
**********************************************************************
count = dsUsers.Tables["Users"].Rows.Count;
if(count==0) {
log.WriteEntry("AccessDbMaster authentication failed. User not found");
return;
}
foreach(DataRow user in dsUsers.Tables["Users"].Rows)
{
db_username = user["username"].ToString();
db_passwd = user["passwd"].ToString();
db_numlogin = (int) user["numlogin"];
retcode = db_numlogin; //return value
//Increment number of login:
db_numlogin++;
user["numlogin"]=db_numlogin;
}
OleDbCommandBuilder cmdBuilder = new OleDbCommandBuilder(daUsers);
daUsers.Update(dsUsers, "Users");
connUsers.Close();
} //try block
catch(Exception err)
{
log.WriteEntry("AccessDbMaster authentication failed. Info: " + err.Message);
retcode=-1;
ContextUtil.SetAbort();
}
I'm not out of the woods yet. Any advice will be greatly appreciated.
|
|
|
|
|
I believe it can
|
|
|
|
|
Humm... thanks... Need to trace that E_NOINTERFACE error, that makes me an unhappy man on this date November 12, 2003.
|
|
|
|
|
Hello,
I've a problem creating objects using Reflection. I tried to create a new System.Drawing.Size object using the CreateInstance Method from the Assembly class. Everything worked well, but if i try to cast this object into another Size object my application crashes.
Here is the source :
//----------------------------------------
using System;
using System.Drawing;
using System.Reflection;
namespace TestApp
{
public class TestApp
{
public static void Main ()
{
object[] args = new object[2];
args[0] = (int) 200;
args[1] = (int) 400;
object o1 = null;
object o2 = null;
Size s1 = new Size ();
try
{
o1 = CreateInstance ("System.Drawing.dll", "System.Drawing.Size", args);
}
catch (Exception ex)
{
Console.WriteLine (ex.Message);
}
try
{
o2 = new Size (200, 400);
}
catch (Exception ex)
{
Console.WriteLine (ex.Message);
}
try
{
Console.Write ("Trying to cast o2 to Size s1...");
s1 = (Size) o2;
Console.WriteLine ("DONE");
Console.WriteLine ("s1 : " + s1.ToString ());
Console.ReadLine ();
Console.Write ("Trying to cast o1 to Size s1...");
s1 = (Size) o1;
Console.WriteLine ("DONE");
Console.WriteLine ("s1 : " + s1.ToString ());
Console.ReadLine ();
}
catch (Exception ex)
{
Console.WriteLine (ex.Message);
Console.ReadLine ();
}
}
private static string GetSystemDir ()
{
Assembly [] assemblies = AppDomain.CurrentDomain.GetAssemblies ();
foreach (Assembly a in assemblies)
{
string codebase = a.CodeBase;
if (codebase.EndsWith ("corlib.dll"))
{
return codebase.Substring (0, codebase.LastIndexOf ("/")).Substring (8);
}
}
return "";
}
private static object CreateInstance (string AssemblyName, string ClassName, object[] args)
{
try
{
Assembly a = Assembly.LoadFile (GetSystemDir () + "/" + AssemblyName);
return a.CreateInstance (ClassName, true, BindingFlags.CreateInstance, null, args, null, null);
}
catch (Exception ex)
{
Console.WriteLine (ex.Message);
}
return null;
}
}
}
//----------------------------------------
I hope someone can help me. Thanx in advance
( Sorry about some mistakes, my english is not so good )
|
|
|
|
|
It's failing because your not loading the containing assembly correctly. If you read the documentation for Assembly.CreateInstance , it returns null if the type was not found. Since you're dealing with value types - which cannot be null - casting a null reference to a value type will throw an exception.
I think you're missing the point of the global assembly cache (GAC). You don't have to - nor should you - worry about where the assemblies are so long as they are in the GAC or the private path (the "bin" folder, for instance, in ASP.NET). .NET, first of all, does not use the %PATH% env var. If the Type you want to create is contained in an assembly in the GAC or the private path of your application, you simply create the Type and assembly - if not already loaded - is loaded from the GAC automatically (and if a pre-JIT'ed (native) assembly exists, it'll be used instead because it loads and executes faster).
Try this:
Type t = Type.GetType("System.Drawing.Size, System.Drawing", false, true);
Size s = (Size)t.Assembly.CreateInstance(t.ToString(), ...); Of course, there's many other ways to do this. The important thing is that you shouldn't worry about the paths to assemblies themselves unless they are your assembly in a non-private path, such as plugins or something. The .NET base class library (BCL) is in the GAC and should not be referenced by a local file path. Besides, the method you're using for finding the local path is extremely slow and inefficient. If nothing else, you should at least cache the directory once you've found it and avoid the large loop every time.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hello,
Thanks for you help. I've tried you code, but my app still does not work. If I try to get a System.Int32 or something else in the System assembly it works fine. But if I try to get a System.Drawing.Size it fails.
Type t1 = Type.GetType ("System.Reflection.Assembly", false, true);
Type t2 = Type.GetType ("System.Int32", false, true);
System.Drawing.Size s = new System.Drawing.Size (100, 200);
Type t3 = Type.GetType ("System.Drawing.Size, System.Drawing", true, true);
Type t4 = Type.GetType ("System.Drawing.Size", true, true);
What's my mistake ? I've included the link to the System.Drawing.dll in my project and I've also included a using System.Drawing; in my code. Is there any configuration to do for my app assembly ?
|
|
|
|
|
Stux wrote:
If I try to get a System.Int32 or something else in the System assembly it works fine.
Actually, those types are in the mscorlib.dll assembly, the implicit library that is always included.
Stux wrote:
What's my mistake ?
Good question. t3 is the correct code. Unless something is in the mscorlib.dll assembly (which is why I mentioned that above) or in the currently loaded assembly, you must give an assembly name like you did there. Everything looks right, though. Type.GetType will load the assembly in which the Type is contained if it isn't already. And you don't have to include a reference to it in your project if you plan on using Reflection. The BCL assemblies are in the GAC (at least they should be, open the folder \Windows\assembly and verify) which is alway checked after private paths (like the bin directory in ASP.NET) or assembly binding redirections in the .config file.
The only other thing I can think of that you could do is use the fully-qualified the type name, i.e. "System.Drawing.Size, System.Drawing, Culture=neutral, Version=1.0.3300.0, PublicKeyToken=b03f5f7f11d50a3a" (for .NET 1.0), although I've never had to do this on my work machine - but I only have one framework currently installed. Do you, by chance, have both .NET 1.0 and 1.1 installed?
Anyway, try using the FQN (fully-qualified name) and see if that works. Other than that, you're doing it right.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
You're right. I've both Frameworks installed, but I've already tested the fully-qualified type name. I've also tested the Project on an other machine, having only the .NET 1.1 Framework installed. Nothing worked
But I found an other solution :
Assembly a = Assembly.LoadWithPartialName ("System.Drawing");
Type t = a.GetType ("System.Drawing.Size");
I hope that will work until I've more time to examine the problem.
Thanks anyway.
Nice "Geek-Code-Block" I think I will also include one in my Profile.
|
|
|
|
|
Please help me ! I want to communicate bettwen a service and an application . But i don't know how to .
q
|
|
|
|
|
Use .NET Remoting.
Just search for "remoting" and/or "services" here on CP. Remember to look out for "obsolete" samples. (Ie. code written with a beta version of the framework.)
Have a look at my latest article about Object Prevalence with Bamboo Prevalence.
|
|
|
|
|
I want to experiement with COM+ application load balancing. What do I need to get started?
a. two machines with Win2000/2003 installed
b. What else do I need?
Would you recommend any article/references/book?
Thanks.
|
|
|
|
|
I am trying to load data to an string variable in the next way:
.
.
.
string s = "";
string text = "";
do {
If ( text have some conditions)
s = s + text + "\n";
text = reader.ReadLine( );
}
while (text != null);
.
.
Then I need to show string "s" to user using a multiline textbox created with Web Forms. The problem is that the previous loop lasts many, many minutes. It tries to load 2MB but in a slow manner, I imagine that the memory allocation is the problem. I need textbox for copy/paste purposes.
Is there anyway to enhance the speed of s = s + text + "\n"; ???
Best regards.
|
|
|
|
|
System.Text.StringBuilder is a little faster:
StringBuilder s = new StringBuilder();
string text = "";
do {
If ( text have some conditions)
s.AppendFormat("{1}\n", text);
text = reader.ReadLine( );
}
while (text != null);
|
|
|
|
|
Corinna,
Wouldn't this be even a little faster?
StringBuilder s = new StringBuilder();
string text;
while ((text = reader.readLine()) != null) {
if ( <condition> )
s.Append(text).Append('\n');
}
Regards,
Jeff Varszegi
[edit] Forgot to include the condition! I'm gonna test the impact of AppendFormat() versus the extra method call. JKV [/edit]
|
|
|
|
|
I was interested enough to run a performance test because I never used AppendFormat before, and I know that StringBuilder is highly optimized. I ran this code in Debug mode in VS .NET 2003 on my laptop:
StringBuilder sb;
string text = "abc";
int x, y;
long startTime, endTime;
<br>
startTime = DateTime.Now.Ticks;
for(y = 0; y < 5000; y++) {
sb = new StringBuilder(10000);
for (x = 0; x < 250; x++) {
sb.Append(text).Append('\n');
sb.Append(text).Append('\n');
sb.Append(text).Append('\n');
sb.Append(text).Append('\n');
sb.Append(text).Append('\n');
sb.Append(text).Append('\n');
sb.Append(text).Append('\n');
sb.Append(text).Append('\n');
sb.Append(text).Append('\n');
sb.Append(text).Append('\n');
}
}
endTime = DateTime.Now.Ticks;
Console.WriteLine(((endTime - startTime) / 10000) + " ms using Append()");
<br>
startTime = DateTime.Now.Ticks;
for(y = 0; y < 5000; y++) {
sb = new StringBuilder(10000);
for (x = 0; x < 250; x++) {
sb.AppendFormat("{0}\n", text);
sb.AppendFormat("{0}\n", text);
sb.AppendFormat("{0}\n", text);
sb.AppendFormat("{0}\n", text);
sb.AppendFormat("{0}\n", text);
sb.AppendFormat("{0}\n", text);
sb.AppendFormat("{0}\n", text);
sb.AppendFormat("{0}\n", text);
sb.AppendFormat("{0}\n", text);
sb.AppendFormat("{0}\n", text);
}
}
endTime = DateTime.Now.Ticks;
Console.WriteLine(((endTime - startTime) / 10000) + " ms using AppendFormat()");
It printed these results:
<font color="#000066">1682 ms using Append()</font>
<font color="#000066">7801 ms using AppendFormat()</font>
Interestingly enough, creating a separate variable to hold the format string and using that in calls to AppendFormat increased the run time of the second section a little. I still know next to nothing about the IL, but I'm sure there's some good explanation for this.
Regards,
Jeff Varszegi
|
|
|
|
|
I've create an inherit class of dataGrid and add it to form by press of a button. the class will dispose after sending a value to the form by dblclick. The problem is, I dont want to load the class everytime i press the button. I want it to work like load/unload when button press. Is there anyway to check control or class existence?
// this is how i add the class to form by button press
private void button2_Click(object sender, System.EventArgs e)
{
myLOV aLOV = new myLOV();
aForm.Controls.Add(aLOV);
}
PS: Working Environment is .NET Compact Framework on Windows CE 3.0
|
|
|
|
|
if (aLOV == null)
aLOV = new MyDataGrid();
if (aForm.Controls.Contains(aLOV))
aForm.Controls.Remove(aLOV);
else
aForm.Controls.Add(aLOV); Declare aLOV as a field in your class - most likely a private field like all the other controls.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Great thats works... THANKS
but there's something... weird.
the class show only flashes on the first load, but normal after that. is there anyway to solve this ???
THANKS... a lot
|
|
|
|
|
Bhangorix wrote:
the class show only flashes on the first load, but normal after that
I don't understand what you mean? If you mean you want it to be loaded initially, then instantiate it and add it to the controls collection in your constructor (or, like the VS.NET designer does it, in InitializeComponent ).
If this isn't what you mean, please elaborate.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
i mean... when this proc
if (aLOV == null)
aLOV = new MyDataGrid();
if (aForm.Controls.Contains(aLOV))
aForm.Controls.Remove(aLOV);
else
aForm.Controls.Add(aLOV);
call for the the first time, it just flashes.
but never mind, i've work something else that is different but a litle like that one. THANKS anyway
|
|
|
|
|
Basically, i want to know if there is a way to convert an Image to an Icon in C#. I tried the Icon constructor which accepts a Stream object and a Memory stream accepts a byte[], but i wasnt sure how to convert an Image to a byte[].
I am loading a .png file into memory to show a status, but i also have to show the same image in the form's icon and i dont want to have a .ico and a .png file for every status.
Thanks for the help.
|
|
|
|
|