|
right.
|
|
|
|
|
Hello there,
Whenever i say , "ok, we can solve this by declaring one bool variable (flag) and checking true/false" , my architect says "no flags please!!". Any thoughts why flags not recommended? is it not recommended best practice?
Thanks
|
|
|
|
|
Member 2324483 wrote: "ok, we can solve this by declaring one bool variable (flag) and checking true/false" , my architect says "no flags please!!". Any thoughts why flags not recommended?
Huh? Your architect needs to get his head checked out. There's nothing wrong with using flags for the most part.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Hi,
if a variable can have only two values it is perfectly OK to use a bool which is either true or false.
As an alternative you can define your own enum with two (or more) more meaningful values.
You can see the difference this can make in this hypothetical method call:
TextWriter wr1=File.CreateText("myFile1.txt", true, true, false, true, false);
TextWriter wr2=File.CreateText("myFile2.txt", FileMode.Write, FileShare.None, FileCreate.NoOverwrite,
FileCompression.Off, FileArchive.No);
The first line is error-prone for the programmer and a mystery for all readers and can be understood only
by checking something else (the documentation, Intellisense, whatever); the second line is self-explaining
by not using boolean flags.
|
|
|
|
|
Luc Pattyn wrote: As an alternative you can define your own enum with two (or more) more meaningful values.
The boolean version 2.0 springs to mind...
WTF: What is truth?[^]
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
I think that your architect has had some traumatic experience involving flags. There is nothing inherently wrong with using flags. They can of course be used in the wrong place or overused, but that can be said about anything.
The framework has a lot of exampels of flags, most of them working just fine. The Visible flag, for example, which is used in every control.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks guys for giving good explanations. However the explanation given by luc pattyn makes more sense. Thanks luc. May be thats the reason he (my architect) says "no flags" to make the code more expressive and less error prone.
|
|
|
|
|
Another point worth noting about using flags, especially as instance variables, is that it is important to record state changes. Subsequent changes to the code can often introduce new points of state change that impact the flag, but do not update the flag.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
I am trying to fill a combobox that is in a datagrid with values. The code compiles fine, but when it generates the datagrid it gives a error. "System.ArgumentException: DataGridViewComboBoxCell value is not valid". Any ideas what I am doing wrong?
DataGridViewComboBoxCell colComboCell = new DataGridViewComboBoxCell();
colComboCell.Items.Add("0");
colComboCell.Items.Add("1");
colComboCell.Items.Add("2");
colComboCell.Items.Add("3");
dataGridTicketTypes.Rows.Add(EventTicketPrice_ID, colComboCell);
|
|
|
|
|
You can try the following code assuming that the comboBox column is named valueColumn:
DataGridViewColumn valueColumn = new DataGridViewColumn();
dataGridTicketTypes.Columns.Add( valueColumn );
DataGridViewRow row = new DataGridViewRow();
DataGridViewComboBoxCell cell = new DataGridViewComboBoxCell();
cell.Items.Add("0");
cell.Items.Add("1");
cell.Items.Add("2");
cell.Items.Add("3");
valueColumn.CellTemplate = cell;
int rowIndex = dataGridTicketTypes.Rows.Add( row );
row = dataGridTicketTypes.Rows[ rowIndex ];
Hope it helps.
If you have any question contact me.
|
|
|
|
|
The code you provided did add the items to a dropdown menu, however it added a new column in which it added this data which I want to specify it as I am adding values.
1. Create a new form
2. Add a datagridview1 to the form
3. add two columns to the data grid (IDColumn, valueColumn)
4. Add a button to the form which will insert a record
5. When you click on the button it should add one row to the DataGrid by using something like below (but that actually works).
DataGridViewComboBoxCell cell = new DataGridViewComboBoxCell();
cell.Items.Add("0");
cell.Items.Add("1");
cell.Items.Add("2");
cell.Items.Add("3");
dataGridView1.Rows.Add("test", cell);
|
|
|
|
|
You can skip the first two lines :
DataGridViewColumn valueColumn = new DataGridViewColumn();
dataGridTicketTypes.Columns.Add( valueColumn );
|
|
|
|
|
I already had those skipped. My code looks like this which still does not add information to the drop down menu.
private void button1_Click(object sender, EventArgs e)
{
DataGridViewComboBoxCell cell = new DataGridViewComboBoxCell();
cell.Items.Add("0");
cell.Items.Add("1");
cell.Items.Add("2");
cell.Items.Add("3");
dataGridView1.Rows.Add("test", cell);
}
|
|
|
|
|
Here is what I am trying to do.
I have treeview that is full of a family tree.
Example
parent1
-spouce1
-kid1
-secondkid1
parent2
-kid2
parent3
-spouce3
-kid3
parent4
(but I don't really know how many parents and kids there are.
So, now what I want to do is randomly match up each person with someone else, but not someone in thier own node. For example, I don't want parent1 to get matched up with his spouce or kids, but he would be fine matched up with parent2 or his kid.
My brain is about mush right now and I am not thinking of how to do this, though there must be a simple way.
My original idea was to put everything into arrays. Then choose the longest array and randomly chhose another array then randomly choose a member of that array to match up with the first person, then remove both people from the arrays and calculate the longest array again and repeat until there is no one left. But implementing the idea seemed more complicated and I thought there must be an easier way, no?
|
|
|
|
|
If you want it to be more random you could use your original idea but with a random number generator to determine which array to look at rather than just selecting the longest array. Another idea would be to put everything in a single array and just use the random number generator to give a random index into the array and if the item in the index is in a different family, you've got a hit otherwise get another index from the random number generator.
List<int> peopleUsed = new List<int>();
Random r = new Random();
int person1Index, person2Index;
person1Index = person2Index = 0;
while(peopleUsed.Count < people.Length)
{
if(!peopleUsed.Contains(person1Index))
{
do
{
person2Index = r.Next(0, people.Length);
}
while(peopleUsed.Contains(person2Index) && !peopleAreInSameFamily(person1Index, person2Index));
peopleUsed.AddRange(new int[] { person1Index, person2Index });
}
person1Index++;
}
Keep It Simple Stupid! (KISS)
|
|
|
|
|
the problem I worry about with that is if you don't start with the longest list, then you might end up at the end with only members of one family
|
|
|
|
|
I am able to open uncompressed TIF files using
Bitmap objImage = new Bitmap(ImagePath);
but when I try to read compressed tif (JTIF) it gives me error.
Is there any way I can convert compressed tif to uncompressed?
Thanks.
Niks
|
|
|
|
|
NAMhatre wrote: Is there any way I can convert compressed tif to uncompressed?
Not using anything dependant on GDI+, no. GDI and GDI+ do not support LZH compressed (read JPG) TIFF files. You'll have to use a third party library to handle those files or an external tool to convert the files to uncompressed TIFFs.
|
|
|
|
|
Dave Kreskowiak wrote: LZH compressed (read JPG) TIFF files
Ummmmm LZH is a lossless compression algorithm, JPEG uses a lossy algorithm.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
Ummmmm, yep, you're right! I haven't had to think about that problem in about 2 years now. Man did I screw that up, and I typoed the compression type too (LZW, not H).
|
|
|
|
|
Thinking of GIFs? LZH is a real compression algo so the typo angle never occurred to me yesterday.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
Hi,
following problem:
I have a main application which starts a new thread while loading to show a splash screen.
The new thread is started within a form-class called splash with a static start method.
The splash screen is showed by splash.ShowDialog() in its constructor.
All happens within this class. So in the main application I only have to call the static start method on the splash class, it starts the new thread and initializes the splash class ... that's it.
When the splash closes himself in a timer event with splash.close() the splash is closed but also the main application is minimized!
Althoug it appears behind the splash screen when it is loaded.
I only want to close that splash screen and let the rest as it is .
Is there an easy solution to handle this?
I don't want to give the splash class a reference to the main application!
Thanks for any help,
Daniel
|
|
|
|
|
Hey Daniel,
Have you tried:
Splash.Close();
Splash.Dispose();
Hope this helps. Let me know how it goes?
Regards,
J.t.
|
|
|
|
|
I've developed a desktop application in .net 3.0 C# that is to be deployed to several users. I want to prevent the application .exe from being taken and used on an unauthorized PC. Currently, I've added some registry keys in the install package. The application looks for the registry keys when it launches, if it doesn't see the keys, it doesn't launch. That's working but I want to make sure that's the best way to do it. What is the best way to do that?
Thanks!
|
|
|
|
|
This is quite tricky to do, and it largely depends on how much time/money you are prepared to spend getting it perfect.
At the extreme end there are companies like KeyLok[^] and SmartLock[^] offer products where they use hardware USB dongles to perform checks before the software will run, so you can only run the software if you have a properly licensed dongle in the PC.
On the other end, you can just add reg keys and check them when your app starts like you've done.
It depends also on your target user. A general home user isn't going to be able to figure out how to copy the correct reg keys to a new machine.
You could improve it a bit by collecting some hardware data, or OS serial number or something like that, combining it with a unique license number for the user hashing it and giving the user that as a serial number. That way if they tried to install it on a different PC, serial number would not match the one that the app would generate from hardware data.
Ultimately though, anything written in C# can be easily reverse engineered by a competent programmer so the best thing to do is price is fairly, market it well, keep in touch with your customers. Think of good incentives to buy the real thing, like support, physical disks, manuals, etc and just hope that in general, most people are honest enough to pay for it.
Simon
|
|
|
|