?
Solved

VBScript boolean string selection

Posted on 2007-03-17
3
Medium Priority
?
497 Views
Last Modified: 2010-04-09
Hi again Experts!

I'm learning VBScript and there's a construction I've used in other languages that I need to find the VBScript version of.

It's       boolean_variable("Yes", "No")       so if the variable is true it returns Yes and viceversa.

Also if I've got an integer variable how do I get text from an array of strings?  And how do I create that array?

Thanks!
Peter
0
Comment
Question by:padmasambhava
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Expert Comment

by:Louis01
ID: 18742715
if myBoolean then
  'True Part here
else
  'False Part here
end if

You can also use it as:
if not myBoolean then
 'False part here
end if


To create an array of 3 strings:

Dim myStringArray(2) as string
myStringArray(0)  = "Line 1"
myStringArray(0)  = "Line 2"
myStringArray(0)  = "Line 3"

Another way would be:
Dim myStringArray() As String
Dim i As Integer

For i = 0 To 2
    If i = 0 Then
        ReDim myStringArray(i)
    Else
        ReDim Preserve myStringArray(i)
    End If
    myStringArray(i) = "This is line " & i
Next i

What do you mean by "Also if I've got an integer variable how do I get text from an array of strings?"?

To return the strings created above:
for i = lbound(myStringArray) to ubound(myStringArray)
  msgbox myStringArray(i)
next i
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 2000 total points
ID: 18743185
You can also use

NewString=If(oldString="ABC","True results","False Results")
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18743193
...and if you know your data upfront, you can create an array using

myArray=Array("Item1","Item2","Item3")

and loop through it using

For each item in myArray
  cboItems.Add item
Next
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

800 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