Please help VBA Newbe with second project ever.

Please help VBA Newbe with second project ever.

mid-awe
Collaborator Collaborator
788 Views
24 Replies
Message 1 of 25

Please help VBA Newbe with second project ever.

mid-awe
Collaborator
Collaborator
Hey all,

I'm struggling with learning the most basic VBA concepts. I know how to program from my experience with LISP and the old BASIC so the handling of variables and stuff is easy for me but I need to know how to get the user's input from a text box and store it as a variable that I'll show in the dialogue in a label. I have labels 1 through 119 and I'll increment the numbers as data is entered by a control button. Now when this button is clicked or enter is pressed on the keyboard I'd like to get the value or whatever it's called from the textbox and assign that value to the appropriate label.

Can anyone please help. Thanks in advance.
0 Likes
789 Views
24 Replies
Replies (24)
Message 2 of 25

Anonymous
Not applicable
Maybe I’m missing something but it sounds like what you want to do is something like
Variable = TextBox.Text
Label.caption = variable.
0 Likes
Message 3 of 25

mid-awe
Collaborator
Collaborator
I'll give it a try thanks.
0 Likes
Message 4 of 25

mid-awe
Collaborator
Collaborator
I also think that I'm going to have to use a variable as a name of a variable. I'm sure that is probably confusion so I'll explain. I need the names of the labels to increment each time data is entered into the textbox and the command button is clicked. example:

J48591 = first click becomes label1.caption

J48639 = second click becomes label2.caption

J46320 = third click becomes label3.caption
etc.,etc.

can I just use a variable.lable ? or is there some other way?

Am I going to have to create an array?
0 Likes
Message 5 of 25

Anonymous
Not applicable
Hi,

In general (and certainly not with the programming skills of a learner) VBA
controls cannot be renamed.

You could put 120 labels in the same place and control their visibility with
code, so that only one is visible by use Previous and Next controls - and
each time these controls are used, read the value to an array based on a
counter. These controls have a reference number in the control set of the
form. Hence you could do some along the lines of this psuedo code
For i = x to y
Form.Item( i).visible = false
next i
Form.Item( counter).visible = true

You could also use a list box holding the counter number and use it to
control the visibility of the text boxes.

I would include a label which describes what that particular texzt box is
requiring for data entry.

--

Laurie Comerford
CADApps
www.cadapps.com.au
wrote in message news:4930195@discussion.autodesk.com...
I also think that I'm going to have to use a variable as a name of a
variable. I'm sure that is probably confusion so I'll explain. I need the
names of the labels to increment each time data is entered into the textbox
and the command button is clicked. example:

J48591 = first click becomes label1.caption

J48639 = second click becomes label2.caption

J46320 = third click becomes label3.caption
etc.,etc.

can I just use a variable.lable ? or is there some other way?

Am I going to have to create an array?
0 Likes
Message 6 of 25

mid-awe
Collaborator
Collaborator
I'm not really trying to change the visibility of the labels but it's a good idea. What I want is to have the data sent to the label after button clicking. I need the program to know that if the last data was sent to label1 then the next time the button is clicked it should be sent to label2 and so on. below is what I have so far:
[code]Dim Varcnt As Variant
Dim LblVar As Variant
Dim JNUM As Variant

Public Sub MutiPlot()
Varcnt = 1
End Sub


Private Sub Label1_Click()

Label1.Caption = JNUM
JNUM = DataEnter.Text

End Sub

Private Sub Lst_Add_Click()

Set LblVar = "Label" + Varcnt

JNUM = DataEnter.Text
LblVar.Caption = JNUM

Varcnt = Varcnt + 1

End Sub[/code]
This of course give me and error but I am unable to correct it.

Thanks for all your help
0 Likes
Message 7 of 25

Anonymous
Not applicable
too bad vba does not support control arrays

one could try something like
Dim ctl As Object
Dim i As Integer
i = 1
For Each ctl In Me.Controls
If TypeOf ctl Is Label Then
If ctl.Name = "Label" & i Then
ctl.Caption = "Label caption " & i
End If

End If
i = i + 1
Next ctl

But since you have over 100 labels (yikes!?!)
that's not a very elegant solution
hopefully someone can do better

Mark



wrote in message news:4930325@discussion.autodesk.com...


Set LblVar = "Label" + Varcnt
0 Likes
Message 8 of 25

mid-awe
Collaborator
Collaborator
The 119 labels are for the 119 job numbers that I'm allowing the user to type in before running the remainder of code. The user must be able to view a complete list of the numbers that they type in and make changes if necessary before continuing the code. I would do more than 119 if a reasonably sized dialogue could fit them in.
Thanks for the suggestion I'll try it.
0 Likes
Message 9 of 25

mid-awe
Collaborator
Collaborator
Sorry, I only received an error stating that the object doesn't support this property or method.
Any other suggestions?

Thanks in advance.
0 Likes
Message 10 of 25

Anonymous
Not applicable
Here is another idea. Class is light, just a sample. Something
to play with anyway.

sorry if this goes through more than once.

wrote in message news:4930359@discussion.autodesk.com...
Sorry, I only received an error stating that the object doesn't support this
property or method.
Any other suggestions?

Thanks in advance.
0 Likes
Message 11 of 25

