How to Draw Lines on a Visual Basic Fourm

#1

  • New D.I.C Head

Reputation: 0

  • View blog
  • Posts: 4
  • Joined: 17-May 15

Drawing a line from a module to a form

Posted 17 May 2015 - 01:19 PM

Hello. In my project I have a module and I want to draw some lines to my Form1. Because I have to draw many lines I used the following code:

With Form1 .Line (StartPoint.X, StartPoint.Y)-(StartPoint.X + Lenght, StartPoint.Y) .Line (StartPoint.X, StartPoint.Y)-(StartPoint.X, StartPoint.Y + Lenght)  .Line (StartPoint.X + Lenght, StartPoint.Y + Lenght)-(StartPoint.X, StartPoint.Y + Lenght) .Line (StartPoint.X + Lenght, StartPoint.Y + Lenght)-(StartPoint.X + Lenght, StartPoint.Y) End With            

But it seems that it doesn't work. The error says "Expected '='"(instead of "-"). Why it doesn't work?Can you help me? Sorry for my mistakes...This is not my original language.


Is This A Good Question/Topic? 0

  • +

#2 maceysoftware User is offline

Reputation: 396

  • View blog
  • Posts: 1,672
  • Joined: 07-September 13

Re: Drawing a line from a module to a form

Posted 18 May 2015 - 03:16 AM

Hello,

I believe this is because your drawing this in the wrong place, i believe paint actions in vb6 can only happen within the paint routine (i could be wrong about this however as i am a .Net developer not a vb6, and .Net you can paint from anywhere to a point).

You also dont need form1.line you just need line. this will correct your first issue.

Private Sub Form_Paint() Line (StartPoint.X, StartPoint.Y)-(StartPoint.X + Lenght, StartPoint.Y) Line (StartPoint.X, StartPoint.Y)-(StartPoint.X, StartPoint.Y + Lenght)  Line (StartPoint.X + Lenght, StartPoint.Y + Lenght)-(StartPoint.X, StartPoint.Y + Lenght) Line (StartPoint.X + Lenght, StartPoint.Y + Lenght)-(StartPoint.X + Lenght, StartPoint.Y) End Sub            

The second issue i found is 'object required' which is because your startpoint is a property on the form i am guessing? so you shouldn't run into this issue.

#3 maj3091 User is offline

Reputation: 331

  • View blog
  • Posts: 2,005
  • Joined: 26-March 09

Re: Drawing a line from a module to a form

Posted 20 May 2015 - 12:38 AM

You can draw from a module, but try passing in your form as as a parameter

Public Sub DrawOnForm(frmDrawOnMe As Form)      frmDrawOnMe.Line (10, 10)-(200, 200)  End Sub            

then call it with

DrawOnForm Form1            

This post has been edited by maj3091: 20 May 2015 - 12:39 AM

#4 [email protected] User is offline

  • New D.I.C Head

Reputation: 0

  • View blog
  • Posts: 4
  • Joined: 17-May 15

Re: Drawing a line from a module to a form

Posted 20 May 2015 - 03:07 AM

View Postmaj3091, on 20 May 2015 - 12:38 AM, said:

You can draw from a module, but try passing in your form as as a parameter

Public Sub DrawOnForm(frmDrawOnMe As Form)      frmDrawOnMe.Line (10, 10)-(200, 200)  End Sub              

then call it with

DrawOnForm Form1              

But I want to use "with...". I done this already but there are too many lines and that's why I wanted to use "with".

#5 modi123_1 User is online

Reputation: 16466

  • View blog
  • Posts: 65,285
  • Joined: 12-June 08

Re: Drawing a line from a module to a form

Posted 20 May 2015 - 06:44 AM

I would start with shoring up your code.
Typically methods are called by:

<method name>(<parameter1>, <parameter2>, ... )            

Notice how parentheses close around the parameters.

I certainly do not see that here.

2	.Line (StartPoint.X, StartPoint.Y)-(StartPoint.X + Lenght, StartPoint.Y)            

Close that up so the compiler is 100% certain you are shoving parameters in there.

Quote

.Line ( (StartPoint.X, StartPoint.Y)-(StartPoint.X + Lenght, StartPoint.Y) )

Of course repeat for the others... and if that is not your intended logic flow then you need to sort that out first.

#6 maj3091 User is offline

Reputation: 331

  • View blog
  • Posts: 2,005
  • Joined: 26-March 09

Re: Drawing a line from a module to a form

Posted 21 May 2015 - 12:06 AM

View Post[email protected], on 20 May 2015 - 10:07 AM, said:

