why .....incorrect data printed from vb.net
-
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Try Dim cone As New Conection Dim ii As Integer = ds.Tables(0).Rows(ComboBox1.SelectedIndex).Item(0) Dim sh As String = cone.get_Special_data("select Switch_Access_Code from Swiches where Swich_ID=" & ii & "") b2 = "" b2 = sh Me.WindowState = FormWindowState.Minimized System.Windows.Forms.SendKeys.SendWait(b2)//b2="2494:" come from //database on sql server Me.WindowState = FormWindowState.Normal b2 = "" Catch ex As Exception MsgBox("الرجاء اختيار القسم") End Try End Sub some times when i click on this button will type on active window 4294: but aslo some time type 44294: and some time 4294:: and some time 4294: and some time 4449942: althought the data which comes from data base is just 4294: why the variable b2 some time print wrong data not as want ??????? kilany
-
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Try Dim cone As New Conection Dim ii As Integer = ds.Tables(0).Rows(ComboBox1.SelectedIndex).Item(0) Dim sh As String = cone.get_Special_data("select Switch_Access_Code from Swiches where Swich_ID=" & ii & "") b2 = "" b2 = sh Me.WindowState = FormWindowState.Minimized System.Windows.Forms.SendKeys.SendWait(b2)//b2="2494:" come from //database on sql server Me.WindowState = FormWindowState.Normal b2 = "" Catch ex As Exception MsgBox("الرجاء اختيار القسم") End Try End Sub some times when i click on this button will type on active window 4294: but aslo some time type 44294: and some time 4294:: and some time 4294: and some time 4449942: althought the data which comes from data base is just 4294: why the variable b2 some time print wrong data not as want ??????? kilany
It's not the B2 variable that has the problem. It's SendKeys. Using SendKeys to send data or control another application is NOT reliable, as you've already found out. You're quite literally stuffing the keyboard buffer with keys that are NOT guaranteed to make it to their intended target control. On top of that, if the target control already has data in it, you could be inserting this data into the middle, or whatever, of the existing data. Dave Kreskowiak Microsoft MVP - Visual Basic
-
It's not the B2 variable that has the problem. It's SendKeys. Using SendKeys to send data or control another application is NOT reliable, as you've already found out. You're quite literally stuffing the keyboard buffer with keys that are NOT guaranteed to make it to their intended target control. On top of that, if the target control already has data in it, you could be inserting this data into the middle, or whatever, of the existing data. Dave Kreskowiak Microsoft MVP - Visual Basic