|
|
:->
"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
|
|
|
|
|
I appreciate all your help Colin. And I understand what you were saying how it get's better when the programs actually work. The very few programs that I did get to work, it was great, made me think I actually wanted to doing programming. But now, I know these problems are actually simple and me not being able to get them, and spending all week on this is driving me crazy. Even with your help and the professors I don't understand why I still can't get it! I think this is a class I should have tried to take in an actuall class room, to get the one on one, instead of online!
Anyway, I still didn't get it to work. I have to take my exam now, when I'm done, I'll work on it some more, but it's due by midnight tonight, so even if I don't get it to come out right I am still going to turn it in.
Thanks for all your help, you have made some things clearer for me and I truely appreciate that.
Ami
|
|
|
|
|
Ok, this seems basic I know but for some reason it's giving me troubles. I have a checkbox on an asp.net page that gets checked...however, there is no postback going to happen on a button click. My question is how can I get the value of the checkbox without a postback?
I created an event and wired it to my continue button, once fired it does the validation. The client didnt like the fact that the page posted back when the checkbox was clicked (I was saving what was checked on postback). So I created this event.
I am able to get the control and everything, but it's telling me the Checked if false, when I know I checked it.
Here is the code I use to Iterate through the controls to find the checkbox:
Public Function IterateControls(ByVal parent As Control) As String<br />
Dim id As String = ""<br />
For Each child As Control In parent.Controls<br />
If child.GetType().ToString().Equals("System.Web.UI.WebControls.CheckBox") Then<br />
Dim clientid As Integer = child.ClientID.IndexOf("chk")<br />
Dim cid As String = child.ClientID<br />
Dim chk As CheckBox = CType(child, CheckBox)<br />
'**************************************<br />
'THIS RETURNS FALSE EVEN IF CHECKED<br />
'************************************** <br />
If chk.Checked = True Then<br />
'get id of this control<br />
If id = "" Then<br />
id = chk.ID<br />
Else<br />
'already populated<br />
'they checked one too many<br />
'now warn them<br />
Dim lblwarn As Label = CType(Page.FindControl("lblWarning"), Label)<br />
lblwarn.Text = "You can only select ONE (1) Asset at a time!"<br />
lblwarn.ForeColor = Color.Red<br />
chk.Checked = False<br />
Return "-1"<br />
End If<br />
<br />
End If<br />
End If<br />
If child.HasControls Then<br />
IterateControls(child)<br />
End If<br />
Next<br />
Return id<br />
End Function
Anyone have any clue if I am able to capture a value even though there is no postback happening?
VB or C# examples would be appreciated. Thanks
Steve Welborn
Software Engineer
BitWise Solutions
|
|
|
|
|
i can't understand your question clearly but i think your anwser is :
you must first set Autopostback property of the checkbox to the true and then work with
checkedchanged event like this code:
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox1.Checked)
Response.Write("checked");
else
Response.Write("unchecked");
}
|
|
|
|
|
Thanks for the time and reply maryamf.
The problem with this is that I cant have it postback when the user clicks the checkbox. All validation will happen when the client clicks the 'continue' button. I had it working perfectly with the autopostback, however they thought it was distracting having it refresh on each click. And I agree if there are on dialup or something.
So my question was mainly in the validation of the page, via the continue button. I have to Iterate through the controls and find the checked one. However, this needs to be done without postback when user clicks checkboxs. Anyway to get the values of the controls this way?
Hope that made sense.
Steve Welborn
Software Engineer
BitWise Solutions
|
|
|
|
|
Javascript, and go ask in the ASP.NET forum
|
|
|
|
|
thanks for the reply leppie, unfortunatly javascript wont do it either. This needs to be server side because the values I get from the id of the checked checkbox will be used to gather the data on the next page.
I guess to ask it a different way: Can I get the correct value of a checkbox without posting back? What needs to change in the code above in order for this to happen? I can't set the AutoPostBack to true because of the refresh. This event I created takes the refresh away but now I cannot grab the value with the current code.
Come to think of it, I might just forget about doing it the event way and just do all validation in the Continue buttons click event...not sure what client would say but I know it works.
Thanks again leppie for the time.
Steve Welborn
Software Engineer
BitWise Solutions
|
|
|
|
|
hi ,
When I click on my textbox , the cursor always appear at the top of textbox.
i dont want the cursor appear
How can I disable the cursor?
|
|
|
|
|
Disable the textbox.
---
b { font-weight: normal; }
|
|
|
|
|
sorry i didnt understand ,
in my textbox , i draw square using pen class at the top of textbox and later when i click to the textbox , cursor appear so square is damaged
how can i correct this
|
|
|
|
|
If you want a textbox without a cursor, you have to make it non-editable. That you do by disabling the textbox.
If you want to draw on top of a control, you have to do that in the paint event, or whatever you draw will be drawn over whenever the control is updated.
---
b { font-weight: normal; }
|
|
|
|
|
Hey again :P
So I have a XML with DataSet in it, in the DataSet I have 2 DataTables, in each DataTable I have a Uniqe ID, and I did to this row, auto-inc, and don't allow DBNull.
So when I try to do NewRow(), and add it without setting the ID column, it throws an Exception DataColumn 'ID' can't allow DBNull.
So how can I do it as UNIQE ID? do I need to allow DBNull?
|
|
|
|
|
Hi,
i am using tableadapters to insert into 2 different tables the insert methods are in transaction. The first insert must return a value for the second insert. both inserts works just fine if the execution mode of the first tableadapter is nonquery(it doesn't return the @@IDENTITY I need) and if i remove the neccessary forein key in the second table but when i change it to scalar(to get the @@IDENTITY neccessary) it returns the following error. "ExecuteScalar requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized.". can anyone please help.
|
|
|
|
|
Hello.
I can't find a control to check a Regular Expression that I want... so I could check a TextBox.
How can I do it? (or what is the Control for that)
|
|
|
|
|
The control is the RegularExpressionValidator control.
---
b { font-weight: normal; }
|
|
|
|
|
I couldn't find it in the toolbox so I searched it in the "choose items".
When I did OK, it didn't show it in the toolbox, and then I did "Show all items", so it shows it, but I can't drag it or do something with it, it looks like it's disabled...
Maybe you know what can I do?
|
|
|
|
|
Just to make sure: Is it a web application you are working with?
---
b { font-weight: normal; }
|
|
|
|
|
No, it's a win application, that's why I'm posting here and not in ASP.NET forum.
but the other guy helped me.
|
|
|
|
|
That explains it. There is no built-in validation controls for windows forms.
---
b { font-weight: normal; }
|
|
|
|
|
|
Hello,
I've got a table orders with 3 fields:
- date
- productid
- amount
productid & amount are values seperated by commas, f.e.: productid = 1,2 amount = 3,4 (which means there are 3 products "1" and 4 products "2").
Now, I want to select a field by date and get the value of productid & amount and put them in an array (or arraylist?).
Than, I want to fill a datagridview with again 2 colums (amount & productid) with that data.
So for the example the datagridview should look like:
3 1
4 2
This is what I wrote:
<br />
bill.Rows.Clear();<br />
SqlCommand myCommand = new SqlCommand("SELECT * FROM orders WHERE date = @date", connect);<br />
myCommand.Parameters.AddWithValue("@date", DateTime.Parse(listOrders.Text.ToString().Substring(0, 19)));<br />
SqlDataReader myReader = myCommand.ExecuteReader();<br />
while (myReader.Read())<br />
{<br />
amounts = myReader["amount"].ToString();<br />
products = myReader["productid"].ToString();<br />
}<br />
myReader.Close();<br />
<br />
string[] product = new string[products.Split(' ').Length];<br />
string[] amount = new string[amounts.Split(' ').Length];<br />
<br />
product = products.Split(' ');<br />
amount = amounts.Split(' ');<br />
<br />
for (int i = 0; i <= product.Length; i++)<br />
{<br />
bill.Rows.Add(amount[i], product[i], 1, 2);<br />
}<br />
But I always get an error near the product = products.Split ..
System.NullReferenceException was unhandled<br />
Message="Object reference not set to an instance of an object."
I don't really think the code is 100% ok, but can somebody help?
Thanks!
|
|
|
|
|
JelleM wrote: I don't really think the code is 100% ok, but can somebody help?
I've annotated your code with what it is doing.
bill.Rows.Clear();
SqlCommand myCommand = new SqlCommand("SELECT * FROM orders WHERE date = @date", connect);
myCommand.Parameters.AddWithValue("@date", DateTime.Parse(listOrders.Text.ToString().Substring(0, 19)));
SqlDataReader myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
amounts = myReader["amount"].ToString();
products = myReader["productid"].ToString();
}
myReader.Close();
string[] product = new string[products.Split(' ').Length];
string[] amount = new string[amounts.Split(' ').Length];
product = products.Split(' ');
amount = amounts.Split(' ');
for (int i = 0; i <= product.Length; i++)
{
bill.Rows.Add(amount[i], product[i], 1, 2);
}
Does this help you see what your code is doing?
"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
|
|
|
|
|