PDA

View Full Version : Need Help With a User Form



Saladsamurai
01-27-2010, 08:01 PM
PLEASE GO STRAIGHT TO POST #12 where I have redefined the problem. Thanks


Hey guys and gals :hi: ,

I need some help with a UserForm as I don't know much about them. I have made some simple ones, but awhile ago. This one is probably really easy for you, so some pointers would be appreciated.

I am pretty open to suggestions on this too. So here is what I hope to accomplish:

I have a program that uses a couple of input boxes to grab some info from the user. The input that it gets from those initial input boxes will determine some things about the UserForm.

I prompt the user for 2 variables: 'nElements' (the number of elements) and 'nNodes' (the number of nodal points).

These variables are representative of a geometry problem. Each Element has 2 nodal points on it. So I would like to now ask the user with a UserForm which nodes are connected by which elements.

So I would like to do it like this:
For i = 1 to nElements

A UserForm pops up and says: "Element i Connects " and then there are 2 dropdown boxes or lists that are populated with the integers '1 To nNodes'.

That way for each element they can choose the 2 nodes that correspond to the element. So my main questions are these:



1.) What is the 'best way' to display the UserForm 'nElements' number of times and grab the data from the controls?

2.) How do I populate the list boxes or dropdowns with the numbers "1 To nNodes" ?


Ant thoughts would be great. And let me know if something is not clear.

thanks!! : pray2:

Saladsamurai
01-27-2010, 08:21 PM
OK: Here is what I have started, if there is a better way, shout it out!


Sub UserFormDevelopment()
Dim i
For i = 1 To 5
UserForm1.Caption = "Element " & i & " - Node Connections"
UserForm1.Show
'Pass collected data to an array or something
Next i
End Sub



Now for the OK and Cancel buttons I have:

Option Explicit

Private Sub Cancel_Button_Click()
Unload UserForm1
End Sub

Private Sub OK_Button_Click()

End Sub

But when they click 'OK' it needs to advance the UserForm to the 'Next i' in Sub UserFormDev(). But since the OK button is in a different Sub, I am confused.

perhaps there is a better way?

lucas
01-27-2010, 08:38 PM
Private Sub UserForm_Initialize()
Dim i
For i = 1 To 5
UserForm1.Caption = "Element " & i & " - Node Connections"
Next i
End Sub

Saladsamurai
01-27-2010, 08:46 PM
Private Sub UserForm_Initialize()
Dim i
For i = 1 To 5
UserForm1.Caption = "Element " & i & " - Node Connections"
Next i
End Sub


Hi Lucas! I am sorry, but I do not really see what this does? I need the Form to show for one thing. And then when it does, the user enters data and hits 'OK' at which point I need the Useform to reload as Element 2 - Node..etc and so on.

lucas
01-27-2010, 08:58 PM
Why are you using input boxes?

Saladsamurai
01-27-2010, 09:05 PM
Why are you using input boxes?

lucas, sorry again, but I don't see how your question is relevant :dunno I am not trying to be difficult here, but my question is about userforms. What do the input boxes that occur 'before' the UserForms have to do with anything?

lucas
01-27-2010, 09:11 PM
If you used textboxes on the userform it seems to me you could avoid using global variables. Just a thought. Plus, input boxes are not as clean or managable as textboxes on a userform in my opinion.

lucas
01-27-2010, 09:13 PM
Maybe you could just describe what you are trying to do in plain English without the psudo code. I'm having trouble understanding your project.

Saladsamurai
01-27-2010, 09:17 PM
If you used textboxes on the userform it seems to me you could avoid using global variables. Just a thought. Plus, input boxes are not as clean or managable as textboxes on a userform in my opinion.

OK. I am kind of with you. But i still don't know how to make what you are saying into something tangible.

Are you suggesting that instead of using input boxes and then a Userform, that I just do everything from the UserForm?

Perhaps you could help shine a little light on the flow of the program?

I had been using input boxes, because the number of times the Userform is loaded *depends on* those values coming from the input boxes.

See what i am saying?

lucas
01-27-2010, 09:26 PM
let the "depends on" happen when the textbox is updated.

lucas
01-27-2010, 09:27 PM
like this. See attached

Saladsamurai
01-28-2010, 11:22 AM
OK. Do-over! Obviously I have failed to describe the problem well enough such that anyone besides myself can understand it.
After looking at your attached file, it would appear that what I have described is me needing a simple input box,
which is what you made except that now it's called a UserForm.

So let me re-explain the problem:

I have 1 UserForm. It is fine; there are no problems with it. It takes 2 values from the user. It looks like this:

http://i12.photobucket.com/albums/a220/saladsamurai/ff130e5e.jpg

Now, I need another UserForm. Some of the details of this other UserForm, that we will call UserForm2,
depend on the values that were entered in UserForm1.

