|
firstly I would not check the connection every second, I would only check it just before I upload the file.
I use a function like the following to check if a connection exists :-
Public Shared Function IsWebSiteAvailable(ByVal Address As String) As Boolean<br />
Try<br />
Dim oUrl As New System.Uri(Address)<br />
Dim oWebRequest As System.Net.WebRequest = System.Net.WebRequest.Create(oUrl)<br />
Dim oResponse As System.Net.WebResponse = oWebRequest.GetResponse<br />
oResponse.Close()<br />
oWebRequest = Nothing<br />
Return True<br />
Catch<br />
Return False<br />
End Try<br />
End Function
There I would the code the upload as follows
If IsWebSiteAvailable("www.mysite.com") Then<br />
DoUpload()<br />
Else<br />
MessageBox.Show("Internet connection unavailable.")<br />
End If<br />
Steve Jowett
-------------------------
Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'
|
|
|
|
|
I want to put a Double Quote (") in a string. if I give it in a string, then the string terminates at the position where the Double Quote is put.
Can anybody suggest how to put a Double Quote in a string ?
Thanks In advance.
Sekhar
|
|
|
|
|
Try """".
e.g. "This is a ""TEST"" string"
|
|
|
|
|
Hi,
In regards to your query I would like to inform you that in order to print double qoutes in a sting we have to use two double quotes (e.g., ""). We can print the double quotes in a string as follows:
BEGIN CODE
Dim str As String = "I ""Love"" VB "
MsgBox(str)
END CODE
The output will be I "Love" VB.
I hope this helps .
Regards,
John Adams
ComponentOne LLC
|
|
|
|
|
Use ChrW(34)
Like this:
TextBox1.Text = ChrW(34) & "This is a string." & ChrW(34)
The output would be:
"This is a string."
You can put any character in ChrW(.) by looking at this page: http://www.utoronto.ca/webdocs/HTMLdocs/NewHTML/iso_table.html[^]
As you can see, the double quote char is decimal 34.
http://www.themightyatom.nl
|
|
|
|
|
Can anyone help with the following? I need my Local System Service to check for the time of last user activity on an XP box with multiple logins using fast user switching. I've tried using a .dll (see link at the Imports statement) to hook the keyboard (intending to set a global TickCount variable on KeyDown events) after setting the service to interact with the desktop of the most recently logged in user. I can attach to the process from the VS debugger and step through everything without any error, but the KeyDown handler never gets called. I know the following "snippet" is still quite a bit to wade through but I'm stumped and getting desperate. Anyone see where I'm going wrong - or know an easier way of getting a global "LastInputTicks" value? How do the Windows Power Management routines know when there was last a sign that the user is still alive? Thanks in advance to anyone who spares the time.
<code>Imports WindowsHookLib 'http://www.codeproject.com/KB/vb/WindowsHookLib.aspx?
Friend WithEvents KbHook As LLKeyboardHook
Private Declare Function OpenWindowStation Lib "user32.dll" Alias "OpenWindowStationA" (ByVal lpszWinSta As String, ByVal fInherit As Boolean, ByVal dwDesiredAccess As Int32) As Int32
Private Declare Function OpenDesktop Lib "user32.dll" Alias "OpenDesktopA" (ByVal lpszDesktop As String, ByVal dwFlags As Int32, ByVal fInherit As Boolean, ByVal dwDesiredAccess As Int32) As Int32
Private Declare Function SetProcessWindowStation Lib "user32.dll" (ByVal hWinSta As Int32) As Int32
Private Declare Function SetThreadDesktop Lib "user32.dll" (ByVal hDesktop As Int32) As Int32
'Start the service with a login handler
Protected Overrides Sub OnStart(ByVal args() As String)
Dim objLog As EventLog = New EventLog("Security")
AddHandler objLog.EntryWritten, AddressOf SecurityLog_OnEntryWritten
objLog.EnableRaisingEvents = True
End Sub 'OnStart
Private Sub SecurityLog_OnEntryWritten(ByVal [source] As Object, ByVal e As EntryWrittenEventArgs)
'Only want user login events
If e.Entry.InstanceId <> 528 OrElse e.Entry.UserName.Contains("SERVICE") Then
Return
End If
MakeServiceInteractive()'http://www.codeguru.com/forum/showthread.php?t=238942
'Service then does other stuff on separate threads I'd like to abort when there's no active user
End Sub 'SecurityLog_OnEntryWritten
Private Sub MakeServiceInteractive()
Dim lngDefaultDesktop As Int32
Dim lngWinSta0 As Int32
lngWinSta0 = OpenWindowStation("WinSta0", False, &H37F)
If SetProcessWindowStation(lngWinSta0) <> 0 Then 'success
lngDefaultDesktop = OpenDesktop("Default", 0&, False, &H8L)
If SetThreadDesktop(lngDefaultDesktop) <> 0 Then 'success
KbHook = New LLKeyboardHook
KbHook.InstallHook()
WriteLog("KbHook state: " & KbHook.GetState.ToString())
'I can step through to a log entry of "KbHook state: Installed" so all seems well, but handler never gets hit.
End If
End If
End Sub 'MakeServiceInteractive
Private Sub KbHook_KeyDown(ByVal sender As Object, ByVal e As WindowsHookLib.KeyEventArgs) Handles KbHook.KeyDown
WriteLog(e.KeyCode.ToString & " Pressed") 'never gets called :confused:
End Sub 'KbHook_KeyDown</code>
|
|
|
|
|
I have 2 treeview on my form and I want to add drag and drop functionality from Treeview1 to Treeview2.
I got the sample code from the net.I tried after making some changes in the code and also tried by copying the same code but its not working.
Down is the samle code which I got from the internet.
[Code]
Private Sub TreeViewExample_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
treeTwo.AllowDrop = True
treeOne.AllowDrop = True
End Sub
Private Sub treeOne_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles treeOne.MouseDown, treeTwo.MouseDown
Dim tree As TreeView = CType(sender, TreeView)
Dim node As TreeNode
node = tree.GetNodeAt(e.X, e.Y)
tree.SelectedNode = node
If Not node Is Nothing Then
tree.DoDragDrop(node.Clone(), DragDropEffects.Copy)
End If
End Sub
Private Sub treeTwo_DragOver(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles treeOne.DragOver, treeTwo.DragOver
Dim tree As TreeView = CType(sender, TreeView)
e.Effect = DragDropEffects.None
If Not e.Data.GetData(GetType(TreeNode)) Is Nothing Then
Dim pt As New Point(e.X, e.Y)
pt = tree.PointToClient(pt)
Dim node As TreeNode = tree.GetNodeAt(pt)
If Not node Is Nothing Then
e.Effect = DragDropEffects.Copy
tree.SelectedNode = node
End If
End If
End Sub
Private Sub treeTwo_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles treeOne.DragDrop, treeTwo.DragDrop
Dim tree As TreeView = CType(sender, TreeView)
Dim pt As New Point(e.X, e.Y)
pt = tree.PointToClient(pt)
Dim node As TreeNode = tree.GetNodeAt(pt)
node.Nodes.Add(e.Data.GetData(GetType(TreeNode)))
node.Expand()
End Sub
End Class
[/Code]
Can I body tell me where is the problem in the above code or any sample code which is working will be appreciated.
Thanks in advance
Ejaz
|
|
|
|
|
Sample works fine in my own app. What's not working?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
I tried the same code in vb.net 2003 and it was working but in vb.net 2005 it is not working.In 2005 it is not working.
It is not adding the node in the targeted treeview while dropping.
|
|
|
|
|
How can 'Instance' be best explained in Visual Basic
|
|
|
|
|
roger6897 wrote: How can 'Instance' be best explained in Visual Basic
Well, it depends on what you mean by "instance"?
I'm guessing you mean in terms of object oriented programming (OOP)
An object is an instance of a class. A class is a type.
You create a new instance of a class with the New keyword.
Dim w As Widget = New Widget(someParameter)
w is the reference to the object (the instance of the class.
Widget is the name of the class
New instantiates the instance of the class.
Does that answer your question?
|
|
|
|
|
Hi all, Please help me with this... I'm developing a system using pocket pc.. i can connect to database (sql server mobile (northwind.sdf) - using sqlClientCe).. but at the same time i need to connect to (SQL SERVER - Northwind database)... my problem is.. i cant make any connection to a SQL Server to fetch my datas... thanks in advance..
|
|
|
|
|
Hey all.
I got a problem wih Aaron Eldreth's Real Time SynTax Colorizing tutorial/article. I've posted the problem on his article page, but i don't think he'll respond, since he made his last post in 2004, so i don't think he visits here anymore.
Thats why im posting the exact same issue here in the VB.NET forum hoping that some else has the solution. So here's the original post:
Hi Aaron!
Awesome code! Im using this in my application which is a front end compiler. This compiler creates a log file, and i want to use your code do colorize error messages in that logfile.
But anyway, something strange is happening, check it out: Screenshot
As you can see, something is wrong:
The word "hlcsg is colored yellow, which is working fine. But there's another instance of this word (Current hlcsg settings) in the log which is not colored yellow! Why?"
Also note that the word "estimate" is colored purple, but i haven't added this word to the Keywords on the left! What the.
The words "max texture memory" (below the purple estimate) is not colored at all.
The word "zhlt.wad" is colored red, but the word "wadinclude" is partially colored red, only the first character and the last character of that word is left white (which is the default color) and it not even in the Keywords! Below the second zhlt.wad is another instance of zhlt.wad, but this one is left white, while it should be colored red as well.
The words "discarded from clipping hulls" is colored greenyellow, only the last character of the word "hulls" is left white.
This is really weird, and i can't figure it out.
I guess this has something to do with text encoding, since the log text is actually being read from a .log file on my hard drive.
When i empty the RichtTextBox and start to type in words manually, it works fine.
If you know why this is happening and how to fix this, please tell me how, i would really appreciate it and ill give you credits in my app when i release it.
I hope knows what the problems is, because i can't figure this out. Its so weird.
- Atom
http://www.themightyatom.nl
|
|
|
|
|
You'll notice that further comments also discount the quality of this article due to its poor performance over many lines. This is because the way its done is not dealing with only the visible lines. Perhaps you should seek an alternative syntax coloring method. Not sure exactly what aaron uses, but, perhaps developing your own using Regex would be a good bet. I'd give you my syntax highlighting code but its still under construction, (i.e. only just started 2 days ago).
|
|
|
|
|
Hmmm, i tried RegEx numerous times, but never got it working, its kinda complicated to me.
If you have some code for me that i can use, i would appreciate it, and ill credit you for that.
I've trying to get this (coloring error message in my log file) for several weeks now, without any results. That article by Aaron was the only thing that (kinda works) if i wasn't for the fact that it has poor performance, like you said.
I really need some help. If you can, please do so.
Thanks.
- Atom.
http://www.themightyatom.nl
|
|
|
|
|
i emailed you some stuff, its just a modification of aarons. So no credit for me. I hope it works right for you. If not we will have to keep trying.
|
|
|
|
|
I don't have anything in my inbox.
It might have been removed by the spamfilter.
Could you send it to mdw DOT breddels1 AT hccnet DOT nl instead?
http://www.themightyatom.nl
|
|
|
|
|
I am using a FillBy method to get certain rows from the Table Adapter. How do I get the number of rows that are returned from the query?
|
|
|
|
|
Hi all,
I'm working in a system that was written in VB.NET, and I ran across a function library(gag) that uses the Shared modifier on all of the functions inside it. I know that this modifier is for accessing non-static members using static syntax, but does anyone know exactly what's going on under the hood? Since the function is NOT static, and is in fact an instance member, does a call to a Shared method implicitly instantiate the object, call the function, return the result and then have the implicit object go out of scope for garbage collection? (That's what I think it's probably doing...but I can't find any information to substantiate my thoughts) Does anyone know of anything that can refute this assumption?
"I need build Skynet. Plz send code"
|
|
|
|
|
Hi,
Alaric_ wrote: Since the function is NOT static ...
Wrong AFAIK.
I'm not a VB expert but this is how I understand it:
1. "static" in VB.NET is what used to be "static" in C, i.e. keep a local variable alive inside
a procedure even when the procedure has exited (so it holds its value for the next execution)
2. "shared" in VB.NET is what is "static" in OO languages such as C#, i.e. have class
members that exist only once, and are shared amongst all instances of the class;
and static methods are methods that do not belong to a specific instance, hence can only
access static class members.
So if you have a C/C++/C# background, you should think of "static" whenever you encounter
"Shared" in VB code...
Hope this helps.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Hi Luc,
Yeah, my background is in C, C++, Java, and C#....was thrown onto a VB.NET project to come in and save the day : P
Luc Pattyn wrote: So if you have a C/C++/C# background, you should think of "static" whenever you encounter
"Shared" in VB code...
ok...that's exactly what I was thinking, because that's what you would immediately assume when you see tons of functions being invoked using the same syntactic structure as a static call in any other language....BUT, I saw that there is still a static modifier AND, I found out that yes you can invoke instance members inside a "Shared" function. (Did it just a second ago) ....As soon as I was able to invoke a private instance method, I threw all of the VB documentation out the window that said that "Shared" equated to "static"...because by the very nature of .NET, static members cannot interact with instance members....Does anyone know why VB allows you to do this?
"I need build Skynet. Plz send code"
modified on Saturday, January 19, 2008 6:48:04 PM
|
|
|
|
|
Alaric_ wrote: BUT, I saw that there is still a static modifier
The Static keywork in VB is something different. It lets you declare variables that has method scope but are stored in the class (for static methods) or in the instance (for member methods).
Alaric_ wrote: I found out that yes you can invoke instance members inside a "Shared" function.
Of course you can, if you have a reference to an instance of the class.
Alaric_ wrote: by the very nature of .NET, static members cannot interact with instance members...
Of course they can, as long as you have an instance of the class. If there is no instance of the class, you can't call a member method from a static method.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
The Shared keyword in VB.NET is synonymous with the static keyword in C#. If a method is defined as Shared, it is invoked against the class itself, not against an instance of the class.
Alaric_ wrote: Since the function is NOT static, and is in fact an instance member, does a call to a Shared method implicitly instantiate the object, call the function, return the result and then have the implicit object go out of scope for garbage collection?
If the method is defined as Shared it is a static, not an instance member of the class. The CLR will load an Type object for the class on the Managed Heap so that the method can be invoked. No instance of the class is created on the heap because an object instance is required to invoke a static method. Garbage collection does not apply since there are no object instances to be cleaned up.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Thanks for all of your help,
pmarfleet wrote: If the method is defined as Shared it is a static, not an instance member of the class. The CLR will load an Type object for the class on the Managed Heap so that the method can be invoked. No instance of the class is created on the heap because an object instance is required to invoke a static method. Garbage collection does not apply since there are no object instances to be cleaned up.
...then why is is that a "Shared" function can still be referenced in the context of an instance member? Just as non-static members cannot be referenced in a static context, static members cannot be referenced in a non-static context....or at least, that's the way it's SUPPOSED to be...I don't know why VB devs would have the need to do something different than the rest of the world
Dim manager As Manager
manager.InsertTransactionHeader()
and
Manager.InsertTransactionHeader()
both execute identically if InsertTransactionHeader is declared with the "Shared" modifier inside the Manager class (example is quite contrived, but I think it demonstrates my point)
"I need build Skynet. Plz send code"
|
|
|
|
|
Alaric_ wrote: ...then why is is that a "Shared" function can still be referenced in the context of an instance member?
I usually code in C#, not VB.NET. You can't do this in C#. At a guess this is just syntatical sugar, a feature of the VB.NET language that is designed to make it more 'user-friendly'. Internally, the method will be invoked against the type and not the object instance, because this is where the code resides.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|