Solved

VBScript boolean string selection

Posted on 2007-03-17
3
485 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
Comment Utility
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
Comment Utility
You can also use

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

Expert Comment

by:sirbounty
Comment Utility
...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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

771 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now