Solved

Multiline input box

Posted on 2007-11-29
15
5,756 Views
Last Modified: 2010-04-21
Hello Expert,

I am looking for some code that makes a mulitiline inputbox (lets say 10 lines) to catch some lines and put them into a array. The functionality is planned to get multiple AD usernames seprated by ";". The usernames should be stored into an array.

The script should have the .vbs extention!

Thanks
0
Comment
Question by:Steynsk
  • 5
  • 4
  • 3
  • +1
15 Comments
 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 20375210
Better try using text box, make its property to multiline
0
 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 20375211
multiline property to True if you are using visual basic
0
 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 20375231
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 18

Expert Comment

by:Crash2100
ID: 20375750
Like that article mentioned, you can do this quite easily with the split command.  Something like this:

Dim x() As String
x = Split(Text1.Text, ";" & vbCrLf)
MsgBox x(1)
0
 
LVL 1

Author Comment

by:Steynsk
ID: 20376714
I don't understand. You guys tell me to use textbox and the multiline property. But I don't need the the code in webpage but in a .vbs script (wscript). Or does this not mater?

Can someone please send a sample?

Thanks
0
 
LVL 18

Expert Comment

by:Crash2100
ID: 20377734
I missed the part about using VBS.  Try putting your input in a text file, and use something like this:

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("test.txt",1)

Do Until objTextFile.AtEndOfStream
strComputer = strComputer & chr(13) & objTextFile.Readline
Loop

Wscript.Echo "File's whole contents: " & strComputer

'Split the contents
dim a
a=Split(strComputer, ";" & chr(13))
Wscript.Echo "First line: " & a(0)
Wscript.Echo "Second line: " & a(1)
0
 
LVL 18

Expert Comment

by:Crash2100
ID: 20377747
Take a look at this website, it documents a lot of this stuff:

http://www.w3schools.com/vbscript/

VBScript Functions
http://www.w3schools.com/vbscript/vbscript_ref_functions.asp
0
 
LVL 1

Author Comment

by:Steynsk
ID: 20380869
No sorry no result. So maybe I have to accept it is not possible. So I move to plan B:

I encountered a problem like this before with making a selection box with a .VBS script. And made little step to HTML to get things done. I've found the script and rebuild it a little. But the only thing I can't figure out is how to catch the input and separate it and store the thunks in to an array. So maybe you guy can help me out. This is the Idea:

sNames = TextBox("Please provide usernames seperated by a ';' ")
Function TextBox(sTitle)
  Dim oIE, s, item
  set oIE = CreateObject("InternetExplorer.Application")
  With oIE
    .FullScreen = True
    .ToolBar   = False : .RegisterAsDropTarget = False
    .StatusBar = False : .Navigate("about:blank")
    Do Until .ReadyState = 4 : WScript.Sleep 100 : Loop
    .width= 400 : .height=200
    With .document
      with .parentWindow.screen
        oIE.left = (.availWidth  - oIE.width ) \ 2
        oIE.top  = (.availheight - oIE.height) \ 2
      End With
      s = "<html><head><title>" & sTitle _
        & "</title></head><script language=vbs>bWait=true<" & "/script>" _
        & "<body bgColor=Silver><center>" _
            & "<b>" & sTitle & "<b><p>" _
        & "<textarea id=entries cols=40 rows=4></textarea><<p>" _
        & "<button id=but0 onclick='bWait=false'>OK</button>" _
        & "</center></body></html>"
      .open
      .Write(s)
      .close
      Do until .ReadyState ="complete" : Wscript.Sleep 50 : Loop
      With .body
        .scroll="no"
        .style.borderStyle = "outset"
        .style.borderWidth = "3px"
      End With
      .all.entries.focus
      oIE.Visible = True
      CreateObject("Wscript.Shell").AppActivate sTitle
      On Error Resume Next
      Do While .ParentWindow.bWait
        WScript.Sleep 100
        if oIE.Visible Then SelectBox = "Aborted"
        if Err.Number <> 0 Then Exit Function
      Loop
      On Error Goto 0
      With .ParentWindow.entries
        SelectBox = .options(.selectedIndex).text
      End With
    End With
    .Visible = False
  End With
End Function

The line:

SelectBox = .options(.selectedIndex).text

Should be replaced for something else

Thanks,

Steynsk

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 20538524
Hi there, sorry to jump in so late, but if what you want to do is prompt a user to enter usernames separated by a semi-colon, can the user put that all on one line, like with this code:

strInput = InputBox("Please provide usernames seperated by a ';')
arrArray = Split(strInput, ";")
For Each strUsername In arrArray
   MsgBox strUsername
Next

Regards,

Rob.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 20538536
Ooops, forgot a closing quote before the first closing bracket....should be:

strInput = InputBox("Please provide usernames seperated by a ';'")
arrArray = Split(strInput, ";")
For Each strUsername In arrArray
   MsgBox strUsername
Next

Regards,

Rob.
0
 
LVL 1

Author Comment

by:Steynsk
ID: 20539983
Hi Rob,

Thanks for the input but I realy need a "multiline" input box. I use the script in the way you discribe it. But I realy need multiline functionality.

Thanks anyway,

Steynsk
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 20539999
Can I ask then, if you want a user to put each username on a separate line, do you really need to separate it by a semi-colon?  Couldn't you just Split by the vbCrLf character?

Rob.
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 20540024
Try replacing
SelectBox = .options(.selectedIndex).text

with
MsgBox oIE.document.all.Entries.Value

and that should show you the value, so then use
arrNames = Split(oIE.document.all.Entries.Value, ";")

Regards,

Rob.
0
 
LVL 1

Author Closing Comment

by:Steynsk
ID: 31411706
Hello Rob,

Thats it. It works perfectly
Thanks a lot,

Steynsk
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 20545781
No problem Steynsk, glad to help.

Rob.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question