473,583 Members | 2,875 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem reading Chr(0) from random file...

hai,
At present I'm facing a strange problem. We are converting a project from
VB to .NET
One record contains Chr(0). Let the record be of length 1800. In the 50th
byte of a record a chr(0) is there.
While I use VB to read it's giving all 1800 bytes. But when I converted my
VB to VB.NET, after the 49th byte all the bytes are truncating. I have to
solve this issue to proceed further. I hope the experts around here can solve
my problem.
I'm using the random file and using a structure of length 1800 bytes.
Following is the code I use

Public Structure StudentRCDetail s
<VBFixedString( 1800)> Dim lsData As String
End Structure

Dim lStructDetails As StudentRCDetail s

FileOpen(liKeyF ileNum, lsFilePath, OpenMode.Binary , , OpenShare.Share d, 1800)
FileGet(liKeyFi leNum, lStructDetails , Integer.Parse(l sStudentID))
FileClose(liKey FileNum)
I'm getting only a part of a string. ie. till the Chr(0). After, all the
datas are discarded.
I tried with opening in Random mode also. The result is same for both the
cases.
Please help me in this issue. It's urgent

regards,
Venkatarajan
Jul 21 '05 #1
11 1781
Venkatarajan <Ve**********@d iscussions.micr osoft.com> wrote:
At present I'm facing a strange problem. We are converting a project from
VB to .NET
One record contains Chr(0). Let the record be of length 1800. In the 50th
byte of a record a chr(0) is there.
While I use VB to read it's giving all 1800 bytes. But when I converted my
VB to VB.NET, after the 49th byte all the bytes are truncating. I have to
solve this issue to proceed further. I hope the experts around here can solve
my problem.


Are you *absolutely sure* that it's actually being truncated? How are
you examining the string? If it's in the debugger, try printing out the
string - you may well find that the rest of the data is there, it's
just not being shown in the debugger.

(I would be more confident about this if you were using standard .NET
IO classes - I'm not familiar with the VB functions you're using.)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
Hai Jon,
I tried to print it out in the debugger?. Let assume the string be
"Venkat" & Chr(0) & "rajan".
When I tried to print it in the debugger it shows as
"Venkat
When try to extract character by character, it shows me a error.
Not even the terminating quotes.

Help me out

Regards,
Venkatarajan

"Jon Skeet [C# MVP]" wrote:
Venkatarajan <Ve**********@d iscussions.micr osoft.com> wrote:
At present I'm facing a strange problem. We are converting a project from
VB to .NET
One record contains Chr(0). Let the record be of length 1800. In the 50th
byte of a record a chr(0) is there.
While I use VB to read it's giving all 1800 bytes. But when I converted my
VB to VB.NET, after the 49th byte all the bytes are truncating. I have to
solve this issue to proceed further. I hope the experts around here can solve
my problem.


Are you *absolutely sure* that it's actually being truncated? How are
you examining the string? If it's in the debugger, try printing out the
string - you may well find that the rest of the data is there, it's
just not being shown in the debugger.

(I would be more confident about this if you were using standard .NET
IO classes - I'm not familiar with the VB functions you're using.)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #3
Venki <Ve***@discussi ons.microsoft.c om> wrote:
I tried to print it out in the debugger?. Let assume the string be
"Venkat" & Chr(0) & "rajan".
When I tried to print it in the debugger it shows as
"Venkat
When try to extract character by character, it shows me a error.
Not even the terminating quotes.

Help me out


Don't print it out in the debugger - print it out in a console window.
Basically, don't trust the debugger when it comes to strings, until you
know exactly how it handles them.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #4
I tried it in Command Window. It gives the same result. Help me to solve this
issue.

Regards,
Venkatarajan

"Jon Skeet [C# MVP]" wrote:
Venki <Ve***@discussi ons.microsoft.c om> wrote:
I tried to print it out in the debugger?. Let assume the string be
"Venkat" & Chr(0) & "rajan".
When I tried to print it in the debugger it shows as
"Venkat
When try to extract character by character, it shows me a error.
Not even the terminating quotes.

Help me out


Don't print it out in the debugger - print it out in a console window.
Basically, don't trust the debugger when it comes to strings, until you
know exactly how it handles them.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #5
Venki <Ve***@discussi ons.microsoft.c om> wrote:
I tried it in Command Window. It gives the same result. Help me to solve this
issue.


Don't try it in the command window, try it in the console - using
Console.WriteLi ne - as I suggested before.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #6
hai jon,
It's working fine when I tried with Console Application. But when did the
same with Web Services or Windows application the string is getting
truncated. Please help me in this issue.
Dim str1 As String
str1 = "Venkat" & Chr(0) & "Rajan"
Console.WriteLi ne(str1)
Console.ReadLin e()
It gave Venkat Rajan in Console Application.

Dim str1 As String
str1 = "Venkat" & Chr(0) & "Rajan"
msgbox(str1)
When I used a windows Application , it showed me only Venkat.
Thanks in Advance.

Regards,
Venkatarajan

"Jon Skeet [C# MVP]" wrote:
Venki <Ve***@discussi ons.microsoft.c om> wrote:
I tried it in Command Window. It gives the same result. Help me to solve this
issue.


