|
Hi! I have a problem with how my program handles an invalid input.
It goes like this:
Enter string: Apple
Enter integer: 1
Enter string: Orange
Enter integer: 2
Search array: Apple
Search found with string name Apple with integer number 1
Search array: Banana
Search found with string name Apple with integer number 1
Object searchValue = null;
string searchString;
do
{
searchString = GetCorrectInput.String(message);
if (!searchString.Equals("Quit"))
{
for (int i = 0; i < objectArray.Length; i++)
{
if (searchString== objectArray[i].studentName)
{
searchValue = objectArray[i];
}
}
if (searchValue == null)
{
Console.WriteLine("{0} was not found", searchString);
}
else
{
Console.WriteLine("Search found string name {0} with integer number {1}", searchValue.stringName, searchValue.integerNumber);
}
}
} while (!searchString.Equals("Quit"));
Console.WriteLine("Thank you!");
Banana is supposed to be not found but its not
|
|
|
|
|
You forgot to set searchValue back to null. The proper place to do that would be at the top of the loop right after searchString is being set.
Regards,
Manfred
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
is there a way to avoid using null?
|
|
|
|
|
Member 11284734 wrote: is there a way to avoid using null?
Why would you want to do that?
Please explain in detail!
Your code (if it even is your code which I'm now beginning to seriously doubt) uses the check for null explicitly so that would be the way to go.
You could of course use a special instance of whatever class ( it is not shown in your code sample) to signify that the searchString wasn't found, but that special instance also would have to be assigned to searchValue every time somewhere at the top of the loop before coig through the array comparing searchString against studentName .
Regards,
Manfred
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
Apart from resetting searchValue variable to null, I think you also should break out if for loop as soon as you found the matching value in array.
|
|
|
|
|
Any answers are appreciated.
Thanks....
|
|
|
|
|
What Operating System?
With Windows (7) I have been using NET USE to create a mapped drive, COPYing to it, and then using NET USE to /delete the mapped drive.
f:\>net use ?
The syntax of this command is:
NET USE
[devicename | *] [\\computername\sharename[\volume] [password | *]]
[/USER:[domainname\]username]
[/USER:[dotted domain name\]username]
[/USER:[username@dotted domain name]
[/SMARTCARD]
[/SAVECRED]
[[/DELETE] | [/PERSISTENT:{YES | NO}]]
|
|
|
|
|
Hi,
I would like to ask why I am getting the following error on the below code please?
The error is: invalid length for a base-64 char array or string
and this is the code:
string server = cipher_utility.Decrypt<RijndaelManaged>(xmlClass.read_registry("Softnames", "ServerHost"), "{1234567-1234-1234-1234-123456789012}", "{12345678-1234-1234-1234-123456789012}");
Thanks,
Jassim
Technology News @ www.JassimRahma.com
|
|
|
|
|
Probably because the encrypted data has not been stored (or encrypted) correctly. And you would find debugging your code much easier if you did not write compound statements. It is just as efficient, and so much easier to debug, and to read, to write it as:
string encryptedData = xmlClass.read_registry("Softnames", "ServerHost");
string server = cipher_utility.Decrypt<RijndaelManaged>(encryptedData, "{1234567-1234-1234-1234-123456789012}", "{12345678-1234-1234-1234-123456789012}");
|
|
|
|
|
so how to go with the fix?
Technology News @ www.JassimRahma.com
|
|
|
|
|
What fix? Your encrypted data is either incomplete or has been corrupted. You need to diagnose the issue to find out how that happened.
|
|
|
|
|
I can't explain it properly in the subject section, it's not as simple as that.
Here is the code snippet in question.
UserPass = reader["Password"].ToString();
So UserPass is my string variable and reader is an SqlReader object.
Here is it being instantiated:
SqlDataReader reader = myCommand.ExecuteReader();
(myCommand is an SqlCommand obj)
reader["Password"]
Password is a column name in my Sql DB. Basically I've just told the reader to go look within that column and used a query to specify where abouts.
I want to set the reader["Password"] equal to an empty string to compare against user input. Now there aren't any errors when I do this but it does throw an exception:
An exception of type 'System.InvalidOperationException' occurred in System.Data.dll but was not handled in user code
It doesn't give much more detail other than that and I'm not entirely sure what's wrong.
|
|
|
|
|
Nothing you provided looks obviously wrong. Which statement throws the Exception? We may need to see the query.
And provide the code in proper order.
modified 3-Dec-14 14:47pm.
|
|
|
|
|
did you debug to identify on which line you had the issue?
Mark the answer as accepted if that worked for you .
And for down-voters please specify the reason to improve the solution .
|
|
|
|
|
HI...
I am beginner in WPF and I have a problem with saving data from DataGrid to text file (text file is usedby other program). I check on google, bing and find nothing. Please help.
|
|
|
|
|
I'd suggest you post your code and show where you are stuck.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Member 10024517 wrote: I have a problem You need to explain clearly what that problem is if you want assistance.
|
|
|
|
|
I will paste my code later, but what I want is to save (export) data from data grid to text file. For example we have few columns number|data|description|date|img with few rows. Then I want to save that to text file in format
number///data///description///date//img (one row for one line in text file).
|
|
|
|
|
Could you recommend me a method how to create a hotel room booking calendar like this?
http://www.daypilot.org/tutorial/hotel/[^]
I have two ideas and I tried to create the calendar, but I have problems with it.
1. idea: Create a DataGridView. It is good because there are cells and header cells in it, it is scrollable, but I can't insert controls in the cells (button or panel) which would show the reservations through days (like in the example) because column span is not supported by the datagridview.
2. idea: Use a TableLayoutPanel. It supports column spanning and I can insert any type of Control in its cells, so I can insert controls which shows the interval, name, etc.. of the room reservation and it can overlap many cells. The only problem is that I have to create row headers and column headers. I created another tablelayoutpanel over the table, it would be the column header. The header would horizontally scroll simultaneously with the main table, but if I turn autoscroll on, the scollbar is visible and it is not good. If I turn off autoscroll, I can't scroll the panel from code. It would be good if I could create an independent hscrollbar and in it's scroll event I could set the header and main tablelayoutpanels scroll position simultaneously.
Have you any ideas?
|
|
|
|
|
|
Thank You! These articles are goood. Unfortunately, column spanning is still a problem.
|
|
|
|
|
Are you doing this as an on-line project hooked up to a DataBase in ASP.NET ... your use of 'TableLayouPanel suggests this is a WinForms project, while 'DayPilot is meant to be used on-line ?
Do Note that DayPilot has an open-source ASP.NET "lite" version, and a MonthPicker version available for download: [^]. You might get some good ideas studying their source code ?
My experiments with the WinForm TableLayoutPanel a few years ago found it got really slow in scrolling when trying to implement lots of Controls in lots of rows, and columns. But, maybe that was related to my using slow hardware.
Why couldn't you use Row #0 to hold Column Names, and Column #0 to hold Row Names ?
«OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. » Alan Kay's clarification on what he meant by the term "Object" in "Object-Oriented Programming."
|
|
|
|
|
Thanks for answering! I am making a windows forms application. I haven't studied the daypilot's source code because it is an ASP.NET control. After your suggestion, I think tablelayoutpanel is not a good solution. So I should add a control (button or panel) to a datagridview, but that control should overlap many cells if the reservations are longer then one day.
|
|
|
|
|
KissGnv wrote: After your suggestion, I think tablelayoutpanel is not a good solution Please, note that I did not directly advise you to avoid using a TableLayoutPanel; I simply told you about my experience a few years ago with it.
I strongly advise you to check out Jing Lu's open-source ReoGrid Control which has an article on CodeProject here: [^], and a web-site here: [^]. ReoGrid does everything but walk your dog, and is very, very fast. Note that the license model for ReoGrid may have changed, on the article on CP it's LPGL; I have written Jing asking him to clarify the current license model.
Why not create a prototype to test, on the type of hardware you'll run your app on, that loads a TableLayoutPanel with as many Controls with synthesized sample data as you think you might need a maximum of, and then observe the speed of response.
Here's some code I used a few years ago: [^]. I suggest you increase the integer Constants that control the number of Rows, and Column, and observe the performance as you scroll.
To use the code in the linked to archive: 'unRar it, and copy-paste the code in Form1.cs, and LabelEx.cs into:
0. create a new WinForms project, set the Main Form, 'Form1 'DoubleBuffered property to 'true. Size the Main Form to taste. Replace its code with the code in the archive for 'Form1.cs.
1. add a Component named 'LabelEx to your Project: replace its code in the file from the archive 'LabelEx.cs.
2. On the main Form: put a TableLayoutPanel named 'testTbl: size it and set its various properties appropriately. Put a Button on the Form named 'btnCreateLayoutPanel, and set its 'Click EventHandler to use the code in 'Form1.cs.
«OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. » Alan Kay's clarification on what he meant by the term "Object" in "Object-Oriented Programming."
modified 3-Dec-14 19:10pm.
|
|
|
|
|
Grids are generally a Very Bad Idea as a user interface. They can be OK in some limited instances with small amounts of data that aren't being changed often -- and with knowledgable users.
One application I tried to use a Grid for I found it completely unmanageable -- so I used a TreeView instead and suddenly everything was suddenly simple.
In either case, I prefer having the primary form display only the highest level data for each entry, then allow the user to select an entry and open a separate editing form with the details of that one item. Don't try to show everything in one place, and don't try to allow editing of everything with one giant Grid.
If you had to use the system eight hours a day with calls and guests coming in constantly, which would you prefer?
How about go to some local hotels and see what they use, what it looks like, what the users like and dislike?
|
|
|
|