|
But did you build a fully qualified path to the file?? If you just specified the filename for the text file and not the full path to the file, you can run into issue like you've described.
|
|
|
|
|
|
Hello Experts,
I don't know what is com Port. And How to Connect PC to Hardware using Com Port.
IS RCID is related with us.
Actually i want to get Help for com port.
I think i submit the question in right side.
Thanks
If you can think then I Can.
|
|
|
|
|
How can you possibly write code to handle a COM port when you don't even know what it is or what you're doing with it??
|
|
|
|
|
Com Port is usually a 9 pin D port at the back of your pc, as so known as a Serial Port, using the RS232C standard. I is usually used to comunticate with other hardware devices such as weighing scales, clocks and back in the day, mice and modems. They are largely being superceded with USB devices.
VB.NET includes a SerialPort component.
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
Thank you Sir,
What is the Relation of RFID to Com Port.
If you can think then I Can.
|
|
|
|
|
You need to explain what you mean by RFID. Radio Frequency Identification?
It's just another serial device. How you communicate with the device, how to format the data you send and how the data your receive back should all be in the manufacturers product manual.
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
Hello All,
I have called PrintDocument.Print() method to print given document.
How to check given print is success or not.
Regards,
Sri
|
|
|
|
|
Normally, you don't. Normally, once your app prints it, your app shouldn't care at all about the job. The job may get hung up in the queue for various reasons, including being about 20th in line to print, none of which are the responsibility of your app to report. It may be an hour before the job actually makes it to paper, even if theres nothing wrong. Those conditions are left up to the printing system to report to the user, not your app. Normally...
What is your app doing that you feel the need to know if the doc printed or not?
|
|
|
|
|
Thanks Dave,
My application is printing checks. Before printing check number is saved to database. If print fails at any reason (Paper Jam,Paper Out,Not connected...etc) i nedd to update database with default check number "000000". Thats why i need print staus of check.
Dave, Can you please give me idea to get the status.Please
Thanks,
Sri
|
|
|
|
|
You'd have to get the information using the classes in the System.Printing[^] namespace. This is oknly available in .NET 3.0 and above.
If you're using .NET 2.0 and below, you'd either have to use WMI and the System.Management namespace to do something like this, or implement printing directly to the printer without going through the print spooler. You can find an example of that here[^].
|
|
|
|
|
How to sort the following list,
nodes is my list
tv is my treeview
Now I'd like nodes to sort.
Dim nodes As New List(Of TreeNode)
Dim queue As New Queue(Of TreeNode)
Dim top As TreeNode
Dim nod As TreeNode
For Each top In Tv.Nodes
queue.Enqueue(top)
Next
While (queue.Count > 0)
top = queue.Dequeue
nodes.Add(top)
For Each nod In top.Nodes
queue.Enqueue(nod)
Next
End While
Thanks!
|
|
|
|
|
Why do you use a Queue? the main purpose of a queue is to act as a pipe where things get added on one side, stored, and removed on the other side, which inherently means their order is always preserved.
What you need is another kind of collection, such as a simple List<treenode>, on which you can call Sort(). Then provide a Comparer to explain how you compare two TreeNode instances. This[^] explains and illustrates it.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Hi,
I am trying to write a vbscript which should give the difference between to given excel sheet. I am actually updating a excel sheet i.e adding a row somewhere in between. I want to vbscript show only the added row as the difference.
Any help will do a lot.
Thanks in advance for your help.
|
|
|
|
|
In general, if I start a thread in sub-1 that will thread sub-2...
when sub-2 runs (and sub-1 may never run again), once sub-2 has completed, can I start the sub-2 thread at the end of sub-2 before it finishes?
In other words, sub-1 started the thread for sub-2, then sub-1 ends.
Sub-2 runs and I want it to run over and over in the background..
So can I initiate the sub-2 thread from within (at the end of) sub-2?
Can a sub call its own thread?
Hope I made it clear?
Thanks
|
|
|
|
|
crashcup wrote: Hope I made it clear?
No you didn't; actual code would be easier to understand.
crashcup wrote: Can a sub call its own thread?
That doesn't make any sense. Nothing can call a thread; a thread executes code.
Yes a method A can start a thread that runs method B.
and yes a method A can start a thread that runs method A (Some kind of recursion, dangerous, and most often not very sensible).
If some code needs to run all the time, why not run it in a loop (possibly by one thread)?
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Message Closed
modified 5-Dec-16 6:40am.
|
|
|
|
|
you seem confused.
A method is like a job, a piece of work that needs to be done.
A thread is a worker, something that performs a job.
A process start off having a single thread, and starts executing your Main() method.
You can write:
public void someJob() {
while(!done) {
doSomething();
}
}
and now you can let your main thread execute someJob() by simply calling it.
Or you can start one more thread that executes someJob(), which causes doSomething() to run forever (or until done is set true).
That is the scheme you most often need, e.g. when dealing with TCPListener. No need to create threads all the time.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Thanks, no confusion here as I've been programming for years, just not in .Net.
I'll accept Daves answer as it relates directly to my question about subs started by a thread.
|
|
|
|
|
yes you are confused, and your vocabulary is wrong.
threads don't start a "sub", in fact there are no "subs".
it is code (inside methods) that start some Thread, then the thread executes the code in the method given to it.
Also what Dave and I are telling you is basically the same. Use a loop. I have shown you code that does that.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Hmm still no confusion here.
As you can see below the Sub Read() is indeed started by a thread.
And the Read Sub is started from whthin itself.
The program works fine.
And there are Subs as I have 3, 'connect', 'send', and 'read'.
My vocabulary is correct.
These are also considered methods I suppose. But VB calls them Subs or Functions.
Sub procedures are methods which do not return a value.
Function is a method which returns a value.
---------------------------------------------------------------
Public Sub connect(ByVal IP, ByVal Port)
Try
'ccSocket.Connect("127.0.0.1", 2000)
ccSocket.Connect(IP, Port)
Catch ex As Exception
End Try
myThread = New Thread(AddressOf read)
myThread.Start()
End Sub
Public Sub send(ByRef q)
'Dim outStream As Byte() = System.Text.Encoding.ASCII.GetBytes("connect")
'serverStream.Write(outStream, 0, outStream.Length)
'serverStream.Flush()
'Dim serverStream As NetworkStream
Try
serverStream = ccSocket.GetStream()
Dim sendBytes As [Byte]()
sendBytes = Encoding.ASCII.GetBytes(q)
serverStream.Write(sendBytes, 0, sendBytes.Length)
Catch
End Try
End Sub
Public Sub read()
'myThread = New Thread(AddressOf read)
'myThread.Start()
' Read the NetworkStream into a byte buffer.
Dim bytes(ccSocket.ReceiveBufferSize) As Byte
Try
Dim serverStream As NetworkStream
serverStream = ccSocket.GetStream()
serverStream.Read(bytes, 0, CInt(ccSocket.ReceiveBufferSize))
' Output the data received from the host to the console.
Dim returndata As String = Encoding.ASCII.GetString(bytes)
''Console.WriteLine(("Host returned: " + returndata))
DataIn = returndata
Catch ex As Exception
End Try
Try
If Asc(DataIn) = 0 Then
myThread.Abort()
DataIn = "Connection Closed"
End If
Catch ex As Exception
Exit Sub
End Try
Try
myThread = New Thread(AddressOf read)
myThread.Start()
Catch ex As Exception
End Try
End Sub
modified on Monday, November 9, 2009 5:53 AM
|
|
|
|
|
Luc Pattyn wrote: You can write:
public void someJob()
{
while(!done)
{
doSomething();
}
}
Does that work in VB.NET?
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
what have you tried so far?
did you check the documentation?
ask Google!
hint: probably not, not enough capitals used.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
A thread doesn't call "it's own sub" as threads are not limited to a single sub, as you put it. You setup a loop inside the sub to keep itself running until some bailout condition is met. Using Thread.Abort is a poor choice to end a thread.
|
|
|
|
|
You wrote " A thread doesn't call "it's own sub""
I have done just this and things seem to work ok, or have I inadvertently started a memory leak?
You wrote "You setup a loop inside the sub to keep itself running until some bailout condition is met."
So to clarify, I guess you are saying once a sub is started as a thread, inside that sub, if you want it to continue to run (like TCPListener) keep looping as long as you want it to listen.
"Using Thread.Abort is a poor choice to end a thread."
As an aside, what is the proper method to terminate the thread and can it be terminated from within the 'threaded' sub?
|
|
|
|