Solved

Windows and Extended desktop

Posted on 2016-08-08
9
62 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 41747276
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
ID: 41747283
Depends on the syntax error.
Otherwise, just check if this is on top of your code:

Imports System.Runtime.InteropServices
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 41747320
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:HLRosenberger
ID: 41747324
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
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 250 total points
ID: 41747330
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 63

Expert Comment

by:Fernando Soto
ID: 41747349
What is the exact error you are getting now? Please post.
0
 
LVL 34

Accepted Solution

by:
it_saige earned 250 total points
ID: 41747610
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
ID: 41749196
Thanks for the help.
0
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 41749197
thanks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Error import assembly 19 31
CHANGE FORM TEXT BEFORE IT SHOW TO USER 13 35
vb.net dbnull syntax 1 59
Call to SQL server times out 5 56
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

752 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