Solved

VBScript boolean string selection

Posted on 2007-03-17
3
494 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 500 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

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.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

690 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