TheSwamp

Code Red => VB(A) => Topic started by: Keith™ on September 21, 2004, 12:09:40 AM

Title: (Challenge) Resizeable Form
Post by: Keith™ on September 21, 2004, 12:09:40 AM
Your mission, if you choose to accept, is to create a form in VBA that can be resized while the form is active....

Any takers?

I'll post something as soon as I figure out how to do it....
Title: (Challenge) Resizeable Form
Post by: MP on September 21, 2004, 12:17:21 AM
Just use the mouse events to determine if the left mouse is down and on the bottom edge, right edge, or lower right corner, then if it is dragged change the form's width and / or height (which is permissible) to reflect the mouse coordinates delta.
Title: (Challenge) Resizeable Form
Post by: Keith™ on September 21, 2004, 08:09:13 AM
....well where is the code ? ...

and I thought it would be a little bit harder than that... I guess I need to think about it a little more huh...
Title: (Challenge) Resizeable Form
Post by: MP on September 21, 2004, 08:20:41 AM
Had I the time I'd be more than happy to bash it out, but alas ...
Title: (Challenge) Resizeable Form
Post by: Jeff_M on September 21, 2004, 01:22:55 PM
Quote from: MP
Had I the time I'd be more than happy to bash it out, but alas ...
...someone already has.....  :wink:
No, I didn't write  this (http://www.cadvault.com/index.php?page=code&cats=29&view=128) but I remembered seeing it recently.
Title: (Challenge) Resizeable Form
Post by: Keith™ on September 21, 2004, 02:17:19 PM
must be something wrong with the web site, cause it won't let me log in (page not found error)

Who knows ....
Title: (Challenge) Resizeable Form
Post by: t-bear on September 21, 2004, 02:22:13 PM
I'm logged in but the link takes me to never-never land.........oh hum.
Title: (Challenge) Resizeable Form
Post by: Jeff_M on September 21, 2004, 02:44:03 PM
Well, I didn't realize that was a 'member only' area....sorry.  Here's the disclaimer from the page
Quote from: Cadvault

All of the code in the Public database was written by Randall Rath, members of the VBA Expresso (Credit given in the description field) community, or code released into public domain by MSDN and is to be considered "for example only." If you decide to use it in a production environment as is, you agree that you are doing so at your own risk. If you have suggestions for improvement or modification of any code samples please feel free to tell me about them.

And here's the code
Code: [Select]
Description:
Using the WIN32API and a bit of "slight of code" you can create a User Form that can be resized while running.
Snippet Code: - User Re-sizeable Form

Code removed to encourage development of new code.- JM
If you want to see the code, just go to CADVault.com, register and go to the Code Archives.
Title: (Challenge) Resizeable Form
Post by: Keith™ on September 21, 2004, 04:28:53 PM
I have seen that before ... Oh well...
Jeff.. thanks for the code, but the purpose of this challenge was to make us better programmers, not go out and see if we could find the code already done elsewhere.
Title: (Challenge) Resizeable Form
Post by: Jeff_M on September 22, 2004, 12:14:13 PM
My apologies. This is what happens when I check the forum when I'm in the middle of actually doing some work. I somehow missed the "Challenge" in the original title.  :oops:

So now the chalenge would be....Can this be done without calls to the Win32API?
Title: (Challenge) Resizeable Form
Post by: Keith™ on September 22, 2004, 02:02:28 PM
No problem ...
I suspect it CAN be done, I just have not had the time to look into it ... been busy on other proggies
Title: (Challenge) Resizeable Form
Post by: MP on September 22, 2004, 09:40:47 PM
... well where is the code ? ...

:lol:
Title: (Challenge) Resizeable Form
Post by: Keith™ on September 22, 2004, 11:07:35 PM
Here it is ....

Place in UserForm1 Code Window
Code: [Select]

'define these as global vars
Dim XPointPrev As Single
Dim YPointPrev As Single

Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If XPointPrev = 0 Then
 XPointPrev = X
End If
If YPointPrev = 0 Then
 YPointPrev = Y
End If
If (Button = 1) And (Shift = 0) And (X > UserForm1.Width - 20) And (Y > UserForm1.Height - 50) Then
 UserForm1.Width = UserForm1.Width + (X - XPointPrev)
 UserForm1.Height = UserForm1.Height + (Y - YPointPrev)
 XPointPrev = X
 YPointPrev = Y
ElseIf (Button = 1) And (Shift = 0) And (X > UserForm1.Width - 20) Then
 UserForm1.Width = UserForm1.Width + (X - XPointPrev)
 XPointPrev = X
ElseIf (Button = 1) And (Shift = 0) And (Y > UserForm1.Height - 50) Then
 UserForm1.Height = UserForm1.Height + (Y - YPointPrev)
 YPointPrev = Y
End If
If (Button = 0) Then
 XPointPrev = 0
 YPointPrev = 0
End If
End Sub
Title: (Challenge) Resizeable Form
Post by: MP on September 22, 2004, 11:23:29 PM
Quote from: Keith
Here it is ....

Place in UserForm1 Code Window
Code: [Select]

'define these as global vars
Dim XPointPrev As Single
Dim YPointPrev As Single

...

Wouldn't it be more correct to declare 'em
Code: [Select]
Private _
    XPointPrev As Single, _
    YPointPrev As Single
at the form level?

Said another way, does VB let you use DIM at the module | form level?
Title: (Challenge) Resizeable Form
Post by: Keith™ on September 22, 2004, 11:35:50 PM
Either way I suppose... you can declare hem as private at form/module level and you can use DIM at both the module level and at the form level in VB as globals.

Personally, I seldom use private vars because of the simple fact I may need (or want) to access them from other modules.

Question is ... did it work for you?

Maybe it is bad coding practice but I declare them local while I am developing, then move them to global (if need be) when I am done.

I am thinking of another little challenge just so everyone can get their thinking caps on....
Title: (Challenge) Resizeable Form
Post by: daron on September 24, 2004, 11:23:53 AM
How about something to help us newbies to vba get started. Start something simple and develop it. Maybe use the cvs thingy?
Title: (Challenge) Resizeable Form
Post by: Keith™ on September 24, 2004, 11:39:37 AM
Where is the CVS thingy?
Title: (Challenge) Resizeable Form
Post by: daron on September 24, 2004, 11:50:18 AM
I believe it's here. (http://theswamp.org/phpBB2/viewtopic.php?p=25668#25668)