|
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
|
|
|
|
|
I actually went with your timer theory and it seems to be working well. I haven't tried the others since I haven't learned out to append prefix and postfix strings. It was on the cheaper end around $100 scanner (HP LS2208-SR20361R)
|
|
|
|
|
hi
i came across the same sencerio as u, but its really easy
by using textbox KeyUp event, my scanner sends the
barcode data plus 'enter key'. so it got simple
private sub txt_barcode(byval sender as object, byval e as keyeventargs) handles txt_barcode.keyup
if e.keycode = key.enter then
dim barcode as string = txt_barcode.text.trim
.............
'lookup the database and pull the data
.....................
end if
end sub
|
|
|
|
|
I will have to try that! I think I was trying to look for that enter on a key down event before... Not a key up
|
|
|
|
|
Hi! I have made a Client and a Server applications. I want to send a file from the Server to the Client. This is how I do it:
<br />
ns is a NetworkStream which is connected.<br />
writer is a StreamWriter.<br />
<br />
The Srever:<br />
<br />
FileStream fs = File.OpenRead(path);<br />
long byteCount = fs.Length;<br />
writer.WriteLine(byteCount);
writer.Flush();<br />
int readBytes = 0;<br />
byte[] buffer = new byte[1024];<br />
while (readBytes < byteCount && ns.CanWrite)<br />
{<br />
int length = fs.Read(buffer, 0, buffer.Length);<br />
ns.Write(buffer, 0, length);<br />
ns.Flush();
readBytes = readBytes + length;<br />
}<br />
<br />
The Client:<br />
<br />
FileStream fs = File.Create(Application.StartupPath + "\\buffer.nkl");
long byteCount = long.Parse(reader.ReadLine());
int readBytes = 0;<br />
byte[] buffer = new byte[1024];<br />
while (readBytes < byteCount && ns.DataAvailable)<br />
{<br />
int length = ns.Read(buffer, 0, buffer.Length);<br />
fs.Write(buffer, 0, length);<br />
readBytes = readBytes + length;<br />
}
The problem is that the received file is trimmed - it isn't whole (sent file is 198 kb, received file is 23 kb). If I remove ns.DataAvailable it takes a long time and the file is almost complete (sent file is 198 kb, received file is 196 kb).
What am I doing wrong???
Still learning...
|
|
|
|
|
Hi,
you shouldn't give up once ns.DataAvailable is false, that could happen any time: maybe the server is temporarily busy (say waiting on disk I/O, serving other clients, ..) or the client has a more powerful machine, hence it would run ahead.
A better approach would be for the client to either just ignore ns.DataAvailable (now the client would hang if the server exits unexpectedly) or allow for a later retry (say when false, wait 100 msec and try again) which increases the odds, but exits gracefully when the communication really goes wrong.
If it goes wrong, add some logging statements to both server and client so you can see where it fails.
Example: Console.WriteLine("server: readBytes="+readBytes);
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.
|
|
|
|
|
When the download is complete I can enter other commands to the server. If I have ns.DataAvailable, when I enter the command to my server to disconnect (the server should return "Disconnected") I receive a part of the transferred file (several words from it). As if there is still data in the stream.
But when the ns.DataAvailable is absent from the while loop, when I enter the command for download, the download begins but never ends. I have to close the client and then the buffer file is at 196 kb.
I am testing the application on my computer - both the client and the server (for an IP I am using localhost) so there shouldn't be a difference.
Still learning...
|
|
|
|