d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Could Use Some Vb Help
123Next
Add Reply New Topic New Poll
Member
Posts: 21,222
Joined: Sep 10 2009
Gold: 0.00
May 7 2015 04:59pm
could use some guidance on these 2 problems i got left.

ones creating a word palindrome checker
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
May 7 2015 05:14pm
i recommend posting your problem and your current code attempt. also include any compile/runtime errors.
Member
Posts: 21,222
Joined: Sep 10 2009
Gold: 0.00
May 7 2015 05:21pm
i guess i get the idea of it, i want to create a loop that pulls each word out(backwords) and then compares to the original sentence

whatevs, i can prob do it myself

This post was edited by soullogik on May 7 2015 05:33pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
May 7 2015 05:32pm
and whats the other problem?
Member
Posts: 21,222
Joined: Sep 10 2009
Gold: 0.00
May 7 2015 05:46pm
i guess my issue is now that i have the array with all the words split up. how do i call them in order backwards before i join them and check them?

really only part i don't know how to code.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
May 7 2015 05:47pm
whats the last element? length - 1
what's the first element? 0

so loop from there

This post was edited by carteblanche on May 7 2015 05:48pm
Member
Posts: 21,222
Joined: Sep 10 2009
Gold: 0.00
May 7 2015 06:10pm
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim sentence As String
' You can cage a swallow, can't you, but you can't swallow a cage, can you
sentence = TextBox1.Text
If ispalindrome(sentence) Then
TextBox2.Text = "This sentence is a word palindrome."
Else
TextBox2.Text = "This sentence is not a word palindrome."
End If
End Sub
Function ispalindrome(sentence As String) As Boolean
Dim words() As String
Dim revsentence As String
Dim oldsentence As String
words = sentence.Replace(",", "").Split(" "c)
For i As Integer = 0 To (words.Count - 1)
If
End If
If revsentence = oldsentence Then
Return True
Else
Return False
End If
End Function


this is kind of where im at atm. i know i want to have a loop pull the words out maybe like (words.count -1) to 0 and then join but unsure of what the code would look like :o
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
May 7 2015 06:11pm
Literally start at the end and loop backwards lol.

Code
for i as integer = myarray.length to 0 step -1
print myarray(i)
next i


Or you can move forwards in the loop while going backwards

Code
index = myarray.length
for i as integer = 0 to myarray.length
print myarray(index - i)
next i


The later code snippet will simply minus the current loop index from the total size to access that element.

This post was edited by AbDuCt on May 7 2015 06:14pm
Member
Posts: 21,222
Joined: Sep 10 2009
Gold: 0.00
May 7 2015 06:41pm
Quote (AbDuCt @ May 7 2015 08:11pm)
Literally start at the end and loop backwards lol.

Code
for i as integer = myarray.length to 0 step -1
print myarray(i)
next i


Or you can move forwards in the loop while going backwards

Code
index = myarray.length
for i as integer = 0 to myarray.length
print myarray(index - i)
next i


The later code snippet will simply minus the current loop index from the total size to access that element.


how do i compare that to the original sentence using print? thank you tho, that helped me see what i was missing tho
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
May 7 2015 07:02pm
Quote (soullogik @ May 7 2015 08:41pm)
how do i compare that to the original sentence using print? thank you tho, that helped me see what i was missing tho


I don't know VB.

I don't even know if there is a print function.

Was just showing you how to loop backwards.
Go Back To Programming & Development Topic List
123Next
Add Reply New Topic New Poll