Don't try it in the command window, try it in the console - using
Console.WriteLi ne - as I suggested before.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #7
Venki <Ve***@discussi ons.microsoft.c om> wrote:
It's working fine when I tried with Console Application. But when did the
same with Web Services or Windows application the string is getting
truncated. Please help me in this issue.
Dim str1 As String
str1 = "Venkat" & Chr(0) & "Rajan"
Console.WriteLi ne(str1)
Console.ReadLin e()
It gave Venkat Rajan in Console Application.

Dim str1 As String
str1 = "Venkat" & Chr(0) & "Rajan"
msgbox(str1)
When I used a windows Application , it showed me only Venkat.
Thanks in Advance.


That's just because message box will truncate strings. The string
itself is fine.

If you want to get rid of the nul characters, use String.Replace and
replace them with whatever you want (eg space).

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #8
Hai Jon,
See my first post. I'm getting the Structure of length 1800 bytes. When I
tried to read it from the file, the character what I'm getting is terminated
when it reaches the null string. I have solve this issue.
Thanks in advance

Regards,
Venkatarajan

"Jon Skeet [C# MVP]" wrote:
Venki <Ve***@discussi ons.microsoft.c om> wrote:
It's working fine when I tried with Console Application. But when did the
same with Web Services or Windows application the string is getting
truncated. Please help me in this issue.
Dim str1 As String
str1 = "Venkat" & Chr(0) & "Rajan"
Console.WriteLi ne(str1)
Console.ReadLin e()
It gave Venkat Rajan in Console Application.

Dim str1 As String
str1 = "Venkat" & Chr(0) & "Rajan"
msgbox(str1)
When I used a windows Application , it showed me only Venkat.
Thanks in Advance.


That's just because message box will truncate strings. The string
itself is fine.

If you want to get rid of the nul characters, use String.Replace and
replace them with whatever you want (eg space).

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #9
Venki <Ve***@discussi ons.microsoft.c om> wrote:
See my first post. I'm getting the Structure of length 1800 bytes.
When I tried to read it from the file, the character what I'm getting
is terminated when it reaches the null string. I have solve this
issue.


I'm still not convinced it *is* actually being terminated - have you
tried printing out the string *to the console* (not the debugger, not
the command window, not a web page, not a message box) after reading
it?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
16859
by: David Gray | last post by:
Greetings all, I'm working on a program that allows a user to enter notes in a multiline textbox. I would like to be able to read the contents of the textbox (as records - one per line) and store in an array then a file. Perhaps this is the wrong control to use as there seems no way of referencing each line of the text box.
6
6589
by: Dietrich Epp | last post by:
Are there any good modules for reading a bitstream? Specifically, I have a string and I want to be able to get the next N bits as an integer. Right now I'm using struct.unpack and bit operations, it's a bit kludgy but it gets the right results. Thanks in advance.
3
2570
by: Tim::.. | last post by:
Can someone please tell my why I get the following problem when I type the following piece of code! How do I get around this??? The idea is that when a user clicks a button on a form it causes a postback to occur which in turn triggers a sub in a user control... Error: Argument not specified for parameter e of Public Sub...
2
1892
by: Bruce Wiebe | last post by:
hi all im having a problem accessing a text file on my hard disk after ive created it and added some text to it it would appear that the file is still locked. What happens is this i have three buttons on a windows form that provide three options for the user the process goes like this user clicks button one and a web service is called...
9
6743
by: jeff M via .NET 247 | last post by:
I'm still having problems reading EBCDIC files. Currently itlooks like the lower range (0 to 127) is working. I have triedthe following code pages 20284, 20924, 1140, 37, 500 and 20127.By working I get the correct answer by taking the decimal valueand using that as an index to an array that will map to thecorrect EBCDIC value in hex. By larger...
0
1520
by: Tim Wagaman | last post by:
I an having issuses with a loop I am running to keep checking for messages coming across our line. The goal: Listen for messages on port 5001 and print the messages into a text file. The port must stay open at all times and only close if no activity for 60 seconds. The problem: If I do a read on a networkstream and the connection is...
11
291
by: Venkatarajan | last post by:
hai, At present I'm facing a strange problem. We are converting a project from VB to .NET One record contains Chr(0). Let the record be of length 1800. In the 50th byte of a record a chr(0) is there. While I use VB to read it's giving all 1800 bytes. But when I converted my VB to VB.NET, after the 49th byte all the bytes are truncating. I...
10
1533
by: tvin | last post by:
Hi all I brought a string from a .txt file which was saved like utf-8. In the .txt file i have this string "frédéric".My problem is that when i read this file .txt,the bytes of é are like this : 101,180. é length are 2 in utf-8 file.how can i change this 2 length to 1. my problem that i want to use é like 233 byte and not like 2...
0
1373
by: phpfreak2007 | last post by:
Hi all, I am trying to upload file using VB HTTP Post method and winsock control . Can successfully upload the files when client machine is English OS, but create problem when upload from Chinese OS. Currently what i am doing is reading file in string and then build a html request and send these string data to upload. fuction which read a file...
0
7888
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8159
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8314
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7922
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8185
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5689
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3811
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2317
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.