|
I believe the original poster was talking of the throw keyword by itself, rather than throwing an exception instance:
try
{
}
catch
{
throw;
}
|
|
|
|
|
Hi.
I have used "AxInterop.ShockwaveFlashObjects.dll" in my project.
How can I handle write click on it?
There is't any mouse event for it.
Best wishes
|
|
|
|
|
Hello,
I got a weird problem with an sql string and a datetime field.
First the code:
<br />
SqlCommand myCommand = new SqlCommand("SELECT * FROM orders WHERE date = @date", connect);<br />
<br />
myCommand.Parameters.AddWithValue("@date", DateTime.Parse(listOrders.Text.ToString().Substring(0, 19)));<br />
<br />
SqlDataReader myReader2 = myCommand.ExecuteReader();<br />
<br />
while (myReader2.Read())<br />
{<br />
Messagebox.Show(myReader2["amount"].ToString() + " | " +products = myReader2["productid"].ToString());<br />
}<br />
The table orders exists of a few rows which are added for testing purposes.
Some are added by hand (so in the "show table data" window), others are added by a form with a datetime.now value.
Now the weird thing is that the query gets a result when the date of the row was added by hand, but when the date of the row was added by the other form, it doesn't get a result (so the while loop isn't executed).
I don't understand why this goes wrong?
Can somebody plz help?
Tnx!
|
|
|
|
|
So, the form doesn't insert data? Or it inserts date but not with the values you expect? Either way, it would appear to be a problem with the way that the data is inserted, not with the way it is retrieved.
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
No, it's really weird, I will give you exact copies of the values I find in the date field.
By Hand:
23/10/1986 20:24:23
Inserted data:
26/05/2006 12:39:48
So the data is EXACTLY the same (as far as I know).
That's why I cannot understand it?
|
|
|
|
|
JelleM wrote: So the data is EXACTLY the same (as far as I know).
The problem is that you don't know enough.
The dates you are looking at cuts the time after the seconds and doesn't show the milliseconds. When you compare if two dates are equal, they have to be equal down to the last millisecond. When you take the truncated date that you see and compare it to the date in the database, they will differ by a fraction of a second, but that is enough for them not to be equal.
To get the exact time you need to make the comparision work, you have to display the date with full precision so that you get the millisecons also.
As you see, identifying records by a datetime value is not a very good method. You should use an id instead.
---
b { font-weight: normal; }
|
|
|
|
|
Tnx for the reply!
But the thing is I don't see the milliseconds (if I show the results in the database), so they must be hidden in some way or another.
But can't I use some sort of * to add to the truncated date, so the query doesn't look at the milliseconds or something like that?
TNX!
|
|
|
|
|
JelleM wrote: But the thing is I don't see the milliseconds (if I show the results in the database), so they must be hidden in some way or another.
They are not so much hidden, as they are not shown. If you read the values from the database and display them using a date format that shows the milliseconds, you'll see them.
JelleM wrote: But can't I use some sort of * to add to the truncated date, so the query doesn't look at the milliseconds or something like that?
You could subtract and add a second from the time, and get the records between the times. But then the time is not unique any more...
As I said, using a datetime value to identify a record is not a very good method.
---
b { font-weight: normal; }
|
|
|
|
|
TNX!
|
|
|
|
|
I changed the date-field temporary to a string-field..
What would be the advantage of using a datetime field instead of a string-field?
TNX!
|
|
|
|
|
When ever i set the size of form more than 1036,800...its again resetting to this size only.
It seems this is the maximum size of form.
But i need big form, is there any way...Pls let me know.
|
|
|
|
|
Have you set the maximum size of the form to 1036, 800? What happens when you maximise the form?
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
I think, there is no maximum for the size. I've tried it and it works:
this.Size = new Size(1280, 1024);
|
|
|
|
|
Hi there, my name is Ami. I am currently a student at DeVry University and am taking my first programming class! I am ready to pull my hair out because I can never get any of my programs right and I really want to understand this stuff. (by the way I'm taking C# programming online)
I have a lab that I need help with....I have to design a solution with a Main() method that holds an integer variable named seconds to which I assign a value, create a method to which you pass the value, the method displays the seconds in minutes and seconds (66 sec. = 1 min and 6 sec.)...I go there from hours and so on, if anyone could give a jump start in the right direction I would appreciate it. Thanks, Ami
Ami
|
|
|
|
|
Have you tried DateTime (And it's static members like DateTime.Parse() etc...?)?
turn it to DateTime and it will be easyer then deviding it by 60 and by 24...
|
|
|
|
|
NaNg15241 wrote: Have you tried DateTime (And it's static members like DateTime.Parse() etc...?)?
turn it to DateTime and it will be easyer then deviding it by 60 and by 24...
True, but that is not the point of the exercise. The exercise is trying to teach basic concepts, using examples that everyone will understand, such as how to simple maths in a computer language.
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
Basically this is what I have so far...
using System;
struct Time
{
public Time(int hh, int mm)
{
hours = hh;
minutes = mm;
seconds = 0;
}
private int hours, minutes, seconds;
}
Time now = new Time(12, 30);
Console.WriteLine(now.hours);
Console.WriteLine(now.minutes);
Console.WriteLine(Now.Seconds);
Ami
|
|
|
|
|
betty_boop wrote: if anyone could give a jump start in the right direction I would appreciate it
Well... Lets see what you know, then we can concentrate on teaching you the bits you don't know.
1. Do you know how to create a method?
2. Do you know how to call a method?
3. Do you know simple maths (such as 66 divided by 60, and 66 modulus 60)?
4. Do you know how to create a variable? And assign a value to it?
5. Do you know how to write information to the console? (This lab appears to be a console application)
For every "yes", you are part way to the solution. If you answer "yes" to all, then you need to learn how to put it all together in order to get your program working.
So, what are your answers to the above questions?
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
I am comfortable saying that I know 3,4,& 5 but a lost on 1 & 2
Ami
|
|
|
|
|
Well, looking at your other post, you seem to have a handle on creating struct s (which is a little more advanced than I'd expect)
You create a method inside a class or struct . struct s are rarely used, but for the most part are very similar to a class . They, struct s, are passed "by value" rather than "by reference". Passing by value means that the "value" is copied when it is passed to a method or assigned to a new variable. Passing by reference means that only a reference to the object is passed, not the object itself. This means there is only one copy of the object.
For the rest of this post every time I use class you can also assume it will work with a struct also.
Now, to create a method you need to know some things.
1. What is it going to be called? Typically method names are verbs or verbal phrases. That means they indicate what they are going to do. e.g. CalculateTime
2. What information does the method need to know in order to work? Because a method is part of a class or struct, it will be able to see the information that the class holds. If the class doesn't hold the information that the method needs it will have to be passed in as parameters. So, a method may need parameters.
3. What information is return ed? Not all methods return information, sometimes they just modify the class they are part of. But if a method does return some information you need to know what that is. Is it a string ? An int ? a DateTime ?
4. What can see the method? Is is public , private , protected , internal , or internal protected . Don't worry about all these choices at the moment. The two most common are public and private . public means that everything can see the method, private means that only the class (or other instances of the class ) can see the method.
So here is an example all put together:
public Time CalculateTime(int seconds)
{
}
1. It is called CalculateTime
2. It needs to know how many seconds to use is the calculation. And it needs to know that seconds is an int .
3. It returns a Time object (from the struct I saw in your other post)
4. It is public , which means that anything that has an instance of this class can use it.
The next thing you need to know is how to call the method.
As the method return s something you need somewhere to store that (assuming you are interested in the return value - It is perfectly okay to ignore the return value if you want). In this case we need a variable of type Time .
We also need to know what to pass in to the method. In this case we can use a literal value that is hard coded into the application, but you can use a variable of type int (because that is what the method expects) if you want.
Time calculatedTime = CalculateTime(66);
And that is it.
Does this help?
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
Yes, that does clear things up a little. The actual "struct" that I was using, I'm not allowed to for this assignment(just asked my professor), so I had to redo it. I did set the method to CalculateTime, let me play with it for a minute and I'll let you know what I come up with...thanks for all your help I truely appreciate it!
|
|
|
|
|
|
:->
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
This is what I have, and I know I am totally off. I thought I would like programming, but I have never been so frustrated in my life!!!!!
using System;
public class CalculateTime
{
public static void Main()
{
int s=0, Totalmin=1, h;
int TotalTime = 1, Total;
}
public static void CalculateTime()
{
while (s >= 0)
//calculate min. to sec.
for (s = 0, s > 60, ++s)
if ((s % 60) !=0)
{
TotalTime = TotalTime + h;
Time++;
h = x + 1;
}
}
Total = Totalmin % s;
Console.WriteLine("The time is: {0}", Time);
}
Ami
|
|
|
|
|
betty_boop wrote: I have never been so frustrated in my life!!!!!
Yeah! But it is such a wonderful feeling when it all works out!
Okay - The code you have probably doesn't even compile. Code can only exist within methods (and Properties - but I'm guessing you haven't got that far yet)
First, you are thinking about the whole thing sequentially (which is common for a beginner). Think about calling method like looking up an entry in the dictionary or an encyclopaedia (The methods themselves are like the entry in the book). You don't read a encyclopaedia from start to finish. You jump in where you need to. You might want to read an article about Edinburgh, and it mentiones a famous ex-resident, Sean Connery, and you want to know more so you skip to that entry, and it mentiones James Bond movies so you jump to that entry. The editor that compiles the encyclopaedia isn't going to know what order you want to read in so cannot compile the book in the order Edinburgh, Sean Connery, James Bond. The only sequential things is the normal reading order of the sentences and paragraphs within an entry. In a program the developer doesn't know what order the methods will be called in (typically - your examples are simple enough that you can tell in advance, but when you get to interactive stuff it all depends on the user making descisions at runtime)
Next thing is that a method knows nothing about anything before it was called unless you tell it (by passing in parameters, or if the information is available by calling other methods, from class fields or properties - don't worry about all that just now, at this stage I think concentration on passing in parameters is what your professor is interested in)
Going back to your original description of the problem:
betty_boop wrote: I have to design a solution with a Main() method that holds an integer variable named seconds to which I assign a value, create a method to which you pass the value, the method displays the seconds in minutes and seconds (66 sec. = 1 min and 6 sec.)...I go there from hours and so on,
That means the Main method needs very little
int seconds = 66;
DisplayTime(seconds);
That is all that your Main() method needs.
The more complext thing is creating the DisplayTime() method.
You have a loop which you don't need. Some of the maths may feel a little odd to start with but you'll begin to recognise common patterns soon enough. The trick is to think ahead a little and figure out what you are going to need and see if you can get that a better way - Don't worry, this will start to come naturally once you are practiced more. Which is, of course, the purpose of the exercises you are being set.
There are 3600 seconds in an hour .
hours = seconds / 3600;
There are 60 seconds in a minute, but we also need to discount the hours from the total number of seconds.
remainingSeconds = seconds - (hours * 3600);
The calculation for the minutes is now similar to the hours , but divide by 60 . Then the calcualtion for the remainingSeconds is similar to the one above also, but multiplying your calculated minutes by 60 .
So you now have hours, minutes and remainingSeconds which you can output using Console.WriteLine();
So, hopefully I've given you enough that you can re-write your code so that it gets you closer to your goal.
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|