Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

VB script help?

Original Message
Name: alias_neo
Date: November 21, 2007 at 10:54:34 Pacific
Subject: VB script help?
OS: Windows Vista x64 Ultimat
CPU/Ram: AMD Athlon X2 4600+, 2x C
Model/Manufacturer: Built by Moi.
Comment:
Hi there, I'm trying to do something here and having a bit of a dilemma, I am trying to take 2 input boxes from a user, the first with a string, the second with a string.

The output should be the first string reversed with the characters in the second string excluded.

I have a nester Do while loop but my conditional is causing problems.

The conditional is like this:

i = string1.length
j = string2.length

Do while i >= 0

Do while j >= 0
if string1.char = string2.char then
add char to ecluded list
Exit Do
else
output = output & string1.char
endif
j = j-1
Loop
i = i-1
Loop

The problem here is that if the char isnt in the ecluded list, it will go through and keep outputting the char until it reaches the number of chars in the eclusion list, if string 2 is 5 long, and the char isnt hte same, i will get the char output 5 times by the loop, then for hte next char and so on.

Any one got an idea of how i can fix this? Thanks.

AMD X2 4600+ AM2 ACFrzr64
M2N32-Sli Dlx
2x 1GB Corsair XMS2 DDR2 800
NvGeforce7600GT
Enrmx. Lib. 500W
2x 250GB SATA2 7200 RAID 0
1x 200GB SATA2 7200
Logitech G7 Carbon SE


Report Offensive Message For Removal


Response Number 1
Name: Razor2.3
Date: November 21, 2007 at 17:26:17 Pacific
Subject: VB script help?
Reply: (edit)
That's not VBScript. VB.NET, maybe, but not VBScript.

The easiest way to do your comparison is from a function. The following code is untested, as I'm not near a version of VS, but it should give you an idea.

Function IsExcluded(ByVal c As Char, ByVal filter As String) As Boolean
Return = InStr(filter, c) = 0
End Function

Then, in your main function/sub, just say If Not IsExcluded(<whatever>) Then <add to output>


Report Offensive Follow Up For Removal

Response Number 2
Name: alias_neo
Date: November 21, 2007 at 17:52:17 Pacific
Subject: VB script help?
Reply: (edit)
My apologies, it's actually ASP.net using the scripting language of VB. (The page is an .aspx I'm not to good with the terminology since all this .net stuff.

Please ignore the way I wrote it, the way i wrote it is unrelated to the actual code, i just wanted to make it understandable without typing the whole code, call it pseudo-code if you like.

AMD X2 4600+ AM2 ACFrzr64
M2N32-Sli Dlx
2x 1GB Corsair XMS2 DDR2 800
NvGeforce7600GT
Enrmx. Lib. 500W
2x 250GB SATA2 7200 RAID 0
1x 200GB SATA2 7200
Logitech G7 Carbon SE


Report Offensive Follow Up For Removal

Response Number 3
Name: Razor2.3
Date: November 21, 2007 at 19:40:29 Pacific
Subject: VB script help?
Reply: (edit)
If it's pseudo code, say so!

I'd do something like this:

Function newStr(ByVal s1, ByVal s2)
For l = 1 To Len(s1)
If InStr(s2, Mid(s1, l, 1)) = 0 Then _
newStr = Mid(s1, l, 1) & newStr
Next
End Function

Just make sure you're using runat=server on the script tag. Otherwise, it'll only work with IE.

EDIT: I'm an idiot. I saw ASP and not the .NET part. Ignore this code. Still, it might just work with a little modification. Who knows?


Report Offensive Follow Up For Removal

Response Number 4
Name: alias_neo
Date: November 21, 2007 at 19:42:59 Pacific
Subject: VB script help?
Reply: (edit)
Ok, I have my string in a CharArray, how would I go about implementing that?

The variables set up are as follows:

Dim excText As String = excBox.Text
Dim nCharNum = txtBox.Text.Length
Dim xCharNum = excBox.Text.Length
Dim chArray() As Char = strText.ToCharArray()
Dim cxArray() As Char = excText.ToCharArray()
Dim i As Integer = nCharNum-1
Dim j As Integer = xCharNum-1

AMD X2 4600+ AM2 ACFrzr64
M2N32-Sli Dlx
2x 1GB Corsair XMS2 DDR2 800
NvGeforce7600GT
Enrmx. Lib. 500W
2x 250GB SATA2 7200 RAID 0
1x 200GB SATA2 7200
Logitech G7 Carbon SE


Report Offensive Follow Up For Removal

Response Number 5
Name: Razor2.3
Date: November 21, 2007 at 20:35:44 Pacific
Subject: VB script help?
Reply: (edit)
You want to use Char arrays? It's simple enough; just use a nested For loop. You'll probably need to add a Boolean to know the results of the inner For, though.

Report Offensive Follow Up For Removal


Response Number 6
Name: alias_neo
Date: November 23, 2007 at 11:39:39 Pacific
Subject: VB script help?
Reply: (edit)
I think that's where i went wrong, when i found the char in the exclusion list i tried to exit the loop and reset the loop counter for the internal loop, but it wouldn't work, i ket getting the non exlucded characters several times, can you explain to me exactly why the outer loop needs to know the status of the inner?

My brain is switched off atm, gonna g ive the project a break until i get some rest of my own.

AMD X2 4600+ AM2 ACFrzr64
M2N32-Sli Dlx
2x 1GB Corsair XMS2 DDR2 800
NvGeforce7600GT
Enrmx. Lib. 500W
2x 250GB SATA2 7200 RAID 0
1x 200GB SATA2 7200
Logitech G7 Carbon SE


Report Offensive Follow Up For Removal

Response Number 7
Name: Razor2.3
Date: November 23, 2007 at 12:43:41 Pacific
Subject: VB script help?
Reply: (edit)
Fine. Untested:

Dim addChr As Bool
For i as Integer = 0 To UBound(chArray)
addChr = True
For j as Integer = 0 To UBound(cxArray)
If chArray(i) = cxArray(j) Then
addChr = False
Exit For
End If
Next
If addChr Then newStr = chArray(i) + newStr
Next


Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: VB script help?

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




acer 312T BIOS problem

K7 Turbo possible max fsb?

Pc anywher problem

WinFLP & OE/Outlook2003

Computer resets after a few minutes


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC