473,396 Members | 1,734 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 2009
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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
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...

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.