|
Hey guys, dunno what I am doing wrong here... seems so simple.
Helper Class:
Class Paramaters
{
Public DateTime time = DateTime.Now;
public string formatDate = "MM/dd";
}
The Call:
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = Parameters.time.ToString(Parameters.formatDate);
}
Can anyone shed some light on what exactly I am doing wrong? Thank you.
|
|
|
|
|
taking a punt, since you dont say what error(s) you are getting ..
shouldnt Class Parameters and/or its members be 'public static' ? (else, iirc, you have to create an instance of it)
'g'
|
|
|
|
|
Wrong?? That would mean we need to know what you expected it to do. Whether it works right or wrong is relative to the expected result.
If you wanted the code to fail a certain way, well, then it would be working correctly, now wouldn't it?
|
|
|
|
|
LOL
I understand the concerns. What I have is a huge list of if statements associated with one of my buttons. They all will return this date in some way. Instead of having a million copies of the same code, I want to reference that class so when I change something within that class, it applies to all instances of the code.
The error I am getting is An object reference is require for non-static field, method, or property.
Copying the code
DateTime time = DateTime.Now;
string formatDate = "MM/dd";
textBox1.Text = time.ToString(formatDate);
In each and every if statement seems like it would be a big waste of code and space. I have about 20 buttons or so that would use it, each with 2 if statements attached. I want to just reference that code in a helper class and just have to type something like this:
textBox1.Text = Parameters.time.ToString(Parameters.formatDate);
which would return "03/11" in the text box, for today's date.
I hope this helps clarify my intentions, thanks.
|
|
|
|
|
If you want to use Parameters without creating an instance then the methods/properties/fields you are exposing need to be static. If they are all static, then the class should be static too.
You will have a problem with time if you make it static as it will only be set the first time you call it.
This will fix your problems:
public static class Paramaters
{
public const string MonthDayFormat = "MM/dd";
public static DateTime Time
{
get { return DateTime.Now; }
}
}
textBox1.Text = Paramaters.Time.ToString(Paramaters.MonthDayFormat);
|
|
|
|
|
Worked exactly as intended Dave! Thank you for clearing that up for me.
Time was a misleading description IN this case. However, this was also going to serve as my template for the time stamp portion of my next step.
How can I make Time (one that actually displays the current system time), dynamic? So if I push a button every 5 seconds, it updates the field I am pointing to to the current time?
Gosh not only do I sound like a noob, I am a babbling, confusing... noob.
Edit: Could I have it return my result into the box (or in my literal case, a log.txt file) and then turn around and reset that value?
|
|
|
|
|
No problem!
By using a property as in the code I posted, or using DateTime.Now each time directly rather than a cached field as you were attempting previously.
Edit: If you want to make it a little less wordy to access you could just create a static property or method that does it all for you:
public static class DateTimeHelpers
{
private const string MonthDayFormat = "MM/dd";
public static string NowMonthDayString
{
get { return DateTime.Now.ToString(MonthDayFormat); }
}
}
textBox1.Text = DateTimeHelpers.NowMonthDayString;
|
|
|
|
|
Sorry Dave, didn't realize you had already prevented that from becoming a problem. I just added another private const string to display hours and minutes how I desired, and it works flawlessly, you sir, are a gentleman and a scholar 
|
|
|
|
|
You're welcome
|
|
|
|
|
Class Paramaters
Parameters.time.ToString(Parameters.formatDate);
And also
- or you should instintiate the Parameter class
- or make the members static.
I would also advice in using properties instead of members directly.
|
|
|
|
|
I'm still quite new the WCF Services
School assignments that I done on WCF were writing simple methods of WCF service which accepts strings or int or bool values.
However, I came across this wcf service that wasn't done by myself, and now I am required to write C# client to consume this service.
This WCF has a GetFees method which takes a Student Object as parameter (from WCF's Student DataContract)
See this image for how Student and Fee's datamembers
http://oi47.tinypic.com/wtgap3.jpg
My assignment is to Get Fees of particular students. The information i'm given are
StudentID=1, FirstName=Fernando, LastName=Gadd, Grade=4
StudentID=3, FirstName=Allan, LastName=Pascoe, Grade=1
Currently stuck on how to approach this question, but i'm thinking something like
Fee[] newFee1 = client.GetFees(new Student("1", "Fernando", "Gadd", "4".......
Fee[] newFee2 = client.GetFees(new Student("3", "Allan", "Pascoe", "1".......
Thank you whoever can help
|
|
|
|
|
hi all
i have 2 RFID readers that read active RFID tags ID within range, and i have written the code in c# and it works and reads the tags. each tag represents a device.
i have created a database on MS access provides information related to each tag, such as serial number, location, company,...
ISSUE: i need to insert the tag ID to the database and only update Location coloumn, AOTUMATICALLY. as long as the reader reads the tag the program has to update the location where the rest information will be as they are.
i have 2 readers (reader A & reader B) so that i have to compare the data coming from each reader in order to update the location. if reader A reads the tag ID and reader B doesn't >> location updated to Location A. while if reader B reads the tag ID and reader A doesn't >> location updated to Location B. and if neither of 2 readers read the tag the location will be (OUTBOARD). also if the readers read the tag ID at the same time ( readers range interfere), the location will be (mutual A&B).
readers are real time working, and i need to do the updating aotumatecally & continuously.
I really need help ASAP.
|
|
|
|
|
Basic process
1. Create (learn) how to do database insert and update. This does NOT have anything to do with the reader data. It is just basic knowledge.
2. Use 1 to create an API that creates/updates RFID data. This has NOTHING to do with getting the data.
3. Write code to read from a SINGLE reader and then call the API in 2.
4. Create (learn) two threads. Each thread calls 3. Maybe with a delay or maybe not. Depends on how you tell if the reader has data or not.
|
|
|
|
|
first of all, thank u for ur reply.
second:
1- somebody told me that there is library codes already created to do this purpose, is that true? and where can i find them?
2- i'm not a programmer, unfortunately, so that i really need more explanation.
3- if u don't mind we could communicate on skype or teamviwer,..etc, to discuss these steps.
4- if u mind, can u provide me the best and easiedt references on tutorials?
5- if u know someone is ready to solve my problem and programs it i'll be really thankful.
|
|
|
|
|
Eng.almasrouhi wrote: if u know someone is ready to solve my problem and programs it
You would need to hire a programmer to do this then. Highly unlikely that anyone is just going to do all of this for you for free.
|
|
|
|
|
actually, i'm looking for a programmer to hire. of course i'll pay him but i need to find one first.
|
|
|
|
|
Eng.almasrouhi wrote: i'm looking for a programmer to hire
The you need to go to such a site. This site is not it.
|
|
|
|
|
"I'm not a real doctor. Just relax, you won't feel a thing."
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
Eng.almasrouhi wrote: and i have written the code in c# and it works and reads the tags. each tag
represents a device.
This statement would seem to be at odds with your other post that says you are not a programmer.
Eng.almasrouhi wrote: I really need help ASAP.
Per your other comment that you want to hire someone.
You might want to look to a employment agency and an employment lawyer. Both should have experience with software.
The first provides candidates. The second insures that what you get is what you paid for.
1. You should improve your requirements.
2. Make sure that the lawyer knows that you want to retain ownership of the code.
3. Make sure that the lawyer knows that you want to insure the product works. To that end your requirements will need to state HOW you would determine that.
4. Make sure that hte lawyer knows that will want to provide bug fixes to the code. Or not if you want to try to do it yourself.
Then you just need to find a candidate you like, get them to sign a contract (the lawyer approved one) and then get out your check book.
You probably should pick a local candidate because then you can sue them if they fail to deliver (breach of contract.) Doing that is generally easier if it is local although there are some localities where it is better for you (contractor) than for the (contractee) which is something else you should ask the lawyer.
|
|
|
|
|
what is wrong with this query ?
i cant find them...
i use c# and access database.
command.CommandText = (@"UPDATE Users_Table SET Password= '" + txtNewPassword.Text.ToString() + "' WHERE (Username='" + txtUsername.Text + "' AND Password='" + txtOldPassword.Text + "' )");
command.ExecuteReader();
|
|
|
|
|
What is the error message?
Or why not throw that sql into a string. And then set the .commandtext as this string?
like::
string sqlSelect =
"UPDATE Users_Table SET Password= '" + txtNewPassword.Text.ToString() + "' WHERE Username='" + txtUsername.Text + "' AND Password='" + txtOldPassword.Text + "'");
command.CommandText = sqlSelect;
Also, I did notice an extra space at the time of closing the sql.
txtOldPassword.Text + "' )");
Change to
txtOldPassword.Text + "')");
|
|
|
|
|
the error message is :Syntax error in UPDATE statement.
can i use sql commands when i use access database???
|
|
|
|
|
You can use it. But make sure you specify in the connection string, that the database type is access.
Can you print out the sql in your c# program, log onto access, and try to run the same update statement in access.
|
|
|
|
|
string sqlSelect = string.format("UPDATE Users_Table SET Password= '{0}' WHERE Username='{1}' AND Password='{2}'",txtNewPassword.Text.ToString(),txtUsername.Text,txtOldPassword.Text);
command.CommandText = sqlSelect;
you can also try like this.
|
|
|
|