473,406 Members | 2,707 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,406 software developers and data experts.

Owner Information with Option Strict On

I'm trying to use the code posted in various forums to get the Owner Name on
a Pocket PC device, and I'm having a bit of trouble. Please help.
(I'm using VB.NET with Option Strict On.)

My code is:

I have a form with a button. The button click event has the following two
lines:

Dim test As String = OwnerName()
MessageBox.Show("[" & test & "]")

OwnerName is the following function:

Public Function OwnerName() As String

Try

Dim ownerbytes As Byte()
ownerbytes =
CType(OpenNETCF.Win32.Registry.CurrentUser.OpenSub Key("ControlPanel\Owner").
GetValue("Owner"), Byte())

OwnerName = System.Text.Encoding.Unicode.GetString(ownerbytes, 0,
72).TrimEnd(CType("\0", Char))
'Note: I've also tried the following line with the same result:
'OwnerName = System.Text.Encoding.Unicode.GetString(ownerbytes,
0,72).TrimEnd("0"c)

Catch nEx As NullReferenceException
MessageBox.Show("Please enter your Owner Name before using this program." &
CL & nEx.ToString & CL & nEx.Message)

Catch ex As Exception
MessageBox.Show(ex.ToString)

End Try

End Function

The Owner Name on the device is

Test Name

Stepping through the code, I typed the following into the Command Window
before the 'OwnerName=' assignment:
?System.Text.Encoding.Unicode.GetString(ownerbytes , 0,
72).TrimEnd(CType("\0", Char))
"Test Name"

I typed the following into the Command Window after the 'OwnerName='
assignment (note the trailing quote is gone from the result):
?ownername
"Test Name

When control returned to my button event, I got the same result with the
variable, test:
?test
"Test Name

And finally, the Messagebox displayed (Note no trailing ']'):
[Test Name

I'm trying to get test = "Test Name", and the Messagebox to show [Test Name]

What am I missing??

Thanks for your help.

- Jeff
Nov 20 '05 #1
2 1075
OwnerName = System.Text.Encoding.Unicode.GetString(ownerbytes, 0,
72).TrimEnd(CType("\0", Char))
'Note: I've also tried the following line with the same result:
'OwnerName = System.Text.Encoding.Unicode.GetString(ownerbytes,
0,72).TrimEnd("0"c)


Try replacing

..TrimEnd(CType("\0", Char))

with

..TrimEnd(ChrW(0))
VB.NET doesn't support C style string escapes.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 20 '05 #2
Thanks very much. That solved the problem.

- Jeff
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:uu**************@TK2MSFTNGP11.phx.gbl...
OwnerName = System.Text.Encoding.Unicode.GetString(ownerbytes, 0,
72).TrimEnd(CType("\0", Char))
'Note: I've also tried the following line with the same result:
'OwnerName = System.Text.Encoding.Unicode.GetString(ownerbytes,
0,72).TrimEnd("0"c)


Try replacing

.TrimEnd(CType("\0", Char))

with

.TrimEnd(ChrW(0))
VB.NET doesn't support C style string escapes.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nov 20 '05 #3

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

Similar topics

9
by: Microsoft News | last post by:
I have a project that was created all with Option Strict OFF. Works great, not a problem with it. But if I turn Option Strict ON then I get a LOT of errors. My question, should I even care...
11
by: Daylor | last post by:
hi. im using option strict on. im doing in ,from the simple reason ,to be warn when there are implict conversion like string to int ,int to string. BUT. the price ,(now i see ), is very bad....
2
by: John Regan | last post by:
Hello All I am trying to find the owner of a file or folder on our network (Windows 2000 Server) using VB.Net and/or API. so I can search for Folders that don't follow our company's specified...
8
by: Rich | last post by:
Hello, If I leave Option Strict Off I can use the following syntax to read data from a Lotus Notes application (a NotesViewEntry object represents a row of data from a Lotus Notes View - like a...
2
by: dan heskett | last post by:
I am owner-drawing a listbox, in an attempt to create a nice list with some custom "fields" and text layout. Essentially it works, but I must be missing something big, conceptually, because I...
17
by: David | last post by:
Hi all, I have the following problem: my program works fine, but when I add option strict at the top of the form, the following sub fails with an error that option strict does not allow late...
1
by: Jerad Rose | last post by:
I believe this issue is specific to ASP.NET. Why does VB.NET (2.0) ignore the project-level setting for Option Strict? I have the setting turned on in web.config: <compilation debug="true"...
2
by: levimc | last post by:
I know that that topic may be old to you but I looked at other more- than-two-year-old topics related to mine. However, I didn't find them working for my project at all because its errors return...
8
by: Rory Becker | last post by:
A wise man once said: "Never put off until runtime what you can fix at compile time." Actually I think he said it about 10 minutes before I started this post. I am a firm believer, like the...
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
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: 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
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.