gruizelgruis Member Licensed User Longtime User Jun 18, 2018 #1 Hi all, Sorry if this has been asked before. I'm debugging a project I created a view years back. I think I run into a string length problem. My question is: What is the max lengts of a variabel declared as a string ? Are there any alternatives ? Pls advice
Hi all, Sorry if this has been asked before. I'm debugging a project I created a view years back. I think I run into a string length problem. My question is: What is the max lengts of a variabel declared as a string ? Are there any alternatives ? Pls advice
OliverA Expert Licensed User Longtime User Jun 20, 2018 #21 gruizelgruis said: I did. It worked. But .... is ..... very .... slow ..... Click to expand... In Release mode? gruizelgruis said: Im not getting anywhere with this. am I correct to say if the length of the string is Len(senddata) = 603 Then the prefix would be chr(93) & chr(2) & chr(0) & chr(0) ? please advice I'm lost Click to expand... Looking at the code I linked to in post #18, as long as Len(senddata) returns a Int32 value, you should just Write(Len(senddata)). Code snippet from linked code: Code: Copy Dim name As Byte() = Encoding.UTF8.GetBytes(Path.GetFileName(fileToSend)) Dim bw As New BinaryWriter(stream) 'send the first message which is the file name bw.Write(name.Length) bw.Write(name) Instead of a filename, you just need to sent your UTF8 encoded string, so something like Code: Copy Dim myTextToSent = "Some really really long string here" Dim data As Byte() = Encoding.UTF8.GetBytes(myTextToSent) Dim bw As New BinaryWriter(stream) 'send the first message which is the file name bw.Write(data.Length) bw.Write(data) Note: This is just a code snippet. You still need to set up the "stream" variable/object. I'm not a VB6 programmer, I'm just going by the code provided (linked to in post#18). Upvote 0
gruizelgruis said: I did. It worked. But .... is ..... very .... slow ..... Click to expand... In Release mode? gruizelgruis said: Im not getting anywhere with this. am I correct to say if the length of the string is Len(senddata) = 603 Then the prefix would be chr(93) & chr(2) & chr(0) & chr(0) ? please advice I'm lost Click to expand... Looking at the code I linked to in post #18, as long as Len(senddata) returns a Int32 value, you should just Write(Len(senddata)). Code snippet from linked code: Code: Copy Dim name As Byte() = Encoding.UTF8.GetBytes(Path.GetFileName(fileToSend)) Dim bw As New BinaryWriter(stream) 'send the first message which is the file name bw.Write(name.Length) bw.Write(name) Instead of a filename, you just need to sent your UTF8 encoded string, so something like Code: Copy Dim myTextToSent = "Some really really long string here" Dim data As Byte() = Encoding.UTF8.GetBytes(myTextToSent) Dim bw As New BinaryWriter(stream) 'send the first message which is the file name bw.Write(data.Length) bw.Write(data) Note: This is just a code snippet. You still need to set up the "stream" variable/object. I'm not a VB6 programmer, I'm just going by the code provided (linked to in post#18).
Erel B4X founder Staff member Licensed User Longtime User Jun 20, 2018 #22 Why aren't you using AsyncStreamsText ? You just need to make sure that each message ends with an end of line character. Upvote 0
Why aren't you using AsyncStreamsText ? You just need to make sure that each message ends with an end of line character.
gruizelgruis Member Licensed User Longtime User Jun 20, 2018 #23 Erel said: Why aren't you using AsyncStreamsText ? You just need to make sure that each message ends with an end of line character. Click to expand... I did try asyncstreamstext, It was very slow compared to asyncstreams. Atleast in design mode it was. I use asyncstreams with prefix now. And it looks good. I'll be testing it this weekend. @OliverA Thank you for your input. I managed the 4byte the prefix with this code Code: Copy Public Function LongToByte(ByVal lng As Long) As String Dim Rest As Byte Rest = lng \ 255 LongToByte = Chr((lng - (255 * Rest)) - Rest) & Chr(Rest) & Chr(0) & Chr(0) end function Its good enough for string lengths upto 65025. I'm sending the sendata just as tekst. Last edited: Jun 20, 2018 Upvote 0
Erel said: Why aren't you using AsyncStreamsText ? You just need to make sure that each message ends with an end of line character. Click to expand... I did try asyncstreamstext, It was very slow compared to asyncstreams. Atleast in design mode it was. I use asyncstreams with prefix now. And it looks good. I'll be testing it this weekend. @OliverA Thank you for your input. I managed the 4byte the prefix with this code Code: Copy Public Function LongToByte(ByVal lng As Long) As String Dim Rest As Byte Rest = lng \ 255 LongToByte = Chr((lng - (255 * Rest)) - Rest) & Chr(Rest) & Chr(0) & Chr(0) end function Its good enough for string lengths upto 65025. I'm sending the sendata just as tekst.
Erel B4X founder Staff member Licensed User Longtime User Jun 21, 2018 #24 gruizelgruis said: I did try asyncstreamstext, It was very slow compared to asyncstreams. Atleast in design mode it was. Click to expand... You should never test performance in debug mode. AsyncStreamsText is not slow. Though prefix mode is a good solution. Upvote 0
gruizelgruis said: I did try asyncstreamstext, It was very slow compared to asyncstreams. Atleast in design mode it was. Click to expand... You should never test performance in debug mode. AsyncStreamsText is not slow. Though prefix mode is a good solution.