View Postmaj3091, on 20 May 2015 - 12:38 AM, said:

You can draw from a module, but try passing in your form as as a parameter

Public Sub DrawOnForm(frmDrawOnMe As Form)      frmDrawOnMe.Line (10, 10)-(200, 200)  End Sub                

then call it with

DrawOnForm Form1                

But I want to use "with...". I done this already but there are too many lines and that's why I wanted to use "with".

You didn't explicitly say you need to use WITH.

The line function can't be used with With and end with.

The comment below is direct from MSDN

Quote

This method cannot be used in an WithEnd With block.


#7 BobRodes User is offline

Reputation: 607

  • View blog
  • Posts: 3,086
  • Joined: 19-May 09

Re: Drawing a line from a module to a form

Posted 04 June 2015 - 07:57 PM

View Postmodi123_1, on 20 May 2015 - 08:44 AM, said:

I would start with shoring up your code.
Typically methods are called by:

<method name>(<parameter1>, <parameter2>, ... )              

Notice how parentheses close around the parameters.

I certainly do not see that here.

2	.Line (StartPoint.X, StartPoint.Y)-(StartPoint.X + Lenght, StartPoint.Y)              

Close that up so the compiler is 100% certain you are shoving parameters in there.

Quote

.Line ( (StartPoint.X, StartPoint.Y)-(StartPoint.X + Lenght, StartPoint.Y) )

Of course repeat for the others... and if that is not your intended logic flow then you need to sort that out first.

VB6 is atypical in this regard. If the method is a Sub, the parameters aren't enclosed in parentheses (unless you use the Call keyword which was deprecated as of 3.0). Function calls use parentheses. What's more, the syntax for the Line function is entirely aberrant: object.Line [Step] (x1, y1) [Step] - (x2, y2), [color], [B][F] . So, it's as Maj has it. (By the way, the reason you can't use With here is because Line is a method of object, not of Form1.) Parentheses must be as they are here; "proper" parameterization is not an option. (Well it is an option, one that won't compile. But anyway.) And that's not the whole story. Check out this code:

Sub Command1_Click() Dim x As Integer x = 10 TryThis x Debug.Print x x = 10 TryThis (x) Debug.Print x End Sub  Sub TryThis(x As Integer) x = x + 10 End Sub            

The output to the Immediate window is

20
10

Why? :)

This post has been edited by BobRodes: 04 June 2015 - 08:12 PM

#8 maj3091 User is offline

Reputation: 331

  • View blog
  • Posts: 2,005
  • Joined: 26-March 09

Re: Drawing a line from a module to a form

Posted 04 June 2015 - 11:07 PM

Good to see you again Bob.

View PostBobRodes, on 05 June 2015 - 03:57 AM, said:

VB6 is atypical in this regard. If the method is a Sub, the parameters aren't enclosed in parentheses (unless you use the Call keyword which was deprecated as of 3.0). Function calls use parentheses. What's more, the syntax for the Line function is entirely aberrant: object.Line [Step] (x1, y1) [Step] - (x2, y2), [color], [B][F] . So, it's as Maj has it. (By the way, the reason you can't use With here is because Line is a method of object, not of Form1.) Parentheses must be as they are here; "proper" parameterization is not an option. (Well it is an option, one that won't compile. But anyway.) And that's not the whole story. Check out this code:

Sub Command1_Click() Dim x As Integer x = 10 TryThis x Debug.Print x x = 10 TryThis (x) Debug.Print x End Sub  Sub TryThis(x As Integer) x = x + 10 End Sub              

The output to the Immediate window is

20
10

Why? :)/>/>

Looks like using parentheses overrides the default ByRef behaviour, unless it's explicitly stated in the sub definition?

You learn something new every day! :)/>

This post has been edited by maj3091: 04 June 2015 - 11:08 PM

#9 BobRodes User is offline

Reputation: 607

  • View blog
  • Posts: 3,086
  • Joined: 19-May 09

Re: Drawing a line from a module to a form

Posted 05 June 2015 - 09:33 AM

That's correct. :) It's syntax from early versions of VB, and if you are a .Net person who has inherited some legacy VB6 code and don't know this, you may parenthesize method calls in the proper manner as you have been taught. Thereby creating some spectacular bugs that the Ancient Ones can charge a great deal of money to fix.

How to Draw Lines on a Visual Basic Fourm

Source: https://www.dreamincode.net/forums/topic/376101-drawing-a-line-from-a-module-to-a-form/

0 Response to "How to Draw Lines on a Visual Basic Fourm"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel