|
Set and get your boolean via a property, so you can raise an event when it is changed.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Sounds like a plan, but how do you end the the current method that this boolean is on?
eg.
Property B {get{read data} set{IF failure [???]}}
Method A
{
[is there something I can do here to conditionalize if B is not true do something]
B = test1;
B = test2;
[this is where it catches the condition when its not true]
}
-- modified at 19:26 Thursday 10th November, 2005
|
|
|
|
|
Kuira wrote: how do you end the the current method that this boolean is on?
Oh, OK. Why do you want to do that ? Surely there's better ways to do it ( for example, check the boolean in the method in question ). If you wanted, you could throw an exception here and put a try/catch in the method that sets it, but it's really convoluted, and ugly.
If I get this right, your calling code will change a boolean, and if it sets it to the right value, the rest of that function won't execute ? Why do you need to do this ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I have a testing procedure that calls my other testing procedures. If one of them fails the test, I want to be able to catch it, store it as a message and pass it back to the originator. Writing the error and saying this test failed, please try again and telling him to recall this function when he is ready for his set of data to be tested again.
That way, the originator will only need to call one function, I will pass him the message pass or fail, and everyone is happy.
I dont like the idea of
bool = test 1
if bool is true (return message)
bool = test 2
if bool is true (return message)
... Imagine I have 100 tests
|
|
|
|
|
Kuira wrote: I have a testing procedure that calls my other testing procedures.
Have the testing procedures return a boolean value indicating success or failure (true or false). Then represent those procedures with delegates. Put the delegates into a collection or an array. From the main testing procedure, iterate through the collection invoking each delegate until one returns false.
If one of the testing procedures fails, that is returns false, make note of which procedure it is (this could involve some extra work to associate some information with each procedure delegate, but it should be pretty straightforward), and return the appropriate error message.
To be honest, I'm not entirely clear on what you're trying to do, so this suggestion is in part guesswork. Hope it helps.
|
|
|
|
|
.... I dont know how to explain it but I'll try again:
- User clicks on a button after they written out a form with a set of data that has been validated on the data side.
- The middleware looks at this and then validates the set of data provided by the GUI to determine if the data that has been inputted is valid to be stored in a database.
- These set of tests range from testing the database connectivity, if any of the data inputted will conflict with the current set of data or even if the entry cannot be inserted because the exact same data exists.
- If one of these tests fail because of those issues, it will stop the test, write a message back to the user to explain the fault, and let the user decide if they want to refix it or cancel the action.
So in essence currently in pseudo code its
string test(input data, input tablename, output conflictions)
{
bool = test1() //connect to database
if (!bool) { return "cannot connect to database"; }
bool = test2(tablename) // checks if the table is not locked at the moment
if (!bool) { return "currently in session, please try again later"; }
bool = test3(data, tablename) // checks if the data is already inserted
if (!bool) {return "data already exists in database!"; }
bool = test4(data, tablename, conflictions) //validates if we insert this data and hits a number of constraints
if (!bool) {return "Conflictions has occured please look at the conflictions and try again"; }
}
|
|
|
|
|
Ok, my eariler suggestion doesn't work because the test methods have different signatures.
One approach would be to abandon using the boolean and just use exceptions:
public void Test(input data, input tablename, output conflictions)
{
Test1()
Test2(tablename)
Test3(data, tablename)
Test4(data, tablename, conflictions)
}
private void Test1()
{
if(unableToConntect)
{
throw new ApplicationException("Cannot connect to database.");
}
}
You would probably want to use your own exception class derived from Exception or ApplicationException that contains information about the failure.
If throwing an exception from the Test method is unacceptable, you could catch the exception in the method itself, and do whatever is appropriate there, or maybe even take some action and rethrow the exception.
|
|
|
|
|
Ok, from the exception part, if Test1 fails from there, will that means that Test2 wont fire from the algorithm you written up? If so this should be acceptable, I'll just make a simple exception thats derived or something to say true or false, as long as I dont need to use if statements whenever I need to check each methods return value.
|
|
|
|
|
Kuira wrote: Ok, from the exception part, if Test1 fails from there, will that means that Test2 wont fire from the algorithm you written up?
Right. Say you did something like this, building on the code example I provided in the previous post:
public void SomeMethod()
{
try
{
Test();
}
catch(TestException ex)
{
Console.WriteLine(ex.Message);
}
}
When an exception gets thrown from one of Test methods, flow of control jumps immediately to the catch block above without executing any of later Test methods.
Kuira wrote: I'll just make a simple exception thats derived or something to say true or false, as long as I dont need to use if statements whenever I need to check each methods return value.
You can include an error message with the exception. Since each Test method knows what its purpose is, by having them throw an exception upon failure, they know also know what the error message should be (see my example in the previous post).
|
|
|
|
|
Ok sounds like a good plan to me, I'll use that thanks.
|
|
|
|
|
(Be gentle, I'm a .Net newbie)
How do I parse an XML string to a DOM tree? My gut says use a variant of an XMLReader so I thought I'd give XMLTextReader a try by giving it a Stream created from my string , but I don't know how to do that, so I'm probably barking up the wrong tree. I was hoping I could use BufferedStream ...
Thanks!
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Looks like I may need to use XmlDocument.LoadXml() ...
[edit]
Yep - that was it!
[/edit]
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Hey PPL
I mad a homepage using the new asp.net 2.0 controles and all my users are stored in a SQLExpress db files connected with the SQLMembershipProvider.
Is there any way to use this Provider from a windows application ?? I made a reference to System.Web.Security, where it's located and i can make a new class like System.Web.Security.SqlMembershipProvider mp = new System.Web.Security.SqlMembershipProvider(); but that's pretty much it. I cannot find any way configurer it like in the web.config file. Any idears ?
Thx in Advance
|
|
|
|
|
I am looking for a way to drag-drop regions inside a Panel.
Can somebody please point me to the right direction.
|
|
|
|
|
Hello, I want to call a method which accepts an array. I've defined an array (originalArray) and want work with it within the method CheckArray. But if I change something within the array inside the method, the original array will be modified too. I thought the parameters are ByValue automatically? Isn't it?
Thanks in advance for every tip.
private void button4_Click(object sender, System.EventArgs e)<br />
{<br />
CheckArray(originalArray);<br />
}<br />
<br />
private void CheckArray(int[,] iArray)<br />
{<br />
int[,] copyArray = iArray;<br />
copyArray[0,0] = 0;<br />
}
|
|
|
|
|
Seraphin wrote: Hello, I want to call a method which accepts an array. I've defined an array (originalArray) and want work with it within the method CheckArray. But if I change something within the array inside the method, the original array will be modified too. I thought the parameters are ByValue automatically? Isn't it?
Yes. But...
private void button4_Click(object sender, System.EventArgs e)
{
CheckArray(originalArray);
}
private void CheckArray(int[,] iArray)
{
int[,] copyArray = iArray;
copyArray[0,0] = 0;
}
You've not copied the array, you've only created another reference to the same array. When you assign a value to the array using the copied reference, the original array is affected, too. iArray and copyArray both reference the same array.
Remember, iArray is just a reference to an array held somewhere in memory. References are just variables. The reference is passed by value so that if you did something like this:
private void button4_Click(object sender, System.EventArgs e)
{
CheckArray(originalArray);
}
private void CheckArray(int[,] iArray)
{
iArray = new int[10, 10];
iArray[0, 0] = 0;
}
The originalArray will not be affected. You've only changed the iArray variable, which has local scope within the method.
To copy the array, you have to create a new array, not just a new reference, and copy the contents of the old array into the new array. Unfortunately, the CopyTo method only works for one-dimensional arrays, so you may have to write code that does the copying by hand. Or maybe someone else knows of a better way.
|
|
|
|
|
Thx, but what "ref" stands for, if you use it in a parameter list? If its just a reference, why I should use "ref"? I've read that ByValue is the standard, so I am confused ...
|
|
|
|
|
Hmm, I thought I had replied to this post, but it's not showing up. Here is the second attempt (good thing I had my answer saved).
Say I did this:
private void button4_Click(object sender, System.EventArgs e)
{
CheckArray(ref originalArray);
}
private void CheckArray(ref int[,] iArray)
{
iArray = new int[10, 10];
iArray[0, 0] = 0;
}
This will actually change the originalArray variable. It now points to the new array I created in the CheckArray method. Without the ref modifier, it would only change the local iArray variable.
A reference is a variable that points to some object in memory. The originalArray variable is a reference to an array held in memory somewhere. It allows me to perform operations on the array. However, operations on the originalArray variable itself only effect that variable. For example:
int[] arrayA = new int[10];
int[] arrayB = arrayA;
arrayA[0] = 42;
arrayA = null;
Console.WriteLine(arrayB[0]);
When a reference variable is passed by value to a method, a copy of the reference variable itself is made, much like what I did above with the arrayB variable. You'll notice that when I nulled out the arrayA , it did not affect the arrayB variable. It's the same when you pass a reference by value to a method. operations on the reference variable itself only affect the local variable.
Now, the ref keyword gives me a reference to a reference, so to speak. If I modify a parameter with ref , and perform operations that change the variable itself, it also affects the reference variable that was originally passed to the method.
This takes awhile to wrap your mind around it, but keep at it and it will eventually make sense.
|
|
|
|
|
Right, so i'm using direct x to play some music - easy right?
Well anyway, i add in the reference and what not and it all works, but i go to a different computer which i havn't installed the sdk, and obviously it doesn't work.
So.
If i go get the dll files and supply it with the app, then put the refference on them, would that work?
Or do i actually need to have the sdk installed?
If so, how do i get it to work without the user having to download and install the sdk?
ps. what exactly does the DirectX redistributable do? It doesnt let me run the app.
|
|
|
|
|
The Undefeated wrote: ps. what exactly does the DirectX redistributable do? It doesnt let me run the app.
It should do, so long as it's the right one. Your app should probably have some DirectX dlls to install with it as well, when you reference them, do you set your project up to copy them to the local directory ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I had a similar issue. After installing the VS2005 Pro as well as the VS2005 C++ express, I got a package load error each time I started VS2005 pro OR the vs2005 C++ express editon. I uninstalled and reinstalled several times and got the same result. I also tried using the uninstall exectutable from Microsoft to no avail.
Finally I took the following steps:
1. uninstalled EVERYTHING that had to do with Visual Studio, and .NET components (2.0, 1.1, 1.0), SQL Server and MSDN, MSXML. I mean everything. I followed the uninstall directions given in the dialog after uninstalling Visual Studio and removed/uninstalled the items in the order specified.
2. Then I went to the WINDOWS\assembly directory and deleted EVERYTHING under that directory.
3. I went to "Program Files" directory and deleted everything that had to do with Visual Studio and .NET (2.0, 1.1, 1.0) and SQL Server and MSDN.
4. I also went to the following directories and deleted everything and all directories that had to Visual Studio, SQL Server, MSDN and .NET (2.0, 1.1, 1.0)
"Documents and Settings\<username>\Application Data\Microsoft"
"Documents and Settings\<username>\Local Settings\Application Data\assembly"
"Documents and Settings\<username>\Local Settings\Application Data\Microsoft"
5. Finally I deleted all tempory files in all temporary directories and cleared the internet cache and temporary files using IE
6. I also went to "My Documents" and deleted the Visual Studio stuff there.
After all that I reinstalled VS2005 Pro and VS2005 C++ express and I no longer get the errors.
|
|
|
|
|
When rendering a string onto a Graphics, on can specify a StringFormat. The StringFormat object has propery named "Trimming". Using this feature a string that doesn't fits into a region is trimmed.
How can this be achived with a label. How can I make a label's to trim it's text?
I hope I understand...because is a rough world out there...
|
|
|
|
|
When you put text in a label doesnt it just get cut off if it doesnt fit anyway?
Or am i just confused about stuff
|
|
|
|
|
It does get cut off, meaning that what it doesn't fit it's not rendered, but the trimming method offers a way of informing the user that the text didn't fit it's area by inserting a "..." string at the end of the visible text.
I hope we understand...because is a rough world out there...
|
|
|
|
|
I kind of resoved the problem in a "manual" way : implementing my own Pain method - work's fine for what i neaded the functionality.
I hope you understand...because is a rough world out there...
|
|
|
|
|