473,396 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to examine the first 32bits of a string in vb.net

I am working with a thermal printer that returns it's status in a string. In
vb6.0 I would use the MidB,AscB functions to examine the first 32 bits. What
can I use in vb.net to do the same.
Jul 21 '05 #1
9 2010
VBS Programer <an***********@comcast.net> wrote:
I am working with a thermal printer that returns it's status in a string. In
vb6.0 I would use the MidB,AscB functions to examine the first 32 bits. What
can I use in vb.net to do the same.


What *exactly* do you mean by "the first 32 bits"? You need to talk in
terms of characters, not bits when it comes to text data. Use Substring
to get parts of the string.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
I have a function that return a pointer to 32bits of data from the printer.
The code I am using to get that data into my program is "
pOutData = Marshal.PtrToStringAnsi(pCscDhlPara.pOutData) ". as per the
printer developer. The variable pOutData is defined as "string =
space(2048)". I now need to examine the data "32bits" that was returned.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
VBS Programer <an***********@comcast.net> wrote:
I am working with a thermal printer that returns it's status in a string.
In
vb6.0 I would use the MidB,AscB functions to examine the first 32 bits.
What
can I use in vb.net to do the same.


What *exactly* do you mean by "the first 32 bits"? You need to talk in
terms of characters, not bits when it comes to text data. Use Substring
to get parts of the string.

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

Jul 21 '05 #3
VBS Programer <an***********@comcast.net> wrote:
I have a function that return a pointer to 32bits of data from the printer.
The code I am using to get that data into my program is "
pOutData = Marshal.PtrToStringAnsi(pCscDhlPara.pOutData) ". as per the
printer developer. The variable pOutData is defined as "string =
space(2048)". I now need to examine the data "32bits" that was returned.


Hmm. If it's really binary data, marshalling it as a string sounds like
a really bad idea. What's the type of pCscDhlPara.pOutData?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #4
The structure is defined as

Structure CscDhlPara
Dim hCsc As Int32
Dim Spec As Int32
Dim InLen As Int32
Dim pInData As IntPtr
Dim OutLen As Int32
Dim pOutData As IntPtr
Dim StClass As Int32
Dim StCode As Int32
Dim StWarn As Int32
Dim StAction As Int32
End Structure

Thanks for your time.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
VBS Programer <an***********@comcast.net> wrote:
I have a function that return a pointer to 32bits of data from the
printer.
The code I am using to get that data into my program is "
pOutData = Marshal.PtrToStringAnsi(pCscDhlPara.pOutData) ". as per the
printer developer. The variable pOutData is defined as "string =
space(2048)". I now need to examine the data "32bits" that was returned.


Hmm. If it's really binary data, marshalling it as a string sounds like
a really bad idea. What's the type of pCscDhlPara.pOutData?

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

Jul 21 '05 #5
VBS Programer <an***********@comcast.net> wrote:
The structure is defined as

Structure CscDhlPara
Dim hCsc As Int32
Dim Spec As Int32
Dim InLen As Int32
Dim pInData As IntPtr
Dim OutLen As Int32
Dim pOutData As IntPtr
Dim StClass As Int32
Dim StCode As Int32
Dim StWarn As Int32
Dim StAction As Int32
End Structure

Thanks for your time.


I would suggest using Marshal.ReadInt32(IntPtr) then - that should read
the first 32 bits of data at the right place.

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

I have tried
Marshal.ReadIntPtr(pCscDhlPara.pOutData, pOutData)

with pOutData defined as Integer, but it seem always to return 0. How would
I check the bits of an Intger?

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
VBS Programer <an***********@comcast.net> wrote:
The structure is defined as

Structure CscDhlPara
Dim hCsc As Int32
Dim Spec As Int32
Dim InLen As Int32
Dim pInData As IntPtr
Dim OutLen As Int32
Dim pOutData As IntPtr
Dim StClass As Int32
Dim StCode As Int32
Dim StWarn As Int32
Dim StAction As Int32
End Structure

Thanks for your time.


I would suggest using Marshal.ReadInt32(IntPtr) then - that should read
the first 32 bits of data at the right place.

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

Jul 21 '05 #7
I have also tried ReadInt32 and still get zero

"VBS Programer" <an***********@comcast.net> wrote in message
news:kM********************@comcast.com...

I have tried
Marshal.ReadIntPtr(pCscDhlPara.pOutData, pOutData)

with pOutData defined as Integer, but it seem always to return 0. How
would I check the bits of an Intger?

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
VBS Programer <an***********@comcast.net> wrote:
The structure is defined as

Structure CscDhlPara
Dim hCsc As Int32
Dim Spec As Int32
Dim InLen As Int32
Dim pInData As IntPtr
Dim OutLen As Int32
Dim pOutData As IntPtr
Dim StClass As Int32
Dim StCode As Int32
Dim StWarn As Int32
Dim StAction As Int32
End Structure

Thanks for your time.


I would suggest using Marshal.ReadInt32(IntPtr) then - that should read
the first 32 bits of data at the right place.

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


Jul 21 '05 #8
VBS Programer <an***********@comcast.net> wrote:
I have also tried ReadInt32 and still get zero


If ReadInt32 is returning zero, I'm not sure what's wrong. You need to
find out *exactly* what's going to be at the memory location returned.
Marshalling it as text seems like a very bad idea to me, but without
knowing more about the details, it's hard to know why ReadInt32 isn't
working.

You might want to ask on the interop group too - they may well be able
to help you more.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #9
Thank you for your time, Jon.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
VBS Programer <an***********@comcast.net> wrote:
I have also tried ReadInt32 and still get zero


If ReadInt32 is returning zero, I'm not sure what's wrong. You need to
find out *exactly* what's going to be at the memory location returned.
Marshalling it as text seems like a very bad idea to me, but without
knowing more about the details, it's hard to know why ReadInt32 isn't
working.

You might want to ask on the interop group too - they may well be able
to help you more.

--
Jon Skeet - <sk***@pobox.com>
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

8
by: MLH | last post by:
Have a look at the procedure below. In particular, note lines 1 and 21... Private Sub JudHrngReqBtn_Click() On Error GoTo Err_JudHrngReqBtn_Click Dim ThisForm As String ThisForm = Me.Name ...
2
by: Robert W. | last post by:
I'm trying to write a utility that will use Reflection to examine any data model I pass it and correctly map out this model into a tree structure. When I say "any" , in fact there will only be 3...
1
by: Edward Wilde | last post by:
Hi, Does anyone know how to examine items in the ASP.NET cache that are added using the OutputCache directive in framework 1.1 i.e. <%@ OutputCache Duration="300" VaryByParam="None"...
9
by: VBS Programer | last post by:
I am working with a thermal printer that returns it's status in a string. In vb6.0 I would use the MidB,AscB functions to examine the first 32 bits. What can I use in vb.net to do the same.
36
by: Cap'n Ahab | last post by:
I have used VB3 - VB6, so learning all this OO stuff is reasonably new to me (although I looked at Java a few years ago). Anyway, I thought I would write a small class to begin with, with a...
9
by: Noel Milton | last post by:
Hi: Ok, I've just read in up to 65,535 bytes into a char array (using the recvfrom socket API call). So I have an array of 8 bit char's (char recvString;). Now, four (4) consecutive bytes...
10
by: Woody Ling | last post by:
In 32 bits DB2 environment, is it meaningful to set sheapthres larger than 256MB for the following case.. 1. Intra-parallel is ON 2. Intra-parallel is OFF
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.