Solved

VBScript boolean string selection

Posted on 2007-03-17
3
489 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
  • 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

786 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