Computing.Net > Forums > Programming > VB script help?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

VB script help?

Reply to Message Icon

Name: alias_neo
Date: November 21, 2007 at 10:54:34 Pacific
OS: Windows Vista x64 Ultimat
CPU/Ram: AMD Athlon X2 4600+, 2x C
Product: 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



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: November 21, 2007 at 17:26:17 Pacific
Reply:

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>


0

Response Number 2
Name: alias_neo
Date: November 21, 2007 at 17:52:17 Pacific
Reply:

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


0

Response Number 3
Name: Razor2.3
Date: November 21, 2007 at 19:40:29 Pacific
Reply:

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?


0

Response Number 4
Name: alias_neo
Date: November 21, 2007 at 19:42:59 Pacific
Reply:

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


0

Response Number 5
Name: Razor2.3
Date: November 21, 2007 at 20:35:44 Pacific
Reply:

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.


0

Related Posts

See More



Response Number 6
Name: alias_neo
Date: November 23, 2007 at 11:39:39 Pacific
Reply:

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


0

Response Number 7
Name: Razor2.3
Date: November 23, 2007 at 12:43:41 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: VB script help?

VB Script help www.computing.net/answers/programming/vb-script-help/15929.html

vb script help www.computing.net/answers/programming/vb-script-help/18990.html

vbs password protect script help www.computing.net/answers/programming/vbs-password-protect-script-help/13511.html