|
i write a Module as follows
<br />
Imports System.Runtime.InteropServices<br />
Module modGetWinMsg<br />
Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Integer, ByVal lpfn As GetWinMsgDelete, ByVal hmod As Integer, ByVal dwThreadId As Integer) As Integer<br />
<br />
Private Declare Function CallNextHookEx Lib "user32" Alias "CallNextHookEx" (ByVal hHook As Integer, ByVal ncode As Integer, ByVal wParam As Integer, ByVal lParam As MSG) As Integer<br />
<br />
Private Declare Function UnhookWindowsHookEx Lib "user32" Alias "UnhookWindowsHookEx" (ByVal hHook As Integer) As Integer<br />
<br />
Private Const WH_GETMESSAGE As Integer = 3<br />
<br />
Private Const WM_PASTE As Integer = &H302<br />
<br />
Dim hRet As Integer<br />
<br />
Private Structure MSG<br />
Private hwnd As Integer<br />
Private message As Integer<br />
Private wParam As Integer<br />
Private lParam As Integer<br />
Private time As Integer<br />
Private pt As POINTAPI<br />
End Structure<br />
<br />
Private Structure POINTAPI<br />
Private x As Integer<br />
Private y As Integer<br />
End Structure<br />
<br />
Private Delegate Function GetWinMsgDelete(ByVal nCode As Integer, _<br />
ByVal wParam As Integer, _<br />
ByVal lParam As MSG) As Integer<br />
Private Function proGetWinMsg(ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As MSG) As Integer<br />
If nCode = 0 Then<br />
If wParam = WM_PASTE Then<br />
MessageBox.Show("asdfsad")<br />
Return 1<br />
End If<br />
Return CallNextHookEx(hRet, nCode, wParam, lParam)<br />
End If<br />
End Function<br />
Public Sub GetMsg()<br />
hRet = SetWindowsHookEx(WH_GETMESSAGE, AddressOf proGetWinMsg, Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32, 0)<br />
End Sub<br />
Public Sub Unhook()<br />
If hRet <> 0 Then<br />
UnhookWindowsHookEx(hRet)<br />
hRet = 0<br />
End If<br />
End Sub<br />
End Module
Then i use it in form as follows
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
GetMsg()<br />
End Sub<br />
<br />
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing<br />
Unhook()<br />
End Sub
But i cann't make it right work.Why?
|
|
|
|
|
Hi Guys!! I need a function which can return me the free disk space of any drive for my Project of Bit Torrent Client in .Net. Thanx. Cya!!
Also i need to know how can we initialize all the elements of an array while declaring it. This is coz when ever i give Dim strArray() as String
and later when i use any element like: strArray(0) = "something"
i get an error on strArray saying that the array is beeing use before it can be be assigned a value. Plz help, What should i do???
Devraj Raut!!!
|
|
|
|
|
You declared an object as a pointer to an array, but you failed to tell the compiler how big to make the array:
Dim strArray(40) As String
will give you an array of 40 empty String objects.
Or, to expand on your code example, you could use something like this:
Dim strArray() As String
ReDim strArray(new size)
strArray(elementNumber) = "something"
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
As for your Free Disk SPace problem. Google is your friend! Learn to use it. There's about a 245,000 hits when searching for "VB.NET get drive free space".
Click this[^] for an example.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
what is the role of module in vb.net?how it is used?
|
|
|
|
|
It's a deprectaed concept in VB.NET. It still works, but is merely a compatibility thing for VB6 code.
It was usually used as a function library that could be called from anywhere in your VB6 code.
In VB.NET, it's preferable to use Shared methods in classes instead of Modules.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Like Dave said, a Module is just a place to hold public functions and members. It is not a class. You can't make objects out of it. Its functions are directly accessible from the rest of your code, kind of like how the C language does it.
Public Module Foo
Public Sub Test()
End Sub
End Module
Public Class Bar
Public Sub Main()
Foo.Test() ' Can be called like this.
Test() ' Or like this, without specifying the module name.
End Sub
End Class
The problem with Modules in VB.NET is that all of their public members and methods will pollute your namespace. This really crowds intellisense. Because of this, I don't recommend that you use them.
|
|
|
|
|
Hello; can you help about how can i create crystal report in VB 6.0
thanks
|
|
|
|
|
In VB6 when you do
set frm2 = new Form2
frm2.show()
do you have to delete memory etc like in c++
|
|
|
|
|
yes.its good if you do.
set frm2=nothing
Kanchana
|
|
|
|
|
|
Setting the object to Nothing when you're done with it is good practicec, but not mandatory. The VB runtime will clean up objects that fall out of scope for you.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
VB6 is a memory managed language. There is no "delete".
The object will be deleted as soon as it's no longer referenced. This can occur when the last reference goes out of scope or is set to Nothing. And, unlike Java and .NET, the class' destructor will immediately be called just like how it is in C++.
Forms are treated a little differently in VB6. You can "mostly" force them out of memory by calling Unload like this...
Unload frm2
Once you do this, you can't use frm2 again. So in this case, you might as well as set it to Nothing, replace it with a new form reference, or just let the variable go out of scope.
|
|
|
|
|
how about connection and recordset object? Do we need to call the close method and set the object to nothing?
When to call open and close method of connection and recordset object in a procedure/function with try catch? Is it ok to put in "finally" ?
Thanks
WiL
|
|
|
|
|
shiroamachi wrote: how about connection and recordset object? Do we need to call the close method and set the object to nothing?
You absolutely must Close them. You do not have to set them to Nothing. They'll be removed from memory as soon as they go out of scope.
shiroamachi wrote: When to call open and close method of connection and recordset object in a procedure/function with try catch? Is it ok to put in "finally" ?
Uhhh... VB6 doesn't have try/catch functionality. Sounds like you're talking about VB.NET. If you are, then Finally is a good place to call Close.
|
|
|
|
|
my bad. topic starter talking about VB6. I'm asking about VB.Net
is there a way to check a recordset is open or not ?
here's a case
try<br />
dim con as connection<br />
dim rs as recordset<br />
con.open()<br />
rs = con.execute(sqlstring)<br />
<br />
catch ex as Exception<br />
<br />
msgbox "error"<br />
exit sub<br />
<br />
finally<br />
<br />
rs.close()<br />
con.close()<br />
<br />
end try
assume there's error in con.open() and the error was catch and then do finally. in finally, because of rs is not yet open, will cause error cant close object that isnt open. How to resolve this problem?
Thank
WiL
|
|
|
|
|
shiroamachi wrote: assume there's error in con.open() and the error was catch and then do finally. in finally, because of rs is not yet open, will cause error cant close object that isnt open. How to resolve this problem?
First, put the DIM statements before the Try since the variables won't have scope outside the Try block.
Second, in the Catch block determine whether or not the Connection object is open by using something like this:
if con.State = adStateOpen then
con.Close()
end if
I did this from memory so you'll need to check the exact syntax.
...Steve
"Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." (Translation: I'll show you the way, but not write the code for you.) I read that somewhere once
|
|
|
|
|
I believe the "adStateOpen" constant is from VB6's ADO.
In ADO.NET it should be like this...
If (con.State <> ConnectionState.Closed) Then
con.Close()
End If
|
|
|
|
|
I am using a windows form datagrid and a datatable is used as the datasource.I want to prevent deletion of the first row.I tried with datatable's rowdeleting event.But i was not able to reject the changes.Can any one help.I'm pasting the code that i tried
Private Sub DataTable_RowDeleting(ByVal sender As System.Object, ByVal e As System.Data.DataRowChangeEventArgs)
If e.Action = DataRowAction.Delete Then
If dgGrid.CurrentCell.RowNumber = 0 Then
e.Row.RejectChanges()
CType(sender, DataTable).AcceptChanges()
End If
Else
e.Row.AcceptChanges()
End If
End Sub
Anup
|
|
|
|
|
can I upload data to a server from a vb.net windows-app? I know how to upload but I don't know how to LOG into my ftp server to upload file. please it's important
|
|
|
|
|
ok.I found the solution.bye
|
|
|
|
|
Hello All
I want to manually enter items in the combox as:
cbo.Items.Add("Item1")
cbo.Items.Add("Item2")
How i can add ValueMember Field data manually? As we have an option in VB6 as:
cbo.AddItem ("Item1")
cbo.ItemData(cbo.NewIndex) = 1 'How this can be done in VB.Net?
cbo.AddItem ("Item2")
cbo.ItemData(cbo.NewIndex) = 2 'How this can be done in VB.Net?
Regards
|
|
|
|
|
How to open the start menu on the desktop and the windows task manager.
|
|
|
|
|
confusing,
make your question clear.
openning with vb or not.
to open taskmgr you can use shell("taskmgr.exe") otherwise press CTRL+ALT+DEL
Kanchana
|
|
|
|
|
You're looking for the Shell Automation object. Add a reference to the Shell32.dll, usually found in C:\Windows\System32. In your code, you do something like this:
Imports Shell32
.
.
.
Public Class Form1
Private Sub Button1_Click(blah, blah) Handles Button1.Click
Dim myShellObject As New Shell32.Shell
myShellObject.Open(ShellSpecialFolderConstants.ssfDRIVES)
End Sub
End Class
You can find out what all the special folder constants refer to here[^] on MSDN.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|