PDA

View Full Version : Solved: inputbox question



TrippyTom
07-08-2009, 01:46 AM
Am I right in thinking an inputbox only allows for 1 variable? I'd rather not have to make it a userform just to have access to 2 variables.

Here's the situation: I have a small macro that detected if the document was using A4 size setting or not, and adjusted the INPUT value to cm automatically, (inches if not a4).

This was all fine and dandy until people in China started using it - they use A4 paper but prefer to use inches. So now I have to add a variable so it will default to CM in A4 mode, but let them have a choice to switch to inches if they're in China.

Grr..... why are such minor things so frustrating?

John Wilson
07-09-2009, 03:44 AM
UserForm sounds like the answer!
Only way I can see to get two vars from an input box is to type them in seperated with comma eg

John,42

And then use Split to get the two variables

Sub chex()
Dim strIn As String
Dim StrSplit() As String
Do
strIn = InputBox("Type two Variables seperated with a comma")
'crude check for ,
Loop Until InStr(strIn, ",") > 1 Or strIn = ""
StrSplit = Split(strIn, ",")
MsgBox "var1= " & StrSplit(0) & vbCrLf & "var2= " & StrSplit(1)
End Sub

Looks error prone to me!

Paul_Hossler
07-09-2009, 07:28 AM
How about a single input (like Inbox likes), but allowing/requiring units ('cm' if blank)?

Your macro can take a single input from the user like any of these ...

10 = 10 cm
10cm
10in
10"

parse it to see if there are any units specified, and react accordingly.

Paul

TrippyTom
07-10-2009, 02:56 AM
Thanks for both of your suggestions. :thumb

I look forward to trying them out when I get back to work next week. Ah who am I kidding, I'll try it out at home since all I'm doing is lying in bed sick anyway.

John Wilson
07-10-2009, 04:39 AM
Sorry you're sick Tom!

Personally I WOULD use a form with a dropdown(or two). My experience is you can never predict what people will type into inputboxes.

"I know you made the code FOOLPROOF ...
....But you didn't factor in the ingenuity of fools!"

TrippyTom
07-13-2009, 03:47 PM
I ended up going with a userform. But thanks for that code to parse the text, I'm sure that will come in handy sometime!