Anonymous
Not applicable
user has to type in 119 job numbers to start?
are you sure a combo box or list box wouldn't work?
a scroll bar will appear when the contents exceed the size of box
you can also design the form to be resizable if need be.
I'm only suggesting to consider various alternatives to your user interface
before going too far down a very unusual path.
not to be critical but the use of labels for this seems very different from
the usual dialog interface.

Does the user have to type all the data in?
you cant select from a pre-filled list? a directory of folders?

just trying to throw out ideas

hth
Mark


wrote in message news:4930358@discussion.autodesk.com...
The 119 labels are for the 119 job numbers that I'm allowing the user to
type in before running the remainder of code. The user must be able to view
a complete list of the numbers that they type in and make changes if
necessary before continuing the code. I would do more than 119 if a
reasonably sized dialogue could fit them in.
Thanks for the suggestion I'll try it.
0 Likes
Message 12 of 25

Anonymous
Not applicable
what line is the error on?

Mark



wrote in message news:4930359@discussion.autodesk.com...
Sorry, I only received an error stating that the object doesn't support this
property or method.
Any other suggestions?

Thanks in advance.
0 Likes
Message 13 of 25

Anonymous
Not applicable
Hi,

I'm agreeing with Mark.

As well, consider that any form of user input which requires the user to
type in 100+ items of data is an almost certain guarantee of user input
error.

Can you plan to populate your fields with some sort of data (maybe the last
used data set) and have the user only need to edit the changed ones?

--

Regards,


Laurie Comerford
www.cadapps.com.au

"MP" wrote in message
news:4930435@discussion.autodesk.com...
user has to type in 119 job numbers to start?
are you sure a combo box or list box wouldn't work?
a scroll bar will appear when the contents exceed the size of box
you can also design the form to be resizable if need be.
I'm only suggesting to consider various alternatives to your user interface
before going too far down a very unusual path.
not to be critical but the use of labels for this seems very different from
the usual dialog interface.

Does the user have to type all the data in?
you cant select from a pre-filled list? a directory of folders?

just trying to throw out ideas

hth
Mark


wrote in message news:4930358@discussion.autodesk.com...
The 119 labels are for the 119 job numbers that I'm allowing the user to
type in before running the remainder of code. The user must be able to view
a complete list of the numbers that they type in and make changes if
necessary before continuing the code. I would do more than 119 if a
reasonably sized dialogue could fit them in.
Thanks for the suggestion I'll try it.
0 Likes
Message 14 of 25

mid-awe
Collaborator
Collaborator
Ok, it's working now except it only updates the label1 and none of the others. I can click as often as I like but it still assigns the data to label1. any ideas?

Thanks
0 Likes
Message 15 of 25

mid-awe
Collaborator
Collaborator
I'm sorry if I miscomunicated. It allows the user to type in up to 119 Job numbers before they are forced to run the code. If they only type in one Job number it should also work. But it may happen that they will have 200 job numbers at times and they can only run the code for 119 at a time.
0 Likes
Message 16 of 25

Anonymous
Not applicable
>Case -2147024809
>clickCounter.CounterValue = 1
Resume CommandButton1_Click_Exit

I forgot this statement here.
Resume CommandButton1_Click_Exit

"Paul Richardson" wrote in message
news:4930419@discussion.autodesk.com...
Here is another idea. Class is light, just a sample. Something
to play with anyway.

sorry if this goes through more than once.

wrote in message news:4930359@discussion.autodesk.com...
Sorry, I only received an error stating that the object doesn't support this
property or method.
Any other suggestions?

Thanks in advance.
0 Likes
Message 17 of 25

mid-awe
Collaborator
Collaborator
Thanks, I'll give it a try.
0 Likes
Message 18 of 25

Anonymous
Not applicable
I think that because you're coming from LISP, you may
be approaching the design of your UI with the limitations
of what you're used to, which IMO, is a mistake.

The 120 label thing is certainly not the way to go, although
that might be the only avenue if you were using LISP/DCL,
but you're not in DCL purgatory any longer with VBA.

First you should forget about the limitations and constraints
that you're used to designing user interfaces with, and look
at what else VBA has to offer.

Given what you've described so for, it's fairly obvious that
your interface needs to be some type of grid or listview,
that has two columns, one or both of which are editable.

If you are writing code for others, then they deserve better
than a VBA application with a user interface that suffers
from the the inherent (and quite rediculous, if I may say so)
constraints of LISP/DCL.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

wrote in message news:4930455@discussion.autodesk.com...
I'm sorry if I miscomunicated. It allows the user to type in up to 119 Job numbers before they are forced to run the code. If they only type in one Job number it should also work. But it may happen that they will have 200 job numbers at times and they can only run the code for 119 at a time.
0 Likes
Message 19 of 25

mid-awe
Collaborator
Collaborator
Thanks. I see you example works great., but when I try to apply it to my program it doesn't work. I have all of my labels in a separate frame from the frame that hold the command button. Is this possibly why it fails and what can I do to fix it?

Thanks again.
0 Likes
Message 20 of 25

Anonymous
Not applicable
the program looks for Label1-Label...
You would need to edit for your label
names. I would just use it as an example
and take the advice of others here in your
design.

wrote in message news:4931237@discussion.autodesk.com...
Thanks. I see you example works great., but when I try to apply it to my
program it doesn't work. I have all of my labels in a separate frame from
the frame that hold the command button. Is this possibly why it fails and
what can I do to fix it?

Thanks again.
0 Likes