|
I'm not sure I understand the question. I don't think 'Withevents' is required in any circumstances. You can use it when you declare a variable. Like 'Withevents txt as new textbox'. This really just makes it easier to add an event handler for your object because you can select the event just like you would for any textbox you put on your form in the designer. However, you can always write an event handler even if you didn't use 'Withevents'. I hope that made some sense to you.
|
|
|
|
|
Hi - I have a small development app that (used to) talk to a servo on a com port, and get a status reply. I have somehow really fixed it (I tried to simplify the code) - but the symptoms are maddening, and I do not see what I did other than move a readline from a subroutine to be inline with the code.
Here is what I have
Public ServoCommName As String = "COM4"
Public ServoCommSpeed As Integer = 9600
Public ServoCommdataOut As String
Public ServoCommDataIn As String
Public ServoCommParity As System.IO.Ports.Parity
Public ServoCommDataBits As Integer
Public ServoCommStopBits As System.IO.Ports.StopBits
Public Com2 As SerialPort = My.Computer.Ports.OpenSerialPort(ServoCommName, ServoCommSpeed, IO.Ports.Parity.None, 8, IO.Ports.StopBits.One)
Then the subroutine . . .
Public Sub GetServoStatus()
' Sends a status request and then gets Status from the Servo serial port.
ServoCommdataOut = cstCameraServoAddress & "&R"
Call SendSerialData() 'This will return the Firmware Version
'just in case wait 500 ms ' I have tried all sorts of delays . . . it worked before with 500
Call DelayTimer(DelayTime)
ServoCommDataIn = Com2.ReadLine()
MsgBox("End Read" & DelayTime & ServoCommDataIn)
outLabel = "Read Servo"
outMessage = ServoCommDataIn
Call WriteToLog(outLabel, outMessage)
ServoStatusBoxOut = "Ready"
ServoStatusBox = ServoStatusBoxOut
End Sub
Here is the portmonitor recording for this part of the code . . . The response comes in on line 52 and portmon says it is fine !
32 7:18:29 AM CameraControlV1 IOCTL_SERIAL_SET_BAUD_RATE slabser1 SUCCESS Rate: 9600
33 7:18:29 AM CameraControlV1 IOCTL_SERIAL_CLR_RTS slabser1 SUCCESS
34 7:18:29 AM CameraControlV1 IOCTL_SERIAL_CLR_DTR slabser1 SUCCESS
35 7:18:29 AM CameraControlV1 IOCTL_SERIAL_SET_LINE_CONTROL slabser1 SUCCESS StopBits: 1 Parity: NONE WordLength: 8
36 7:18:29 AM CameraControlV1 IOCTL_SERIAL_SET_CHAR slabser1 SUCCESS EOF:1a ERR BRK EVT:1a XON:11 XOFF:13
37 7:18:29 AM CameraControlV1 IOCTL_SERIAL_SET_HANDFLOW slabser1 SUCCESS Shake Replace XonLimit:128 XoffLimit:128
38 7:18:29 AM CameraControlV1 IOCTL_SERIAL_CLR_RTS slabser1 SUCCESS
39 7:18:29 AM CameraControlV1 IOCTL_SERIAL_SET_TIMEOUTS slabser1 SUCCESS RI:-1 RM:-1 RC:-2 WM WC
40 7:18:29 AM CameraControlV1 IOCTL_SERIAL_SET_WAIT_MASK slabser1 SUCCESS Mask: RXCHAR RXFLAG CTS DSR RLSD BRK ERR RING
41 7:18:29 AM CameraControlV1 IOCTL_SERIAL_SET_QUEUE_SIZE slabser1 SUCCESS InSize: 4096 OutSize: 2048
42 7:18:29 AM CameraControlV1 IOCTL_SERIAL_WAIT_ON_MASK slabser1 SUCCESS
43 7:18:49 AM CameraControlV1 IRP_MJ_WRITE slabser1 SUCCESS Length 4: /1TR
44 7:18:49 AM CameraControlV1 IRP_MJ_WRITE slabser1 SUCCESS Length 1: .
45 7:18:49 AM CameraControlV1 IRP_MJ_WRITE slabser1 SUCCESS Length 1: .
46 7:18:50 AM CameraControlV1 IOCTL_SERIAL_WAIT_ON_MASK slabser1 SUCCESS
47 7:18:50 AM CameraControlV1 IRP_MJ_WRITE slabser1 SUCCESS Length 4: /1&R
48 7:18:50 AM CameraControlV1 IRP_MJ_WRITE slabser1 SUCCESS Length 1: .
49 7:18:50 AM CameraControlV1 IRP_MJ_WRITE slabser1 SUCCESS Length 1: .
50 7:18:51 AM CameraControlV1 IOCTL_SERIAL_WAIT_ON_MASK slabser1 SUCCESS
51 7:18:51 AM CameraControlV1 IOCTL_SERIAL_GET_COMMSTATUS slabser1 SUCCESS
52 7:18:51 AM CameraControlV1 IRP_MJ_READ slabser1 SUCCESS Length 48: ./0b...../0`EZServo All Motion V5.45 6-20-06....
53 7:18:51 AM CameraControlV1 IOCTL_SERIAL_GET_COMMSTATUS slabser1 SUCCESS
54 7:18:51 AM CameraControlV1 IOCTL_SERIAL_GET_COMMSTATUS slabser1 SUCCESS
55 7:18:51 AM CameraControlV1 IOCTL_SERIAL_GET_COMMSTATUS slabser1 SUCCESS
56 7:18:51 AM CameraControlV1 IOCTL_SERIAL_GET_COMMSTATUS slabser1 SUCCESS
57 7:18:51 AM CameraControlV1 IOCTL_SERIAL_GET_COMMSTATUS slabser1 SUCCESS
58 7:18:51 AM CameraControlV1 IOCTL_SERIAL_GET_COMMSTATUS slabser1 SUCCESS
59 7:18:51 AM CameraControlV1 IOCTL_SERIAL_GET_COMMSTATUS slabser1 SUCCESS
60 7:18:56 AM CameraControlV1 IRP_MJ_WRITE slabser1 SUCCESS Length 12: /1f0Z500000R
61 7:18:56 AM CameraControlV1 IRP_MJ_WRITE slabser1 SUCCESS Length 1: .
62 7:18:56 AM CameraControlV1 IRP_MJ_WRITE slabser1 SUCCESS Length 1: .
63 7:18:56 AM CameraControlV1 IOCTL_SERIAL_WAIT_ON_MASK slabser1 SUCCESS
64 7:19:01 AM CameraControlV1 IRP_MJ_WRITE slabser1 SUCCESS Length 6: /1Tz0R
65 7:19:01 AM CameraControlV1 IRP_MJ_WRITE slabser1 SUCCESS Length 1: .
66 7:19:01 AM CameraControlV1 IRP_MJ_WRITE slabser1 SUCCESS Length 1: .
67 7:19:01 AM CameraControlV1 IOCTL_SERIAL_WAIT_ON_MASK slabser1 SUCCESS
68 7:19:02 AM CameraControlV1 IRP_MJ_WRITE slabser1 SUCCESS Length 6: /1Tz0R
69 7:19:02 AM CameraControlV1 IRP_MJ_WRITE slabser1 SUCCESS Length 1: .
70 7:19:02 AM CameraControlV1 IRP_MJ_WRITE slabser1 SUCCESS Length 1: .
71 7:19:02 AM CameraControlV1 IOCTL_SERIAL_WAIT_ON_MASK slabser1 SUCCESS
72 7:19:02 AM CameraControlV1 IRP_MJ_WRITE slabser1 SUCCESS Length 8: /1A4576R
73 7:19:02 AM CameraControlV1 IRP_MJ_WRITE slabser1 SUCCESS Length 1: .
74 7:19:02 AM CameraControlV1 IRP_MJ_WRITE slabser1 SUCCESS Length 1: .
75 7:19:02 AM CameraControlV1 IOCTL_SERIAL_WAIT_ON_MASK slabser1 SUCCESS
But ....................... My log file has the following . . . .
Initialize, 2007020571849, File Created
Initialize, 2007020571849, AS2007020571849
Read GPS INIT, 2007020571849, GPRMC,151830,A,3743.1693,N,12203.7291,W,0.0,242.5,050207,15.0,E,A*33
servoInit, 2007020571850, AerialServices - EZComm Servo Control
servoWrite, 2007020571850, /1&R
Read Servo, 2007020571856, ?/0b <===================== This is what VB is seeing ! Help !!
servoWrite, 2007020571856, /1f0Z500000R
servoWrite, 2007020571901, /1Tz0R
servoZero, 2007020571902, /1Tz0R
servoWrite, 2007020571902, /1Tz0R
servoZero, 2007020571902, /1Tz0R
servoWrite, 2007020571902, /1A4576R
servoReadyPosition, 2007020571903, /1A4576R
Another oddity - (not necessarily related but strange that it would occur at the same time as this . . ) is that the vbCRLF constant seems to go missing in the midst of writing some of the log file entries -here is the sub I am using . . .
Public Sub WriteToLog(ByVal outLabel As String, _
ByVal outMessage As String)
'NAME: WriteToLog
'PURPOSE: Write Status message
'PARAMETERS: outMessage - message to be written to error file
' outLabel - type of the log file entry
'RETURNS: Nothing
'*************************************************************
Dim fs1 As FileStream = New FileStream("c:" & "\Logfiles\" & LogFileName & ".txt", FileMode.Append, FileAccess.Write)
Dim s1 As StreamWriter = New StreamWriter(fs1)
Dim DateStringOut As String = String.Format("{0:yyyyMMddHmmss}", DateTime.Now)
s1.Write(outLabel & ", " & DateStringOut & ", " & outMessage & vbCrLf)
s1.Close()
fs1.Close()
End Sub
The vbCRLF goes missing when I am reading another serial port and reading a series of NMEA messages - I thought that it might have something to do with a Public defining of variables such as outMessage but I changed these to a Dim (before the first sub) with no program output change.
|
|
|
|
|
I'm no expert but you moved a line of code maybe with a cut and paste maybe you got an extra line return in there somewhere.
Might be completely silly but the simple things first
Bird with no beak was born to succeed.
|
|
|
|
|
Thanks for the response - I have looked pretty carefully but nothing is obvious - the problem seems to be that PortMon sees the string comming in - but the readline(ServoDataIn) statement in the vb code either gets an incomplete transfer or garbage - I am not certain which . . . this is all very slow stuff and not much data is moving . . .
|
|
|
|
|
An article was printed about one week ago, week of Jan. 29, 2007, regarding purchase of Window s Vista. The article stated that a user can purchase the Ultimate package for around $200. I am wondering how one goes about this. Please let me know at EMAIL given. Thanks, Sid Kraft
Sid
|
|
|
|
|
how does this relate to VB.NET ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Well VB .Net will not be supported under Vista
Bird with no beak was born to succeed.
|
|
|
|
|
Christian: I am using Visual C++ 6.0, not VB. Sid Kraft
Sid
|
|
|
|
|
Then why are you asking a non-programming question, in a forum for a language you don't even use ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian: Sorry, thought I was sending a question to the Windows Group, Sid Kraft;)
Sid
|
|
|
|
|
I am reading a word document in a byte stream and trying to insert it in sql server table (field is varbinary type). The byte array contains 1000s elemets but in table it writes only '0xD0'.
Any idea what's wrong with it?
Thanks
Nas
|
|
|
|
|
manisghouri wrote: Any idea what's wrong with it?
Nope. Perhaps if you showed us what your code it we might be able to see what it wrong with it.
|
|
|
|
|
'To add document
'---------------
Private Function AddRequest(ByVal DocId As String, ByVal DocUSer As String _
, ByVal DocTitle As String, ByVal DocSubject As String, ByVal fileName As String) as Boolean
Dim cmd As New SqlCommand
Dim dr As SqlDataReader
' Read the Data into the Byte Array
Dim fStream As New FileStream(fileName, FileMode.Open, FileAccess.Read)
Dim DocData(fStream.Length) As Byte
fStream.Read(DocData, 0, CInt(fStream.Length))
fStream.Close()
With cmd
.CommandType = CommandType.StoredProcedure
.CommandText = "sp_AddDocument"
.Connection = Conn
Dim para1 As SqlParameter = .Parameters.Add("@DocId", SqlDbType.Varchar)
Dim para2 As SqlParameter = .Parameters.Add("@DocUser", SqlDbType.Int)
Dim para3 As SqlParameter = .Parameters.Add("@DocTitle", SqlDbType.VarChar)
Dim para4 As SqlParameter = .Parameters.Add("@DocData", SqlDbType.VarBinary)
para1.Value = DocId
para2.Value = DocUser
para3.Value = DocTitle
para4.Value = DocData
End With
Try
dr = cmdBrochureRequest.ExecuteReader
With dr
If .HasRows Then
While .Read
DocStatus = .Item(0)
isDone = True
End While
Else
MsgBox("No Document status retrieved", MsgBoxStyle.Critical, appTitle)
isDone = False
End If
End With
cmd.Parameters.Clear()
cmd = Nothing
dr.Close()
Catch ex As Exception
MsgBox("Error while inserting document into database:" & vbCrLf & ex.Message.ToString, MsgBoxStyle.Critical, appTitle)
isDone = False
End Try
If isDone = True Then
isDone = AddRequestDetail(RequestId)
End If
Return isDone
End Function
'To read document
'---------------
Private Function OpenDocument(ByVal DocId as string)
Dim cmd As New SqlCommand
Dim dr As SqlDataReader
With cmd
.CommandText = "sp_GetDocument "
.CommandType = CommandType.StoredProcedure
.Connection = ConnPIMPS
.Parameters.AddWithValue("@DocId", DocId)
End With
Try
dr = cmd.ExecuteReader
dr.Read()
Dim FileData(dr.GetBytes(0, 0, Nothing, 0, Integer.MaxValue) - 1) As Byte
dr.GetBytes(0, 0, FileData, 0, FileData.Length)
DisplayDocument(FileData)
dr.close
Catch ex As Exception
MsgBox("Error while opening document :" & vbCrLf & ex.Message.ToString, MsgBoxStyle.Critical, AppTitle)
Exit function
End Try
Private Sub DisplayDocument(ByVal arrInput() As Byte)
Dim i As Integer
Dim sOutput As New StringBuilder(arrInput.Length)
For i = 0 To arrInput.Length - 1
If Not CType(arrInput(i), Byte).ToString = 0 Then
sOutput.Append(Chr(arrInput(i)))
End If
Next
RichTextBox1.text = sOutput.ToString()
End Sub
Do you think it is what i required to save word document in sql server table,
regards
Nas
|
|
|
|
|
Hi all!
How can i fill color on Detail section of data report <vb6>.Please help .
Thanks.
|
|
|
|
|
I've got three comboboxes. ComboBox1 has two selections, (a) and (b). I can't figure out how to go about to pick one and driving ComboBox2. I'd like to pick (a) from ComboBox1 and have ComboBox2 know that when I pick (a), the associated data selections would be selectable in this ComboBox. Both (a) and (b)have specific data tied to each of them and I need it to know how to differentiate.
When I pick from ComboBox2, this will also drive what I can select in ComboBox3, but I need help getting started first.
Thanks.
|
|
|
|
|
In this event of combobox1 'combobox1_selectedindexchanged' determine which was selected and call the appropriate routine to load/replace the contents of combobox2.
|
|
|
|
|
Thanks.
I hate to ask too much, but I am rusty (2 years since coding of any form). Could you please explain "which was selected and call the appropriate routine to load/replace the contents of combobox2"?
I appreciate the help.
|
|
|
|
|
When the event fires, you need to check combo1 for what the user selected. Then react accordingly. There are 3 properties you can check to do this. Once you know what they selected, then call the appropriate routine to load the correct values in combo2 that belong to the selection they made in combo1
the properties:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Select Case ComboBox1.SelectedIndex 'if you hardcoded the contents of combo1
Case 0
Call FillCombo2WithATypes()
Case 1
Call FillCombo2WithBtypes()
End Select
Select Case ComboBox1.SelectedText 'what they see in the combo list
Case "A - type "
Call FillCombo2WithATypes()
Case "B - type "
Call FillCombo2WithBtypes()
End Select
Select Case ComboBox1.SelectedValue 'the code for what they see
Case "A"
Call FillCombo2WithATypes()
Case "B"
Call FillCombo2WithBtypes()
End Select
End Sub
|
|
|
|
|
I am using windows datagridview. I have added datagridtextboxcolumn as first column and the next column and remaining columns are from database. When I run the application 2nd column is highlighted, instead of first column. I want to highlight first column. I am using "Row header selection mode". I think this behaves when row header selected then selects entire row otherwise it behaves like "cell select" mode which selects the cell. Since I am adding datagridtextboxcolumn as my first column , it is highlighting 2nd column. Please advise how to select first column i.e datagridtextbox column instead of 2nd row. Also, I still need rowheader selection mode.
I appreciate your help!
Thanks,
Nilika
|
|
|
|
|
Hi All,
I want to create a playlist in WMP, so that the user can click "next" to go to the next video clip and "previous" to go back.
Could anybody advise me on 'HOW' to do this? or direct me to a tutorial. Ive searched the web and cannot find one.
Thanks in Advance.
Jaidev
|
|
|
|
|
i use arrays in vb.net
but i have a problem in the dimension
ex :
dim a() as integer
a(0)=new integer
gives error
i don't want to use arraylist because i dound inutil to do the cast
|
|
|
|
|
Could you display your real code please? What are you really setting a(0) equal to? I mean, you are not actually setting it to New Integer right? You are setting it to an actual value? And what is the error that you are getting?
|
|
|
|
|
i'm defining a vector without defining its size
so when i make new to allocate in memory
i get the eror : not set to an instance
|
|
|
|
|
I haven't been able to get through this error without defining the size of the array upfront. If you are using Visual Studio 2005 you can use a List object instead. It is like an ArrayList except that you must declare what type of objects are being listed, so you will not have to worry about the overhead of casting the objects into what you want. Here's how you declare it:
Dim objList As New List(Of Integer)
Hope this helps.
|
|
|
|
|
dim a() as integer
array.Resize(a,0) ' or redim preserve a(0)
a(0) = 9999
|
|
|
|
|