|
I'm coding for Windows Forms. The teacher has only gone over arrays so far, but likes arraylists better. Using arraylists b/c can mix types.
Out of range error from this line:
subtotal = (decimal)subList1[2] + (decimal)subList2[2] + ... (decimal)subList5[2]);
(What gets added previously is a decimal.)
If my menu item 'AddtoCart' has not filled all arraylists (i.e. 5 times) I get the error. Thinking the ones not "given" a value = -1. I don't care to use List<>, etc. as this teacher can get vy prissy.
I just want to change the values that I think are -1 to 0 so addition works. I can't pre-load anything due to how arraylists get 'loaded', obviously. I could Replace the last element: [2].
But I don't know how to loop b/c I can't use a variable such as i in the name of the arraylist itself. Been high and low online for a solution...
Thank you,
Mac
|
|
|
|
|
The out of range exception indicates that there is no element at 2 in one of your lists. Put a breakpoint on that line by pressing F9 and debug your application. Take a look at the size of each one of your lists.
|
|
|
|
|
Your teacher is an idiot. Arraylists are seriously out of date, simply because you can mix types, which means they give runtime errors instead of compile time. That means that it is more likely that a problem will get through to production than using a List<T> which insists on strong typing and doesn't need you to cast the variables.
But in this case, I'd use an array of decimal values instead of a List or ArrayList: unless you are adding items dynamically (at run time) and don't know the number of items in advance.
The error is probably because you are using "magic numbers" - the hard-coded "2" in your code - instead of using a loop to get the values.
Go back a step, and think how you would use a loop to access an array - I'm sure that your teacher has covered that - and then look at the whole of your code (not just the one line you show) and try using that method on your list.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Mac20nine wrote: But I don't know how to loop b/c I can't use a variable such as i in the name of the arraylist itself. Been high and low online for a solution...
I'm not sure what you mean with this sentence ?
if you need to check the values of each item in each list, I fail to see any reason why not using a loop.
|
|
|
|
|
What are the advantages and disadvantages of Entity Framework 4.0. What are best scenarios and cases where we should use EF 4.0. Many Experts including Martin Fowler hates ORM , what's your say on this ?
Do you prefer using Microsoft Enterprise Data Block over EF 4.0 ? There is lot of ambiguity while design your application and decide what to use while writing your DAL (data Access layer).
|
|
|
|
|
Not sure why you got downvoted so I countered it with an upvote.
I haven't used EF yet. I had some code that was partial EF and partial plain ADO.Net and I removed the EF and replaced with out sql helpers classes.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
In my experience, if your application is using OOD then I would prefer EF.
|
|
|
|
|
I'm old school so I refuse to work with EF, every time I see it used by other developers I see situations where they simply state that they cannot do something because of the way EF is wired up.
Using multiple databases in one app tends to be a bit of a nightmare as well.
I use a class that was created in the 90s and has had a number of minor modifications (not including change of language 3 times) since. It is lighter weight, more flexible and I know PRECISELY what is happening so I control my data interface.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
shiv Mohan wrote: Many Experts including Martin Fowler hates ORM , what's your say on this ? I think you should ask "why does Martin hate ORM". Hate is a too strong emotion that kills objectivity. ORM's can add value sometimes, for a price. We got some members that passionately hate triggers - but they will not say that they should be avoided at all costs!
As for the DAL, this is very often a layer that functions merely a a door, without adding any value. SQL is already an abstraction layer; you work with an abstraction of records and relations, not with flat files on the system.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy Vluggen wrote: We got some members that passionately hate triggers Guilty
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I successful converted my project from VB to C# than I deleted an Equipment form from my C# project but when I run my C# project the form appeared in debug mode, How to solve this problem?
|
|
|
|
|
Probably, you didn't compile it after removing the form, or the compilation failed.
Did it say something along the lines of "do you want to run the last successful build instead?" and you said "yes"?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
It says "do you want to run the last successful build instead?";
then I press "Yes";
|
|
|
|
|
So...you try to compile it, it can't do it completely because of errors, then you run the "last successful" build and expect it to have your latest changes in it?
Tell me, if you go the the supermarket and don't have any money on you when you try to pay, does the checkout person say "would you like the previous customer to pay for you?" - because that is what you are trying to get the system to do.
When you compile a program, any errors prevent the system from producing a new executable file - so the exe that is run is the last version of your code that had no errors, not the latest version with your changes. In order to run your code with your changes included, you have to look at and fix the errors that the compiler found and told you about.
So what errors did you get?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
WOW Thanks ORIGINALGRIFF;
It's sorted now thanks hey....
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hi all,
i have a .dotx file with some custom property that i have to change by C#. I have downloaded OpenXml sdk library and i just found a way to find all custom properties in a word document but i don't know how edit their value. For example : custom property "Author" with value "Sam" become "Simon".
Any ideas?
Thank you
|
|
|
|
|
|
hello experts,
i am appreciating some help in if then else statement in crystal report.
numbervar x:={ev1.Hpronunciation};
if({ev1.class}="LKG" OR {ev1.class}="UKG") then
(
if(x>=9 and x<=10 )
then
"A+"
else if(x>=6 and x<=8 )
then
"A"
else if(x>=4 and x<=5 )
then
"B+"
else if(x>=3 and x<4 )
then
"B"
else if( x<3 )
then
"C"
else if( x=999 )
then
"AB"
else if( x=0 )
then
"*"
else
"")
else
(
if(x=5 )
then
"A+"
else if(x=4 )
then
"A"
else if(x=3 )
then
"B+"
else if(x=2 )
then
"B"
else if( x<2 )
then
"C"
else if( x=999 )
then
"AB"
else if( x=0 )
then
"*") ;
i am getting correct result for first condition ,but blank result for else ,can any one help me figure out where i am wrong
|
|
|
|
|
You should not be doing this processing in the report, it should be part of your dataset and supplied in the source query/procedure.
A report should only do grouping and totally on a processed data source. there are exception but this is not one of them.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
please check your last condition part in Else that is
Correct code - New code
else
(
if(x=5 ) then
"A+"
else if(x=4 ) then
"A"
else if(x=3 ) then
"B+"
else if(x=2 ) then
"B"
else if( x<2 ) then
"C"
else if( x=999 ) then
"AB"
else "*") ;
instead of
Error in your code - Old code
else
(
if(x=5 ) then
"A+"
else if(x=4 ) then
"A"
else if(x=3 ) then
"B+"
else if(x=2 ) then
"B"
else if( x<2 ) then
"C"
else if( x=999 ) then
"AB"
else if( x=0 ) then
"*") ;
Don't use then in last else portion and remove last else condition that is if(x=0).
|
|
|
|
|
I don't have any conditions but the OP may still have.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi,
I have .NET WinForm application in C# and I will make Web application for it using PHP.
I would like to ask what's the best way to encrypt / decrypt user authentication so it wll work on both WinForm and PHP portal?
I am currently using this in C#:
user_password = cipher_utility.Encrypt<RijndaelManaged>(result, "xxxx", "xxxxxxxxx");
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.IO;
namespace Application_Class_Library
{
public class cipher_utility
{
public static string Encrypt<T>(string value, string password, string salt) where T : SymmetricAlgorithm, new()
{
DeriveBytes rgb = new Rfc2898DeriveBytes(password, Encoding.Unicode.GetBytes(salt));
SymmetricAlgorithm algorithm = new T();
byte[] rgbKey = rgb.GetBytes(algorithm.KeySize >> 3);
byte[] rgbIV = rgb.GetBytes(algorithm.BlockSize >> 3);
ICryptoTransform transform = algorithm.CreateEncryptor(rgbKey, rgbIV);
using (MemoryStream buffer = new MemoryStream())
{
using (CryptoStream stream = new CryptoStream(buffer, transform, CryptoStreamMode.Write))
{
using (StreamWriter writer = new StreamWriter(stream, Encoding.Unicode))
{
writer.Write(value);
}
}
return Convert.ToBase64String(buffer.ToArray());
}
}
public static string Decrypt<T>(string text, string password, string salt) where T : SymmetricAlgorithm, new()
{
DeriveBytes rgb = new Rfc2898DeriveBytes(password, Encoding.Unicode.GetBytes(salt));
SymmetricAlgorithm algorithm = new T();
byte[] rgbKey = rgb.GetBytes(algorithm.KeySize >> 3);
byte[] rgbIV = rgb.GetBytes(algorithm.BlockSize >> 3);
ICryptoTransform transform = algorithm.CreateDecryptor(rgbKey, rgbIV);
using (MemoryStream buffer = new MemoryStream(Convert.FromBase64String(text)))
{
using (CryptoStream stream = new CryptoStream(buffer, transform, CryptoStreamMode.Read))
{
using (StreamReader reader = new StreamReader(stream, Encoding.Unicode))
{
return reader.ReadToEnd();
}
}
}
}
}
}
Technology News @ www.JassimRahma.com
|
|
|
|
|
As has been explained in your previous question, you should never encrypt passwords. Use a one-way hash with a salt value and store that in your database. When someone tries to login you compare the hashed value with what is stored. In that way the passwords are much more secure because they cannot be decrypted. See Secure Password Authentication Explained Simply[^] for details on how it should be done.
|
|
|
|
|
I don't understand why my code snippet below won't find "14" and set the .SelectedIndex? The .Selectindex is always -1.
comboBoxLSKFontSize.Items.Add("10";);
comboBoxLSKFontSize.Items.Add("11";);
comboBoxLSKFontSize.Items.Add("12";);
comboBoxLSKFontSize.Items.Add("13";);
comboBoxLSKFontSize.Items.Add("14";);
comboBoxLSKFontSize.Items.Add("15";);
comboBoxLSKFontSize.Items.Add("16";);
stringLSKFontSize = "14";
i = 0;
foreach (string str in comboBoxLSKFontSize.Items)
{
if (stringLSKFontSize == str)
{
comboBoxLSKFontSize.SelectedIndex = i;
break;
}
i++;
}
|
|
|
|