VB.NET

Moderators: seancampbell
Number of threads: 4022
Number of posts: 10035

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Problem with Screen.AllScreens(0).DeviceName Posted by Malcolm2008 on 2 Oct 2008 at 5:51 PM
I am having some problem with some code that worked OK when I programmed it on Vista 64 bit edition, but is having problems on a machine with Windows XP SP2. I have created some simple code that simulates the problem, rather than post my original code which is more complicated.

'Obtain Monitor Name
Dim MonitorName As String = Screen.AllScreens(0).DeviceName

'Gets rid of the "\\.\" at the start of the name
Do While MonitorName Like "*\*"
    MonitorName = Microsoft.VisualBasic.Right(MonitorName, Len(MonitorName) - 1)
Loop
'Display message if Monitor Name is "DISPLAY1"
If (MonitorName = "DISPLAY1") Then
    MsgBox("Monitor Found", MsgBoxStyle.OkOnly, "Monitor Search")
End If


The problem is that the message box in the last line never displays, Even though the Monitorname is "DISPLAY1" As expected..

The problem seems to be coming from the call to "Screens.AllScreens(0).DeviceName in the first line. If I obtain the value of "DeviceName" by putting my cursor over this bit of code it says

DeviceName = "DISPLAY1

Notice how there is a quotation mark at the start and none at the end. This problem carries over to the MonitorName variable, and MonitorName would also be missing the final quotation mark when the If Statement is run.

I am programming with VB.Net Express 2008 edition. On a machine with Windows XP SP 2, and the program is using .Net Framework 2.0. I have tried switching to .Net Framework 3.0 without any success.

I suspect this is a bug with something on my machine, rather than with my program. Is there another way of obtaining the name of all monitors attached to the computer?

Thank you


Report
Re: Ignore Post - Problem Solved Posted by Malcolm2008 on 3 Oct 2008 at 12:53 AM
: I am having some problem with some code that worked OK when I
: programmed it on Vista 64 bit edition, but is having problems on a
: machine with Windows XP SP2. I have created some simple code that
: simulates the problem, rather than post my original code which is
: more complicated.
:
:
: 'Obtain Monitor Name
: Dim MonitorName As String = Screen.AllScreens(0).DeviceName
: 
: 'Gets rid of the "\\.\" at the start of the name
: Do While MonitorName Like "*\*"
:     MonitorName = Microsoft.VisualBasic.Right(MonitorName, Len(MonitorName) - 1)
: Loop
: 'Display message if Monitor Name is "DISPLAY1"
: If (MonitorName = "DISPLAY1") Then
:     MsgBox("Monitor Found", MsgBoxStyle.OkOnly, "Monitor Search")
: End If
: 
:
:
: The problem is that the message box in the last line never displays,
: Even though the Monitorname is "DISPLAY1" As expected..
:
: The problem seems to be coming from the call to
: "Screens.AllScreens(0).DeviceName in the first line. If I obtain the
: value of "DeviceName" by putting my cursor over this bit of code it
: says
:
: DeviceName = "DISPLAY1
:
: Notice how there is a quotation mark at the start and none at the
: end. This problem carries over to the MonitorName variable, and
: MonitorName would also be missing the final quotation mark when the
: If Statement is run.
:
: I am programming with VB.Net Express 2008 edition. On a machine with
: Windows XP SP 2, and the program is using .Net Framework 2.0. I have
: tried switching to .Net Framework 3.0 without any success.
:
: I suspect this is a bug with something on my machine, rather than
: with my program. Is there another way of obtaining the name of all
: monitors attached to the computer?
:
: Thank you
:
:
:

Thank you for taking the time to look, however I have solved my problem.

For those that run across the same problem it was simply that VB had inserted Additional Characters in the return value of the DeviceName Property after "DISPLAY1" that didn't show in the box that tells you the current value the variable is holding. I solved it by trimming Characters off the right hand side till the string contained the value I needed




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.