UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Inputbox List, Office 2010    
 
   
PaulBrand
post Sep 6 2019, 03:28 AM
Post#1



Posts: 1,720
Joined: 4-September 02
From: Oxford UK


Hi,

I'm trying to gather user input as comma separated list from an InputBox, then splitting them into a ParamArray later. What I'd like is to convert my input as accdr, xlsx, doc into an array wrapped in quotes eg. "accdr"

I've written the function below which works, but how do I wrap the user input with quotes

CODE
Public Function Extensions() As Variant
Dim strList As String

    strList = InputBox("Enter file extensions separated by commas.")
    Extensions = strList
    
    
End Function

--------------------
Paul
Go to the top of the page
 
pere_de_chipstic...
post Sep 6 2019, 04:50 AM
Post#2


UtterAccess Editor
Posts: 10,507
Joined: 8-November 07
From: South coast, England


Hi have you tried using the split function?

e.g.
CODE
Public Function Extensions() As Variant
Dim strList As String
Dim strListA() as string
Dim i as byte

    strList = InputBox("Enter file extensions separated by commas.")
    strListA() = Split(strList, ",")
    for i = 0 to Ubound(strListA)
       Extensions = Extensions  & CHR(34) & strListA(i) & CHR(34) & ","
    next i  
    
End Function

-Air code - not tested!

hth
This post has been edited by pere_de_chipstick: Sep 6 2019, 04:52 AM

--------------------
Warm regards
Bernie
Go to the top of the page
 
pere_de_chipstic...
post Sep 6 2019, 05:07 AM
Post#3


UtterAccess Editor
Posts: 10,507
Joined: 8-November 07
From: South coast, England


Another option might be:

Extensions = CHR(34) & Replace(strList ,",", CHR(34) & "," & CHR(34)) & CHR(34)

--------------------
Warm regards
Bernie
Go to the top of the page
 
ADezii
post Sep 6 2019, 07:33 AM
Post#4



Posts: 2,674
Joined: 4-February 07
From: USA, Florida, Delray Beach


I like pere's 2nd approach:
CODE
Dim strNewString As String
Const conTEST_STRING = "accdr,xlsx,docx,pptx,mdb"

strNewString = Chr$(34) & Replace(conTEST_STRING, ",", Chr$(34) & "," & Chr$(34)) & Chr$(34)

Debug.Print strNewString

CODE
"accdr","xlsx","docx","pptx","mdb"

Go to the top of the page
 
kfield7
post Sep 6 2019, 08:55 AM
Post#5



Posts: 1,003
Joined: 12-November 03
From: Iowa Lot


the approach has some potential obstacles, i.e., users conforming to the desired input structure (e.g., forgetting a comma, hitting "." instead of ",", etc.

To input a list I would prefer a continuous form tied to an input table.

either that, or getting the input one item at a time, looping until the user is finished.

With these alternate approaches, you can also force the user to conform to the extensions specified.

I guess you could QA the CSV list and push it back to the user for correction, so maybe I'm overthinking this.
This post has been edited by kfield7: Sep 6 2019, 08:58 AM
Go to the top of the page
 
ADezii
post Sep 6 2019, 09:39 AM
Post#6



Posts: 2,674
Joined: 4-February 07
From: USA, Florida, Delray Beach


QUOTE
I guess you could QA the CSV list and push it back to the user for correction

This is also what I was thinking, display the Formatted String and have the User validate it in a Msgbox (vbYesNoCancel). If it is OK, proceed as normal, if not Loop again for either another Input or Cancel the Operation altogther.
This post has been edited by ADezii: Sep 6 2019, 09:41 AM
Go to the top of the page
 
GroverParkGeorge
post Sep 6 2019, 10:14 AM
Post#7


UA Admin
Posts: 35,842
Joined: 20-June 02
From: Newcastle, WA


I wholeheartedly agree with using a multi-select listbox, not a free form (read "anything goes") input box.

File extensions are in a relatively closed domain of values. It's not finite, but it's highly stable. Few new extensions are created, and older extensions don't disappear. So, a Lookup table of "valid" extensions can be used to populate a Multi-Select Listbox on a form. Users click to select one or more of them to use and your code can then create the array without worrying about free-form text typing errors.

If they need an additional extension, one that isn't already in the Lookup table, you can provide a method to add it, although that's probably not going to be a frequent requirement.
This post has been edited by GroverParkGeorge: Sep 6 2019, 10:15 AM

--------------------
My Real Name Is George. Grover Park Consulting is where I do business.
How to Ask a Good Question
Beginning SQL Server
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    14th October 2019 - 01:31 PM