|
can somebody explain the code for me? I will appreciate for the help...
the following code is some part of the example that i take from internet,and i not really understand on it...
Private Sub Receiver(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles COMPort.DataReceived
' Note this subroutine is executed on the serial port thread - not the UI thread.
Dim RXByte, Nibble As Byte
Dim RXArray(2047) As Char
Dim I As Integer = 0
Do
RXByte = COMPort.ReadByte
Nibble = (RXByte >> 4) + 48 ' Convert received byte to Hex
If Nibble > 57 Then
Nibble = Nibble + 7
End If
RXArray(I) = Chr(Nibble)
I = I + 1
Nibble = (RXByte And 15) + 48
If Nibble > 57 Then
Nibble = Nibble + 7
End If
RXArray(I) = Chr(Nibble)
I = I + 1
RXArray(I) = " "
I = I + 1
SpaceCount = (SpaceCount + 1) And 31 ' Insert spaces and CRLF for better readability
If SpaceCount = 0 Then ' Insert CRLF after 32 numbers
RXArray(I) = Chr(13) ' CR
I = I + 1
RXArray(I) = Chr(10) ' LF
I = I + 1
Else
If (SpaceCount And 3) = 0 Then ' Insert two extra spaces for each 4 numbers
RXArray(I) = " "
I = I + 1
RXArray(I) = " "
I = I + 1
End If
End If
Loop Until (COMPort.BytesToRead = 0)
Dim RxString As New String(RXArray, 0, I) ' Convert the first part of the Char Array to a String
' Put a message with a delegate, which points to the display routine and holds the RxString,
' on the message queue and return immediately.
Me.BeginInvoke(New StringSubPointer(AddressOf Display), RxString)
End Sub
' Text display routine, which appends the received string to any text in the Received TextBox.
Private Sub Display(ByVal Buffer As String)
Received.AppendText(Buffer)
End Sub
' Transmitter subroutine.
Private Sub Transmitter(ByVal sender As Object, ByVal e As EventArgs) Handles SendButton.Click
Received.AppendText("TX" & vbCrLf) ' Switch to a new line after every transmission
SpaceCount = 0
Dim TextString As String
Dim TXArray(2047) As Byte
Dim I As Integer
Dim J As Integer = 0
Dim Ascii As Boolean = False
Dim Quote As Boolean = False
Dim Temp As Boolean
Dim Second As Boolean = False
Dim TXByte As Byte = 0
Dim CharByte As Byte
If COMPort.IsOpen Then
TextString = Transmitted.Text
For I = 0 To TextString.Length - 1
CharByte = Asc(TextString.Chars(I))
If CharByte = 34 Then ' If " Then
Temp = Ascii
Ascii = Ascii Or Quote
Quote = Not (Temp And Quote)
Else
Ascii = Ascii Xor Quote
Quote = False
End If
If Not Quote Then
If Ascii Then
TXArray(J) = CharByte
J = J + 1
Else
If (CharByte <> 32) And (CharByte <> 10) And (CharByte <> 13) Then ' Skip spaces, LF and CR
CharByte = (CharByte - 48) And 31 ' And 31 makes it case insensitive
If CharByte > 16 Then
CharByte = CharByte - 7
End If
If Second Then
TXArray(J) = TXByte + CharByte
Second = False
J = J + 1
Else
TXByte = CharByte << 4
Second = True
End If
End If
End If
End If
Next
Try
COMPort.Write(TXArray, 0, J)
Catch ex As Exception
MsgBox(ex.Message & " Check CTS signal or set Flow Control to None.")
End Try
Else
MsgBox("COM port is closed. Please select a COM port")
End If
End Sub
|
|
|
|
|
Perhaps if you specify what it is about the code that you don't understand. I don't think that anyone wants to explain what every single line of the code does...
---
single minded; short sighted; long gone;
|
|
|
|
|
Some of the code is dealing with hexadecimal numbers that get received in ASCII and decoded.
The constants 32, 48, 10, 13 are space, zero, carriagereturn and linefeed, and should
not be there in numeric form at all.
The code is amateuristic and should not be taken as an example.
There is plenty of good code on CodeProject. Read some of the articles relevant to you.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I'm using crystal report 9 developer's edition and im using vb6. When i view the report in crystal viewer the report's lines, items are not in place. but when i print the report the lines and items are in place. i tried to remove and replace the crystal viewer but it is still the same. what can i do so that when i view the report the items are in place just like when i print it.
|
|
|
|
|
crystal report is just for view the page
u have to adjust the report page sequencially with proper order. cr is easy to support any language and easy print.
hope u understand
any problem mail me
lucky
|
|
|
|
|
I want to run my program in the background and be loaded by clicking on the exe file. I don't want to load a visible form. Would I do the console application or is there a different way to do this? My goal is to load my program for demo purposes. I want it to be transparent to the user. It will sit and listen a certain port. But, it has been a long time I looked into main procedures. And that was in C++. I searched using my subject and did not find any articles. Please help me if you can. Thanks.
Ex: instead of running my program and having frmLoad run. I want main to run and run my program until closed.
|
|
|
|
|
Cory Kimble wrote: Would I do the console application or is there a different way to do this?
No, a console application will produce a console window.
You could use a Windows forms application, but just don't instantiate the form.
Alternatively, you could create a windows service.
|
|
|
|
|
In Form Load
Me.Opacity = 0.0
Me.ShowInTaskbar = False
-Andrew
|
|
|
|
|
Folks, I want to declare a structure in C exactly into VB.NET. I had a problem dealing with the dimension of Char as I did not know how to declare them in VB.NET.
So can someone please give me the translated code for the structure below. Important aspect is that I will have to use the EXACT dimension to the Char array. The C structure is defined as shown below
typedef struct _IndexTransaction
{
TCHAR MsgDirPath[MAX_PATH];
DWORD dwMsgTime;
DWORD dwMsgSize;
TCHAR MsgEntryId[256];
TCHAR MsgFolderPath[256];
TCHAR MsgRecSet[32];
TCHAR MsgVolume[32];
} IndexTransaction, *pIndexTransaction;
Thanks in advance. Look forward for your responses.
Ravi
|
|
|
|
|
One problem here is that TCHAR can be char or short.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
But it should be CHAR in my case with the exact dimension as specified, though it might take in less characters than the declared dimension.
|
|
|
|
|
I think you're looking for the MarshalAs attribute:
<StructLayout(LayoutKind.Sequential)> _
Public Structure MyStruct
<MarshalAd(UnmanagedType.ByValArray, SizeConst := 260)> Public c() As Char
End Structure
...I think...
|
|
|
|
|
I never dealt with that attribute, but as you rightly said, I was finding some answers related to MarshalAs attribute. So I will try it out.
Thank you for your time friends.
|
|
|
|
|
Nope buddy. It didn't seem to work. The MarshalAs field doesn't retain the dimension instead it takes the exact string length as normal.
|
|
|
|
|
This is where it helps to know EXACTLY what the API call you're using expects to see in this structure. It LOOKS like those TCHAR arrays are just being passed as if they were strings, passing just the address of the first element. So, try passing them in as strings instead:
<StructLayout(LayoutKind.Sequential)> _
Public Structure _IndexTransaction
<MarshalAs(UnmanagedType.LPTStr, SizeConst:=260)> Public MsgEntryId As String
Public dwMsgTime As Integer
Public dwMsgSize As Integer
<MarshalAs(UnmanagedType.LPTStr, SizeConst:=256)> Public MsgEntryId As String
<MarshalAs(UnmanagedType.LPTStr, SizeConst:=256)> Public MsgEntryId As String
<MarshalAs(UnmanagedType.LPTStr, SizeConst:=32)> Public MsgEntryId As String
<MarshalAs(UnmanagedType.LPTStr, SizeConst:=32)> Public MsgEntryId As String
End Structure
This may or may not work. I have no idea and no way to test it. You're going to have to fiddle with it to get it to work.
|
|
|
|
|
Hi
When I use the "AddressOf" operand to call a procidure that requires some arguments, error occurs. How can I handle this problem. Error is "AddressOf operand must be the name of a method, no parentheses are required.
Code snippet is below.
Dim trThread As New Thread(AddressOf DoSomething(Arguments))
Sub DoSomething(Arguments)
'do something whatever it be
End Sub
Thanks
reman
|
|
|
|
|
You can't do that. AddressOf returns exactly that, the address of a method. Your not actually calling the method, so passing parameters is pointless.
Which version of VB.NET are you using??
|
|
|
|
|
On assumes you should just provide DoSomething and not worry about the arguments. You can only start a thread that takes no arguments, or a single argument, of type object, AFAIK.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: or a single argument, of type object, AFAIK.
You are correct sir.
Now, IIRC, that's only in .NET 2.0 and above. I think .NET 1.1- couldn't take any arguments at all and had to pick up any arguments from a third party object visible to the method being launched.
|
|
|
|
|
No, I think I wrote .NET 1.1 code that multithreaded with a parameter.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Really?? I haven't done any threading in quite a while. I've forgotten a bunch...
I thought ThreadStart didn't take an argument, but the 2.0 ParameterizedThreadStart took an Object. Hmmm... where's my MSDN...
|
|
|
|
|
hi everyone,
when i select Window Media Player from Components tab of Choose Toolbox Items form then toolbox show Window Media Player control but when we draw window media player on form then following error occured
"Failed to Import ActiveX Control.Please ensure it is properly Registered"
i have no idea about this error . Can anyone guide me that how can i resolve this problem ?
Rupesh Kumar Swami
Software Engineer,
Integrated Solution,
Bikaner (India)
My Company
|
|
|
|
|
Rupesh Kumar Swami wrote: "Failed to Import ActiveX Control.Please ensure it is properly Registered"
Have you tried to register / re-register this control using the regsvr32 command? Find the full path to the ocx in question and register it using:
<br />
Syntax<br />
regsvr32 [/u] [/s] [/n] [/i[:cmdline]] dllname<br />
<br />
Examples<br />
To register ActiveX Library:<br />
<br />
regsvr32 "C:\path_to_activex\your_ocx_name.ocx"<br />
<br />
Parameters<br />
/u : Unregisters server. <br />
<br />
/s : Specifies regsvr32 to run silently and to not display any message boxes. <br />
<br />
/n : Specifies not to call DllRegisterServer. You must use this option with /i. <br />
<br />
/i:cmdline : Calls DllInstall passing it an optional [cmdline]. When used with /u, it calls dll uninstall. <br />
<br />
dllname : Specifies the name of the dll file that will be registered. <br />
<br />
/? : Displays help at the command prompt. <br />
Pete Soheil
DigiOz Multimedia
http://www.digioz.com
|
|
|
|
|
Hello to all,
I understand this is not a VB question, nor is related to it in any manner. But as being a Q. based on development, I request Moderator of this forum to let the Q. by here and I may get some idea on my requirements.
I have developed an application for a client. It is a Database Driven application. The client is trying to use to same application for many other databases with same structure. How can I avoid him from making such misuse of an application. After long tries, now he has comeup with just replacing the data; data struc. is same just del. all records & insert new records & use it with another copy of the software & sell for a new purpose.
Any ideas, how can I avoid him being successful in this case. Any idea is appreciated.
Thanks
Terry
|
|
|
|
|
Insert a record into one of the tables that is a marker record for you.
Then when the application kicks off get it to look for this record.
If this record is not present then lock the application.
Would this work with what you are trying?
The issue sounds like you don't want them to be able to redistribute your software - solution: use the registry, set the registry on first use, supply a key with the software.
Alternatively take the person to court for redistributing your software illegally - you did include a EULA with the software didn't you?
You always pass failure on the way to success.
|
|
|
|