Solved

Windows and Extended desktop

Posted on 2016-08-08
9
46 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
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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 62

Expert Comment

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

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 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