Link to home
Start Free TrialLog in
Avatar of ODefaux
ODefaux

asked on

Excel/VB EditBox: assigning variable name to inputs

I have created a DialogBox with a number of different EditBoxes. In these EditBoxes, I wish to input data to which I would like to assign a variable name, later to be used in my code. What I have written so far looks as below (if I could get it to work, I'd be set,since this code would mean that I have successfully assigned EditBox inputs to a variable).

Sub DialogBox()
>     DialogSheets("Dialog1").EditBoxes(1).Text = 100
>     DialogSheets("Dialog1").EditBoxes(2).Text = 12
>     DialogSheets("Dialog1").Show
>     Set iterations = DialogSheets("Dialog1").EditBoxes(1)
>     Sheets("Assumptions Sheet").Activate
>     Range("A13").Value = iterations
> End Sub

My problem is that the DialogSheets object does not support the Value property -- how can I get around this?

With kind regards,

Olivier
Avatar of ChrisLewis
ChrisLewis

I believe what you want to do is use the  .TEXT property to return the value of a edit box.  

Similar to what you have written above, bu use the following:

Set iterations = DialogSheets("Dialog1").EditBoxes(1).text
Sheets("Assumptions Sheet").Activate
Range("A13").Value = iterations

Hope this helps.

CHris
Avatar of ODefaux

ASKER

The text property yields run-time error '424' -- object required.
Avatar of ODefaux

ASKER

The text property returns a run-time error 424 -- object required.
First of all, what line is the error being generated on.  

Second, if you go into debug mode at the SET ITERATIONS line, can you print what DialogSheets("Dialog1").EditBoxes(1).Text is.

Third, what do you have iterations declared as.  And are you using Option Explicit.  

Fourth, try
Range("A13").Value = DialogSheets("Dialog1").EditBoxes(1).text
instead of using the set variable.

Most likely, there's something funky with how you are declaring Iterations.  Sorry I didn't pick this up, but the SET keyword should have tipped me.  Set is used for objects, and you should be just using a straight assignment.

I use this code all over the place in a system with 5 dialogs with 10 fields each.  I haven't ever had a problem with this, but I use the RANGE() = Dialog,Editbox.text without the intermediate variable.


DIM iterations as STRING
iterations = DialogSheets("Dialog1").EditBoxes(1).text
Sheets("Assumptions Sheet").Activate
Range("A13").Value = iterations

Hope this helps,

Chris
Avatar of ODefaux

ASKER

Dear Chris,

In answer to your questions

The error is being generated on the "Set iterations" line -- run-time error 424 (object required).

I can 't print this line as I am currently not hooked up to a printer.

I am using Option Explicit and have iterations dimensioned as a Variant (only thing that doesn't seem to generate an error).

I tried setting Range("A13").Value = DialogSheets("Dialog1").EditBoxes(1).text just to see and it didn't work (run-time error 1004 -- Range method of Application class failed).  I actually need the iterations variable in my code to dimension a simulation I am doing, so even if it had worked, I still would have had to find a way to assign the Edit Box input to a variable name.  Perhaps one way would be to place the value in a range on the spreadsheet and then assign it a variable name?

Hope this clarifies somewhat.  I've been stuck on this for weeks.

Thanks again for your help. Sorry I have to keep rejecting your answer until I get closer to making this thing work.

Olivier

ASKER CERTIFIED SOLUTION
Avatar of ChrisLewis
ChrisLewis

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ODefaux

ASKER

The straight assignment did the trick (no set command)!  Thanks for the assistance and persistence.

Olivier