Let's call the first value (top value) that UserForm1 asks for 'X'.
Let's call the second value that UserForm1 asks for 'Y'.
We will refer back to these values in a moment.
But first, I have put together an example of what the program should do.
So let's go through what I would like to be the user's experience:



1.) They are prompted with the following UserForm1:

http://i12.photobucket.com/albums/a220/saladsamurai/ff130e5e.jpg


2.) Let's say that they type in 3 for the first value and 5 for the second value. They hit 'OK' and now the following happens:

UserForm2 appears; it looks like this at first:

http://i12.photobucket.com/albums/a220/saladsamurai/1.jpg

The user now makes some selections from the dropboxes which are populated with the numbers 1 - Y or in this particular exampl, 1- 5.

Notice that the 'Blue' caption and the label in the Form say Element 1

Now they hit 'OK' and the exact same UserForm2 shows up again except that it looks like this now:

http://i12.photobucket.com/albums/a220/saladsamurai/2.jpg

Notice that the 'Blue' caption and the label in the Form say Element 2 this time.

Now they hit 'OK' for the last time and they again see:

http://i12.photobucket.com/albums/a220/saladsamurai/3.jpg

which now says Element 3.

Now they hit 'OK' and a bunch of stuff that I have not figured out yet happens. But note that the UserForm2 appeared 'X' number of time, or 3 in this case, which came from UserForm1.



What I need is some help with the logic of this. I think that I have figured out how to dynamically rename the labels 'Element 1,2,...,X' by using a For Loop.

However, cannot figure out how after the first instance of displaying UserForm2 I can make it so that when the user hits 'OK' it goes back into the For Loop so that it can advance to the next 'version' of UserForm2.


For Example, if I write a loop like this:


Sub MyUserForms ()

For i = 1 to X
UserForm2.Caption = "Element" & i
UserForm2.Show
Next i

End Sub



The Next i is never reached, beacuse the UserForm2 displays and then the user hits 'OK' which is not a part of the Sub including the 'Next i' part of the Loop.

:help

lucas
01-28-2010, 11:35 AM
What does the numbers that are entered into userform 1 have to do with userform 2?

How are they used by userform 2?

It seems to me like this can all be done on one userform once we figure out what you are trying to do....

Saladsamurai
01-28-2010, 11:42 AM
Honestly lucas, I don't know how to put it any other way. Did you even read what I just took 45 minutes to post? I'm not trying to sound like a dick here, but I explain exactly where the numbers that are entered in UserForm1 are used in UserForm2.


Let's call the first value (top value) that UserForm1 asks for 'X'.
Let's call the second value that UserForm1 asks for 'Y'.
We will refer back to these values in a moment.


UserForm2 appears; it looks like this at first:...he user now makes some selections from the dropboxes which are populated with the numbers 1 - Y or in this particular exampl, 1- 5.



...note that the UserForm2 appeared 'X' number of time, or 3 in this case, which came from UserForm1.



Which part exactly is not clear?

lucas
01-28-2010, 11:48 AM
Ok, I did re-read it and I think I understand.

I have created a textbox where you put in a number.

When you exit the textbox, the combobox is populated with the numbers from 1 to the number entered into the textbox.

see attached.

Tommy
01-28-2010, 12:10 PM
Try this:

Hey Steve :hi:

Tommy
01-28-2010, 12:14 PM
Well SPIT! I did a Word form instead of an Excel Form!!! Oh well I can export it and then import it.

lucas
01-28-2010, 12:23 PM
Hi Tommy, It works just as well in word but my problem has been trying to understand what he's trying to do......

take a look at my example at post 15. It seems to do what he's trying to accomplish but if you put in a double digit number it duplicates some of the numbers......I don't understand why.

ps big winter storm hitting us right now. How's the weather down south?
I'm getting low on firewood and will have to get out and cut some after this storm passes. Been a cold winter here.

Tommy
01-28-2010, 12:33 PM
Steve it is because it is in the text change. take it to the text exit cause then it will only fire once. FYI if you had entered 100 look at what happens. LOL

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim i
For i = 1 To TextBox1.Value
ComboBox1.AddItem i
Next i
End Sub

We actually had a freeze in December. I used up some of the wood from Ike and found 3 more trees to cut up for this weekend (all from Ike), it is supposed to get cold again. We are in the 50's most of the time.

lucas
01-28-2010, 12:56 PM
That did it. Thanks. The simplest things sometimes.

Well I envy you your warm weather. I'm tired of winter here.

Tommy
01-28-2010, 01:20 PM
The first time I came across that little bit of bite your backside was when I was trying to capture a customer's name to lookup in a database. Needless to say I got some real wild results.

I only get to see the sun through the blinds of my office, except for Weekends, so I feel your pain.

We have got to qite highjacking threads like this LOL