Solved

Windows and Extended desktop

Posted on 2016-08-08
9
32 Views
Last Modified: 2016-08-09
I'm trying to code this in VB.NET desktop app.  But I get syntax errors.  What is wrong?

  <StructLayout(LayoutKind.Sequential)>
    Public Structure IntegerPoint
        Public Property X() As Integer
        Public Property Y As Integer
    End Structure

error
0
Comment
Question by:HLRosenberger
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
Did you mean to make X an integer array, Public Property X() As Integer, or did you mean to make it an integer like this, Public Property X As Integer?
0
 
LVL 35

Expert Comment

by:Kimputer
Comment Utility
Depends on the syntax error.
Otherwise, just check if this is on top of your code:

Imports System.Runtime.InteropServices
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
as per the definition on http://www.pinvoke.net/default.aspx/Structures/POINT.html, X is not an array (as pointed by Fernando). You need to remove the () after X:
  <StructLayout(LayoutKind.Sequential)>
    Public Structure IntegerPoint
        Public Property X As Integer
        Public Property Y As Integer
    End Structure

Open in new window

0
 
LVL 1

Author Comment

by:HLRosenberger
Comment Utility
Nothing I try works, using that <StructLayout(LayoutKind.Sequential)> syntax.

This below works just fine.  Is there any difference?


    Public Structure IntegerPoint
        Public x As Integer
        Public y As Integer
    End Structure

    Public Structure IntegerRect
        Public Left As Integer
        Public Top As Integer
        Public Width As Integer
        Public Height As Integer
    End Structure

    Public Structure WindowPlacement
        Public Length As Integer
        Public Flags As Integer
        Public ShowCommand As Integer
        Public MinPosition As IntegerPoint
        Public MaxPosition As IntegerPoint
        Public NormalPosition As IntegerRect
    End Structure
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 69

Assisted Solution

by:Éric Moreau
Éric Moreau earned 250 total points
Comment Utility
the () after the property name indicates that the property is an array which in this case does not fit the definition of a point
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
What is the exact error you are getting now? Please post.
0
 
LVL 32

Accepted Solution

by:
it_saige earned 250 total points
Comment Utility
You are missing the new line specifier in your original code:
<StructLayout(LayoutKind.Sequential)> _
Public Structure IntegerPoint
	Public Property X() As Integer
	Public Property Y() As Integer
End Structure

Open in new window

Notice that the error indicator starts on the end of your StructLayout line, this indicates that the error starts here:Capture.JPGWith regards to array declaration, for properties, you specify if you want the property to be an array by using the array notation on the Type.

Proof of concept -
Imports System.Runtime.InteropServices

Module Module1
	Sub Main()
		Dim point1 As New IntegerPoint() With {.X = 1, .Y = 2, .XArr = New Integer() {1, 2, 3, 4, 5}, .YArr = New Integer() {1, 2, 3, 4, 5}}
		Console.WriteLine("X = {0}, Y = {1}, X-Array = {{{2}}}, Y-Array = {{{3}}}", point1.X, point1.Y, String.Join(";", point1.XArr), String.Join(";", point1.YArr))
		Console.ReadLine()
	End Sub
End Module

<StructLayout(LayoutKind.Sequential)> _
Public Structure IntegerPoint
	'' Not an array
	Public Property X() As Integer
	'' Not an array
	Public Property Y As Integer
	'' ARRAY HERE
	Public Property XArr() As Integer()
	'' ARRAY HERE
	Public Property YArr As Integer()
End Structure

Open in new window

Which produces the following output -Capture.JPGTrying to use the X property as an array results in -Capture.JPG-saige-
0
 
LVL 1

Author Comment

by:HLRosenberger
Comment Utility
Thanks for the help.
0
 
LVL 1

Author Closing Comment

by:HLRosenberger
Comment Utility
thanks.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now