|
In addition to the above posts, if you have to add a lot of quotes as you are creating a string, I would suggest creating a quote String and then just add it wherever you need a quote.
Dim quoteStr As String = """"<br />
MsgBox(quoteStr + "Hello" + quoteStr)
It makes it easier to read if you are working with lots of strings.
|
|
|
|
|
You can also do Chr(34) where you want the quotes.
MsgBox(Chr(34) & "This is in quotes." & Chr(34))
|
|
|
|
|
But that's just nasty as all hell, obviously.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
|
When I am not in C# I still use the Convert.ToChar(10)+Convert.ToChar(13) for a return/newline character.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios
Discounted or Free Software for Students:
DreamSpark - downloads.channel8.msdn.com
MSDN Academic Alliance - www.msdnaa.com
|
|
|
|
|
Hi All, I am working on a VB.Net and SQL Server application. In order to implement Inter process communication, I am using a FileSystemWatcher object to read a text file, which gets updated by other application. When Application A makes any changes it updates FileWatcher text file which triggers an event in Application B.
But when event occurs, I get following error :
'The process cannot access the file 'C:\Program Files\Pimps\Session\UserSession.ini' because it is being used by another process.'
Can anyone guide me how to implement file sharing by using FileSystemWatcher. Many thanks
Public WithEvents Watcher As IO.FileSystemWatcher
Watcher = New IO.FileSystemWatcher
Watcher.Path = 'C:\Program Files\Pimps\Session' 'File location
Watcher.NotifyFilter = IO.NotifyFilters.LastWrite Or IO.NotifyFilters.Size
Watcher.Filter = "UserSession.ini"
AddHandler Watcher.Changed, AddressOf OnSerializedFileChanged
Watcher.EnableRaisingEvents = True
Private Sub OnSerializedFileChanged(ByVal source As Object, ByVal e As IO.FileSystemEventArgs)
Dim strUser As String = ""
Dim iStart As String
Dim iEnd As String
Dim iType As String = ""
Dim arLine() As String
Dim sr As System.IO.StreamReader = Nothing
If File.Exists(UserInfo) Then
Try
sr = System.IO.File.OpenText(UserInfo)
Dim MyContents As String = sr.ReadToEnd
sr.Close()
sr.Dispose()
arLine = MyContents.Split(Chr(13))
For i As Integer = 0 To arLine.Length
If InStr(arLine(i), "ContactId:") > 0 Then
strUser = arLine(i)
If strUser.Length < iEnd Then Exit Sub
iStart = InStr(strUser, "ContactId:") + "ContactId:".Length - 1
If InStr(strUser, ",") > 0 Then
iEnd = InStr(strUser, ",") - 1
iType = strUser.Substring(iEnd + 1, 1)
Else
iEnd = strUser.Length
End If
ContactId = strUser.Substring(iStart, iEnd - iStart)
If iType = "N" Then 'if a new contact
Me.Invoke(dLoadContact, ContactId)
Me.Invoke(dLoadRecentlyCreatedContacts)
Else
Me.Invoke(dLoadRecentlyModifiedContacts)
End If
Me.Invoke(dMinimizePimps)
Exit Sub
End If
Next
Catch
pimForm.pimMsgBox("Error while reading recent contact list:", Err.Description, frmMsgBox.pimIcon.pimError, frmMsgBox.pimButton.pimYes, "OK")
Finally
sr.Close()
sr.Dispose()
arLine = Nothing
End Try
End If
End Sub
|
|
|
|
|
It's tripping up over the file lock, e.g. while one process is writing to the file, the other process is trying to read it before the first process has closed the fs stream. You need to wait until the file is closed before responding the FSWatcher change event, but this just introduces a whole host of other problems!
I suggest you try using another method for inter process communication here (just type that into google for some options) as there's no easy way to synchronise the file access across 2 processes. Try finding an example that does this using Sockets or NamedPipes or Remoting.
"An eye for an eye only ends up making the whole world blind"
|
|
|
|
|
I will tell you my exact problem.
my project in vb.net is properly working in my machine.
Iam using vb.net2003 bundled with crystal report,which is running.
I want to install my project to my client machine which is Vista.And also that machine not installed vb.net,that i don't want.
But when i installed my project, when i view report keycodev2.dll is coming.
merge module included,registration is also fine
but still error coming.vb.net installed machine was running properly.
Why?? help me
by rani
rani
|
|
|
|
|
|
If you look at his history of messages, almost every question has been asked at least 2x. Some have been asked 3x.
|
|
|
|
|
Hello,
I created a little Windows service with VB.NET 2008 (framework 3.5) that displays a message (I know, that's not very clean, but it's for debugging only...) each time a entry is added in a particular table of a database. The installation of the service succeeded, but when I try to start the service, I get the following message :
---------------------------
Services
---------------------------
The AlertSMS service on Local Computer started and then stopped. Some services stop automatically if they have no work to do, for example, the Performance Logs and Alerts service.
---------------------------
OK
---------------------------
Here's the code :
Public Class AlertSMS
Protected Overrides Sub OnStart(ByVal args() As String)
Dim time As System.Threading.Timer
Dim callBack As New TimerCallback(AddressOf Timer_Tick)
time = New System.Threading.Timer(callBack, Nothing, 0, 50)
MsgBox("Le service surveille maintenant la table Alert...", MsgBoxStyle.Information, "Service démarré")
End Sub
Public Sub Timer_Tick(ByVal state As Object)
'Parcours de la liste des entrées de la table Alert
Dim allalerts As New DAL.AlertCollection
allalerts.Load()
For Each elem As DAL.Alert In allalerts.GetCollection()
MsgBox("Nouvelle alerte : " + vbCrLf + "Message #" + elem.MsgID, MsgBoxStyle.Exclamation, "Attention")
'*** Traitement de l'alerte ***
elem.Delete()
elem.Save()
Next
End Sub
End Class
Thanks in advance
Etienne
|
|
|
|
|
Isn't OnStart supposed to start a loop ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
the loop must start every x milliseconds. that's why it's located in the function that handles the timer. But the problem is partially resolved : I removed the MsgBox from the OnStart function and I moved the declaration of the timer outside of the same function. Now the service starts...and stops 5-10s after !...And it doesn't do what it should do...
Thanks for the answer
|
|
|
|
|
Not sure about this, but I don't think you can call MsgBox from a service unless it's been configured as 'Allow service to interact with the Desktop' or run under a specific user account.
"An eye for an eye only ends up making the whole world blind"
|
|
|
|
|
Hi!
Some thoughts/experiences with services:
1. You can't use message boxes (or any other form of user interaction) from services (unless you check the "allow service to interact with desktop" in the service manager, but that is very bad practice). Use the event log instead (see the example in the documentation for System.ServiceProcess.ServiceBase class in the framework class library). This is probably what causes your service to crash. Make sure neither your service nor the libraries you use rely on user interaction.
2. The System.Threading.Timer class is the right one to use in a service (the Windows Forms timers don't work - they rely on the window message pump, which doesn't exist in a service), but beware that it doesn't work like the Windows Forms timer: Among other things, it continues to fire events even when one is executing, so you have to do some synchronization (or disable and then reenable the timer) in Timer_Tick.
3. An exception on your worker thread (Timer_Tick) vanishes without a trace and the service doesn't stop because of it. Make Timer_Tick very small, containing only a try/catch block that logs any exceptions (and possibly does an Environment.FailFast if things look hopeless) and calls another member that does the actual work.
Hope this helped.
Peter the small turnip
(1) It Has To Work. --RFC 1925[^]
|
|
|
|
|
Hello, i was just wondering if anyone could supply me a bit of code that will automatically pin a program to the computers startup when the program is run for the first time. ....
Thank You, Jared7744
|
|
|
|
|
You'd want to put your shortcut in startup ( this is just in the file system ) or add the path to the Run key under windows in the registry.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi All
I am developing Outlook 2003 Addins using vb.net 2005. and i want to insert the some text in my outlook message at the current cursor position.
How can i do this.
Please suggest.
Thanx
Mitesh Khatri
khatrimitesh@hotmail.com
|
|
|
|
|
Hi,
I am using VB 2008 Express Edition and a beginner in the programming just learning. I own a Internet Cafe so i have created a program for the my cafe. I have a question that inseded of writing down the time in the register just click the start button for the speacifed computer and the timer should run counting and when i stop the stop button which are one button only the text must change near to the button the timer show from 00:00:00 to 01:34:21 hh:mm:ss.
|
|
|
|
|
So what is your question? How to use timers? Post your code and we will try to help.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Public Class System1
Dim timerstat As Boolean = False
Dim count As TimeSpan
Dim CHours As Boolean
Dim CMins As Boolean
Dim CSecs As Boolean
Dim CMSecs As Boolean
Private Sub btnSys1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSys1.Click
If timerstat = False Then
btnSys1.Text = "Stop"
Timer1.Start()
timerstat = True
ElseIf timerstat = True Then
btnSys1.Text = "Start"
Timer1.Stop()
timerstat = False
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
count = Timer1
If CSecs >= 10 Then
CMins = CMins + 1
CSecs = 0
Else
CSecs = CSecs + 1
End If
If CMins >= 60 Then
CHours = CHours + 1
CMins = 0
End If
If CHours < 10 Then CHours = "0"
If CMins < 10 Then CMins = "0"
If CSecs < 10 Then CSecs = "0"
lblTimer1.Text = count
End Sub
End Class
this what i gave the code to my program. The timer must count up as in this format hh:mm:ss as 00:34:05, 00:36:10 like this
|
|
|
|
|
And what does the code give you - apart from (I suspect) a lot of errors?
For example you cannot do arithmetic operations on boolean data types, they are true/false
One bit that will help is the string.format function
lblTimer.Text = string.format("{0}:{1}:{2}",hours,mins,secs)
Rethink your code, make sure it compiles and runs, then I may be able to help you, but I am not going to write it all for you.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Not and error message when i build. I get the error in the form in the lblTimer its showing false:false:false like that
|
|
|
|
|
Thats because your datatypes are boolean. Try using a numeric datatype
Bob
Ashfield Consultants Ltd
|
|
|
|
|
hi friends,
I am trying to fill a string array but i am getting an error as "Object Reference not set to an instance of an object"
Here is my sample code
dim str() as string
dim s as string
For i = 1 To 5
s = SomeMethod()
str(i) = s
Next
Here SomeMethod() is returning a string and i want to assign it to string array str(). Why i am getting above error? What i need to do?
Can anyone help me please.
Thanks,
Nagendra
|
|
|
|