|
hehe thanks for advice But that's now the case, because that printer is in the school and students shouldn't print anything on it, but we allow them ... And because of that they don't have any grantee that this document won't be seen by somebody else ... Printing on that printer is just like posting your document online so that everyone can see it ...
|
|
|
|
|
Good to hear they have a printing service nearby
I are troll
|
|
|
|
|
Hello all,
I am creating a timer in a background worker thread as shown below and want to pass arguements to the event handler 'timerevent'.
Private Sub DoJob(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
Dim timer1 As New System.Timers.Timer
AddHandler timer1.Elapsed, AddressOf timerevent
timer1.start()
End Sub
but in the timer event handler i can only get something called 'signal time' from the elapsedeventargs.
Is there a way to pass arguments for (in my case a string) to the timer event handler.
Also is the elapsed event similar to the tick event?
|
|
|
|
|
Sohaib_A wrote: Is there a way to pass arguments for (in my case a string) to the timer event handler
You can't change the signature of the Elapsed event. Also where would that string come from?
Timer.Elapsed is raised by timer when the interval has elapsed. So you cannot change the code how Elapsed is raised by the timer.
You can store strings for example in class variables and use them, but without knowing anything more of your scenario, it's hard to say if that would be a feasible solution.
Sohaib_A wrote: Also is the elapsed event similar to the tick event?
Yes, Elapsed is for System.Timers.Timer class and Tick is for System.Windows.Forms.Timer class.
|
|
|
|
|
Ok.
Well the strings are stored in a database.Each background worker will take a different string depending on input from user.
This is how i am doing it.
If reading <= m_WorkerList.Count - 1 Then
str = ds1.Tables(0).Rows(0)("ReaderLocation").ToString
status = api.TcpConnectReader(ds1.Tables(0).Rows(0)("ReaderIP").ToString, _
ds1.Tables(0).Rows(0)("ReaderPort"))
If status = 0 Then
api.TcpCloseConnect()
st = str
m_WorkerList(reading).RunWorkerAsync(str)
reading = reading +1
End If
m_Workerlist is a list of BGW that i have initailized earlier.
|
|
|
|
|
Okay, so you pass a string to the worker when you run it. And the worker uses that string when doing it's stuff. How the timer is related to this? Do you have a timer inside the worker, which then causes some actions? If that's the case, could you simply store the string inside individual workers as a class variable and use that class variable whenever Elapsed event is raised?
|
|
|
|
|
Yes there is a timer inside the worker which is started in the worker's dojob event as shown in the code i posted earlier.
Ok..so is a class variable something like a global variable?And after i pass the string to worker's DOJOB event,i should declare at is a class variable in the DOJOB?
Do you have any examples for this?
All the workers will be running in parallel,so will there be multiple instances of this string each with it own value relative to the back ground worker it was passed from?
|
|
|
|
|
You can inherit the BGW and add the variable into that class. I don't have VB at the moment but the basic idea is simple. I believe that this C# snippet will give you the idea. Instead of : in class definition, you would use inherits also the definition of the variable, constructor and property are a bit different, but not much:
public class MyWorker : System.ComponentModel.BackgroundWorker {
private string _customData;
public MyWorker() : base() { }
public string CustomData {
get {
return this._customData;
}
set {
this._customData = value;
}
}
}
When using it, you would:
...
MyWorker theWorker = new MyWorker();
theWorker.CustomData = "ABCD";
theWorker.RunWorkerAsync();
...
This is one way that you define and set the class variable inside each BGW. Now in the DoWork yuo can get the value using CustomData property getter.
|
|
|
|
|
Hi, I am new to this site and so far it has been very helpful, however, I have a problem.
Here is what I have so far:
If File.Exists("C:\\File.txt") Then
Dim sReader As New StreamReader("C:\\File.txt")
Dim CurrentLine As String
Dim DataLines As New System.Collections.Specialized.StringCollection
Do While sReader.EndOfStream = False
CurrentLine = sReader.ReadLine
If CurrentLine.Contains(txtR1.Text) = False Then
DataLines.Add(CurrentLine)
End If
Loop
sReader.Close()
sReader = Nothing
Dim sWriter As New StreamWriter("C:\\File.txt")
For Each CurrentLine In DataLines
sWriter.WriteLine(CurrentLine)
Next
sWriter.Close()
sWriter = Nothing
end if
As you can see txtR1.text is what contains the string that needs to be deleted from the .txt file. It works and will delete the string from the text file (if it is there). However I want to delete from txtR2.text and txtR3.text as well. Unsure if this is possible, is there a way to combine txtR1, txtR2, txtR3?
Using Vb.net(05)
Thanks!
-Rp
|
|
|
|
|
Welcome to CodeProject
To you question, I think there are number of ways doing this but can't you simply use multiple conditions in your if statement, like:
...
If CurrentLine.Contains(txtR1.Text) = False
Or CurrentLine.Contains(txtR2.Text) = False
Or CurrentLine.Contains(txtR3.Text) = False Then
...
|
|
|
|
|
Hi RPiskami;
Your if statement should use the And logical operator so that if any one of the three are found it will not write that line to DataLines.
If CurrentLine.Contains(txtR1.Text) = False And _<br />
CurrentLine.Contains(txtR2.Text) = False And _<br />
CurrentLine.Contains(txtR3.Text) = False Then<br />
DataLines.Add(CurrentLine)<br />
End If<br />
Fernando
|
|
|
|
|
Thanks Guys! You have been some great help! Now to learn to error check my adding button so that I don't add the same string twice.
-Rp
modified on Sunday, January 18, 2009 5:30 PM
|
|
|
|
|
Here is todays little problem
Usually I would write soemthing like this :
ErrorMessage = "First Line" & vbCrLf & "second Line"
MSGbox(ErroMessage)
- This will produce a two line message
What I need to do is to write the code like this
ErrorMessage = "First Line ??Linefeed?? second Line"
- Notice This is just one continius string not an assembled string as in the original.
MSGbox(ErroMessage) should then also display two lines
How do I do this the most straigh forward way ?
The reason I'm trying to do this is for globalization of our software
This approach would make it easy to translate any error message into another language
thanks
Georg
|
|
|
|
|
Georg Kohler wrote: ErrorMessage = "First Line ??Linefeed?? second Line"
- Notice This is just one continius string not an assembled string as in the original.
But you constuct it programmatically or is this string stored somewhere else? The problem is that I don't see the difference between those two variations is you still create the message text in the program.
|
|
|
|
|
Actually there is a difference - at least it seems to me
ErrorMessage = "First Line" & vbCrLf & "second Line"
' This will produce a two line message
ErrorMessage = "First Line vbCrLf second Line"
' will not produce a two line message
(maybe replacing VBCrlf with something else would also work - but here is my solution so far)
LogMessage = "First Line \n second Line"
LogMessage = LogMessage.Replace("\n", Environment.NewLine)
MSGbox(Logmessage) ' will again produce a two line message
"First Line \n second Line"
is what get's stored as a resource - as you can see it will be easy to
change this into another language as you can add the line feeds wherever you need to.
In my code I also add Variables to the message - again this will allow for easy translation into another language.
A typical error message might look like this
" Error detected in line \VAR1 \n Dublicate \Var2 values detected!"
This might end up looking like this:
.....
Error detected in line 12
Dublicate N values detected!
....
|
|
|
|
|
I think that's a very good solution. I've used that system a lot. The only thing is that you may consider running the replace twice. First put the variables in place and then format the string with newlines. I sometimes have strings in variables that also contain \n. Doing this in two phases also replaces the newlines from variables correctly.
|
|
|
|
|
Hi,
if you want the multi-line string to be a single string in your database or your localized resource,
how about this:
- use a special substring to indicate NEWLINE (e.g. use \n like C/C++/Java/C# do)
- then replace it by actual newline at run-time; in VB.NET that would be
myString=myString.Replace("\n", Environment.NewLine)
I don't know how it would look in ancient VB.
- obviously reading the database/resource and replacing \n would fit nicely in a little method/function.
modified on Sunday, January 18, 2009 5:33 PM
|
|
|
|
|
Actually that's what I ended up doing last night ..
I was just "fishing" to see if there is a different way to do this
I ended up using @LF@ as the string to be replaced by the Environment.NewLine
I have to look int using \n instead - stick to the standard if possible ...
Anyway - thanks for taking the time to answer my question
As always "you guys" haven been great!
Georg
|
|
|
|
|
You're welcome.
|
|
|
|
|
Hi,
I am trying to use the Fill() method of dataAdapter class to fill a dataset but Im getting a SqlException error when I run my code. The error says Invalid object name 'Testing'. My database name is Runner.mdf and Testing is a table in my database. Heres my code. Hope someone can help. Thanks
Dim ds As New DataSet
Dim cn As New SqlConnection()
Dim connString As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents\Runner.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
cn.ConnectionString = connString
cn.Open()
Dim da As New SqlDataAdapter("SELECT * FROM Testing", cn)
da.Fill(ds)
|
|
|
|
|
carrigart wrote: SELECT * FROM Testing
Is this query executing successfully in query browser?
|
|
|
|
|
How do you use the query browser. Is that the same as the object browser.
I'm not familiar with both of them anyway
|
|
|
|
|
Yeah I figured out how to use the query browser and my query is working fine. It returns the contents of my database. Still getting the same error, so frustrating.
|
|
|
|
|
and one more thing, the code executes fine when I comment out the line da.Fill(ds), So is there something wrong with my dataset.
|
|
|
|
|
Do you have the database (runner.mdf) included in your project? If you do, select it from the project explorer and from properties, check two things:
- path to the file
- is Copy to output directory true
If copy to output directory is true, you should attach the database from the projects debug/bin folder, since each time you start the project the db is copied to that folder. Also note that in this case, all modifications done by program are not reflected to the original database, which is included to the project.
|
|
|
|