Ask Question Forum:
Model Library:2025-02-08:A.I. model is online auto reply
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by duncanb7
at 2024-09-13 01:10:37
Point:500 Replies:4 POST_ID:828527USER_ID:11059
Topic:
Visual Basic Programming;;Microsoft Excel Spreadsheet Software
I got one question on VBA, I am learning how to plot curve in vba and
find some example in goole seach and find following example and VBA code
But I am not familar with VBA userform1 usage , just want to know how to
let the form_paint() run to draw a curve. I try to run it in form_paint() but
it report "Me" word is not using correctly.
So the question is
What is "Me" means in the code, how to use it ?
Where the curve should be displayed, is it on userform window or Excel window ? how to make
it happen, Any good example for beginner ? Do I need to create userform1 first so then
call form_point() function, but how ? any simple code me to start ?
Pleae advise
Duncan
find some example in goole seach and find following example and VBA code
But I am not familar with VBA userform1 usage , just want to know how to
let the form_paint() run to draw a curve. I try to run it in form_paint() but
it report "Me" word is not using correctly.
So the question is
What is "Me" means in the code, how to use it ?
Where the curve should be displayed, is it on userform window or Excel window ? how to make
it happen, Any good example for beginner ? Do I need to create userform1 first so then
call form_point() function, but how ? any simple code me to start ?
Pleae advise
Duncan
Private Type POINTAPI x As Long y As LongEnd TypePrivate Declare Function PolyBezier Lib "gdi32.dll" (ByVal hdc As Long, lppt As POINTAPI, ByVal cPoints As Long) As LongPrivate Declare Function PolyBezierTo Lib "gdi32.dll" (ByVal hdc As Long, lppt As POINTAPI, ByVal cCount As Long) As LongPrivate Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As Any) As LongPrivate Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As LongPrivate Declare Function PolyPolygon Lib "gdi32.dll" (ByVal hdc As Long, lpPoint As POINTAPI, lpPolyCounts As Long, ByVal nCount As Long) As LongPrivate Sub Form_Paint() 'KPD-Team 2000 'URL: http://www.allapi.net/ 'E-Mail: KPDTeam@Allapi.net Dim pts(0 To 6) As POINTAPI Dim numpoints(0 To 1) As Long 'set the co¿¿dinates pts(0).x = 0: pts(0).y = 100 pts(1).x = 125: pts(1).y = 75 pts(2).x = 255: pts(2).y = 148 pts(3).x = 219: pts(3).y = 199 pts(4).x = 315: pts(4).y = 203 pts(5).x = 236: pts(5).y = 16 pts(6).x = 122: pts(6).y = 123 'set the forecolor to green Me.ForeColor = vbGreen 'draw the b¿¿ier PolyBezier Me.hdc, pts(0), 7 'set the forecolor to red Me.ForeColor = vbRed 'move the 'active' point MoveToEx Me.hdc, 200, 25, ByVal 0& 'set the co¿¿dinates pts(0).x = 125: pts(0).y = 50 pts(1).x = 123: pts(1).y = 200 pts(2).x = 102: pts(2).y = 100 pts(3).x = 102: pts(3).y = 100 pts(4).x = 312: pts(4).y = 75 pts(5).x = 289: pts(5).y = 125 'draw the b¿¿ier PolyBezierTo Me.hdc, pts(0), 6 'set the forecolor to blue Me.ForeColor = vbBlue 'set the points belonging to the rectangle pts(0).x = 20: pts(0).y = 10 pts(1).x = 200: pts(1).y = 10 pts(2).x = 200: pts(2).y = 190 pts(3).x = 20: pts(3).y = 190 numpoints(0) = 4 'set the points belonging to the triangle pts(4).x = 100: pts(4).y = 0 pts(5).x = 50: pts(5).y = 100 pts(6).x = 150: pts(6).y = 100 numpoints(1) = 3 'draw the polygons PolyPolygon Me.hdc, pts(0), numpoints(0), 2End Sub 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53:54:55:56:57:
Author: duncanb7 replied at 2024-09-13 03:09:46
If I set hdc instead me.hdc and put
hdc=Getforegroundwindow(), and it works better
Thanks for your reply
Duncan
hdc=Getforegroundwindow(), and it works better
Thanks for your reply
Duncan
Accepted Solution
Expert: andrewssd3 replied at 2024-09-13 02:14:20
500 points GOOD
That's why I suggested you do it another way. It's complicated and not easy to maintain and won't be guaranteed to work in future Office versions. But if you want to go down that route, take a look at this: http://www.cpearson.com/excel/formcontrol.aspx
Author: duncanb7 replied at 2024-09-13 02:04:14
ANd now I create an userform1 and add one command button to call Form_Paint() and
I replace the name of Form_paint() by Commandbutton1_Click(), now it won't report "Me"
error, porbably, ME is refer to userform1. But now report error on Me.hdc in which hdc is
not member. What is hdc, How can I find correct Me.hdc ?
Thanks
Duncan
I replace the name of Form_paint() by Commandbutton1_Click(), now it won't report "Me"
error, porbably, ME is refer to userform1. But now report error on Me.hdc in which hdc is
not member. What is hdc, How can I find correct Me.hdc ?
Thanks
Duncan
Expert: andrewssd3 replied at 2024-09-13 01:57:25
I think the code you have downloaded was probably created for VB6, and you'll find it difficult to get it working in Excel VBA. This code is intended to draw the shapes on a userform, which is not easy in VBA. Are you trying to draw shapes onto an Excel worksheet? If so there are various methods of the Shapes collection that you can look up online, for example AddPolyLine, AddCurve which allow you to do this without using Windows apis.