|
Hi,
when calling printseat on an instance of your print class, you create a new instance of profile; and you store it in a variable named profileupdate however that is completely unrelated to the profileupdate() method.
So probably the profileupdate() method never gets called at all (it is not called by the code shown), hence the postcode shown on the Console will be zero, its initial value.
BTW:
1. rather than waiting 15 minutes before your app ends, it makes sense to perform Console.ReadLine() ; that will have your app wait until you hit the ENTER key.
2. I strongly suggest you choose better names for all variables, methods, properties, etc; a careful choice for each of them makes your code much more readable and will allow you (and others) to more easily see what is going on, and to locate bugs if any.
3. please use PRE tags (e.g. by clicking the "code block" button under the textbox) to show code in a nice non-proportional font while preserving formatting.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
ah yes the waiting is just some thing i added to stop it from closing so i could read it ect it will be changed in time.
im not sure how u mean by calling the profile update method?
profile profileupdate = new profile(); // calls the class profile stores it as a varible called profileupdate
Console.WriteLine("" + profileupdate.postcode + ""); // this calls the class stored in profile update and picks up the postcode varible?
im quite green with c# as you can probably tell
|
|
|
|
|
yes, however you also have this method
public void profileupdate()
{
Console.WriteLine("please enter postcode");
postcode = Console.ReadLine();
}
which never gets called, so postcode will have its initial value of zero.
if you never call it, what is its purpose?
and if you never set postcode to something other than zero, what is its purpose?
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
im inputing my postcode to a varible then calling it in a print class
like a ticket system using inheritance part of a uni project
|
|
|
|
|
Perhaps you meant for the profileupdate method to be a constructor?
Change public void profileupdate() to public void profile() and see what happens.
It has nothing to do with inheritence.
|
|
|
|
|
PIEBALDconsult wrote: public void profile()
too much void.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
But void is nothing, right? I need to get some sleep.
|
|
|
|
|
tried it
im just taking the input im saving to a varible and output it within another class. so i have one class where i ask for the postcode and then when i exit back to the menu i can choose to look in the print class and see what i had inputted
Error 1 'profile': member names cannot be the same as their enclosing type C:\Documents and Settings\Administrator\Desktop\OOPD\OOPD\profile.cs 13 21 OOPD
|
|
|
|
|
|
Ah, so you're instantiating a profile , setting its value, instantiating another one, and expecting it to have the value you put in the first one? It doesn't really work that way.
|
|
|
|
|
oh right thats not good, could you give an example of how i would correct this
|
|
|
|
|
I have a standard class structure for servicing a table, one of the methods is GetRecord (does the obvious, gets the record from the database and populates the fields in the class).
When I inherit the table up the FK tree I get a warning that this method hides an underlying method
hides inherited member 'LimitMgr.clsLimitSet.LimitSetID'. Use the new keyword if hiding was intended
The questions.
1 How essential is it to implement the new keyword in this scenario?
2 Is the app exposed to error or processing faults if the new keyword is not implemented?
3 If I implement the new keyword on all methods, is there an issue when they do NOT hide an inherited method?
I am a great beleiver in elegant and correct code and I dislike having warnings scattered throughout the app, but implementing the new keyword will be a pain so I am trying to asses the impact of not doing the work
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi Mycroft,
You are right to aim for a build without warning messages; so when a warning about hiding, "new" or "override" appears, you should act on it. However you can't just put "new" everywhere.
This is how I understand the situation, assuming a base class and a derived class:
- when a method is not virtual in the base class, it can not be overridden; if it appears in the derived class it needs "new"
- when a method is virtual in the base class, it needs either "override" or "new" and the result is different, see the example.
- when a method is absent in the base class, it should not have "override" nor "new" in a derived class.
public void Test() {
A a=new A();
a.print("A=new A");
B b=new B();
b.print("B=new B");
C c=new C();
c.print("C=new C");
A ab=new B();
ab.print("A=new B");
A ac=new A();
ac.print("A=new C");
}
public class A {
public void some1() { }
public virtual void some2() {}
public virtual void print(string text) {
log(text+" ==> A");
}
}
public class B : A {
public void some1() { }
public virtual void some2() {}
public new void some3() { }
public override void print(string text) {
log(text+" ==> B");
}
}
public class C : A {
public new void print(string text) {
log(text+" ==> C");
}
}
Executing "Test" generates the following output:
A=new A ==> A
B=new B ==> B
C=new C ==> C
A=new B ==> B <-- inheritance
A=new C ==> A <-- no inheritance
illustrating the difference between override and new.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Ya thanks for that info, no matter how you look at it I need to deal with the warning - bugger.
I have a nice simplistic code generator that creates the basic 70% of my crud code and works in isolation for each table, doesn't give a rats about FKs. It may need to get a whole lot more complex b/c I'm dammed if I will add the new keyword manually every time I regen a class!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
It sounds like you're trying to override a method in a base class which doesn't allow polymorphic inheritence; which is all too common in .net and you're right to think twice.
In my opinion, non-polymorphic inheritence (via new) should be avoided. Unfortunately, the only alternative is likely to be wrapping the class and then having to implement all the public methods and properties of the wrapped class, which is a total pain the [wrist].
If you proceed with non-poly-whosis be aware that a user of your class may be able to bypass your implementation and access the base class' implementation; you will need to be sure that this will not leave the instance in an invalid state.
Mycroft Holmes wrote: I am a great believer in elegant and correct code
If only Microsoft was; then methods would be virtual by default.
|
|
|
|
|
PIEBALDconsult wrote: then methods would be virtual by default.
Then that would be a poor design choice.
|
|
|
|
|
That's what they think, others think otherwise.
|
|
|
|
|
PIEBALDconsult wrote: I am a great believer in elegant and correct code
Yeah, yeah I remember "i before e except after c". Spell check does not work on my FF for some reason.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
PIEBALDconsult wrote: If only Microsoft was; then methods would be virtual by default.
They would be called Sun then, wait that is Oracle now.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Now I know that almost all USB barcode scanners type to whatever you have focused...
The problem I am facing is I want to scan something, then it querys a database based upon that barcode scanned. I had just focused a textbox for this, but when I got the scanner today I noticed something that I didn't think about... The scanner doesn't "paste" the data in the textbox. It literally types it out.
So I have a on text change to query the database with whats in the textbox. Is there another way I should be doing this? The length of characters for the barcode we will be scanning is not always the same. So I can't do it based on length of whats in the textbox.
I was wondering if there was a way to read it like you do a serial port scanner and have it not go into a textbox? I have googled and searched for this but have not found anything yet for doing this with a USB barcode scanner.
|
|
|
|
|
If there is not an event or flag sent when the barcode read is compleat then you could always implement something on the textchanged event. Set a flag and a timer when the first char is entered, reset the timer for each change, if the timer reaches 1 second then the last character has been entered. Write the data to the database!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Good idea.. I will give that a try.. although I do have to admit that seems to be kind of a "unreliable" way? I was thinking there would be another way.. but as long as there is no lag in inputing the information it should work great. I will try it out. Thanks
|
|
|
|
|
Most barcode readers provide a prefix and a postfix string, so you can specify text that gets added before and after the scanned data. Putting a unique character or string in the postfix string can be used to detect the end of the input, without waiting a fixed time. When not supported, a time delay seems the best tactic.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Anny decent scanner will let you setup pre- and post-fix character(s) it should add to the barcode when it's scanned. Handle the Form's Keydown event (remember to turn on the Form's KeyPreview!) and you can look for the pre-fix character(s) before any control on your form gets the keystrokes comming from the scanner. If you see the pre-fix character(s), start recording every keystroke until you get the post-fix character(s). Remember to set the e.Handled flag to True while you're seeing the characters you want, including pre-fix, data, and post-fix. When you see the post-fix character(s), you've got your barcode!
You may also want to put some kind of a timeout in this algorithm somewhere so you're not infinitely waiting for post-fix characters you may never see because of some failure of the scanner.
|
|
|
|
|
Dave Kreskowiak wrote: kind of a timeout in this algorithm
See, see my timer did get a look in after all
Never underestimate the power of human stupidity
RAH
|
|
|
|