perfect in c# but facing error in vb.net


G

Guest

Hi
I am running a code in which on a button press event i programmatically
dropdown combobox by passing it F4 key the same code is running perfect in c#
but in vb.net i m getting exception "NotSupportedException"

---vb.net code is---

<DllImport("coredll.dll")> _
Public Function keybd_event( _
ByVal bVk As Byte, _
ByVal bScan As Byte, _
ByVal dwFlags As Integer, _
ByVal dwExtraInfo As Integer)
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
ComboBox1.Focus()
keybd_event(CByte(Keys.F4), 0, 0, 0)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

---c# code is---

[DllImport("coredll.dll")]
public static extern void keybd_event(byte bVk, byte
bScan, int dwFlags, int dwExtraInfo);

private void button1_Click(object sender, System.EventArgs e)
{
ComboBox1.Focus();
keybd_event((byte)Keys.F4, 0, 0, 0);
}

any idea?
 
Ad

Advertisements

P

Peter Foot [MVP]

Your cast from a Keys enumeration to a byte is probably the issue since the
Keys enumeration is an Int32 (Integer) type. Try using CType(Keys.F4,
GetType(Byte)) and if that doesn't work try a two stage approach convert to
an Integer first then to a Byte.

Peter
 
Ad

Advertisements

D

Daniel Moth

Try changing the declare to a Sub (not Function).

Also PLEASE turn option strict on at the project level and deal with the
warnings.

Cheers
Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top