The LB program asks for the user to input a word, and the program will print
to the screen the word in reverse and if the word is spelled the same in
reverse and it is forward, then it will reply back saying that the word is a
palindrome.
I have built a simple form with a label, text box for the word input, and a
label and text box for the reverse spelling of the input word, another label
and text box for the reply as to it being a palindrome as well as an OK
button to fire it all off. Inside the OK button I have inserted my Liberty
BASIC code. Now my problem is how to go about making the mods to the code to
fit VB's needs, but not loose the logic as it's sound.
Many thanks for any and all help, Basil
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
input "Enter a word: "; s$
For i = Len(s$) To 1 Step -1
s1$ = s1$ + Mid$(s$, i, 1)
Next i
print "Reversed is: "; s1$
If s$ = s1$ Then
Print("The word " + s$ + " is a palindrome")
Else
End If
End Sub
End Class
The following assumes that the name of the text box control that will
contain your input is InputLine and output is ReversedTextBox and PalMsg is
a label control that will contain the outcome of the test. Of course you'll
have to change those names to match your control names.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim s As String, i As Integer, s1 As String ' All variables must be
defined first
PalMsg.Visible = False
s1 = ""
s = InputLine.Text
For i = Len(s) To 1 Step -1
s1 = s1 & Mid(s, i, 1)
Next i
ReversedTextBox.Text = s1
If UCase(s) = UCase(s1) Then
PalMsg.Text = "The above IS a palindrome"
Else
PalMsg.Text = "The above is NOT a palindrome"
End If
PalMsg.Visible = True
End Sub
Tom Lake
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim s As String, i As Integer, s1 As String, PalMsg As String ' All
variables must be defined(first)
PalMsg.Visible = False
s1 = ""
s = InputLine.Text
For i = Len(s) To 1 Step -1
s1 = s1 & Mid(s, i, 1)
Next i
ReversedTextBox.Text = s1
If UCase(s) = UCase(s1) Then
PalMsg.Text = "The above IS a palindrome"
Else
PalMsg.Text = "The above is NOT a palindrome"
End If
PalMsg.Visible = True
End Sub
"Tom Lake" <tl...@twcny.rr.com> wrote in message
news:ZW9%d.102866$H05....@twister.nyroc.rr.com...
Don't know if VB.NET has it (VB6 did), but check to see if you have a
StrReverse function available... it will allow you to eliminate the
loop.
Rick - MVP
For the microsoft news server, try these newsgroups for Visual Basic
.NET related questions...
microsoft.public.dotnet.languages.vb
microsoft.public.dotnet.languages.vb.upgrade
microsoft.public.dotnet.languages.vb.controls
microsoft.public.dotnet.languages.vb.data
And these for more general .NET questions
microsoft.public.dotnet.general
microsoft.public.vsnet.general
Note: There are many other .NET newgroups (use the first three "fields"
from the last two as templates when searching for them), but the above
ones should get you started.
Rick - MVP
"Basil Fawlty" <Basil_Fa...@NOSPAMyahoo.com> wrote in message
news:JoSdnWhAs_c...@comcast.com...
InputLine should be the name of the text box control where you type your
input.
ReversedTextBox is the name of the text box control where the reversed text
appears.
PalMsg is the name of a text control (not a text box) that holds the answer
to whether
or not the input is a palindrome.
>> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
>> System.EventArgs) Handles Button1.Click
>> Dim s As String, i As Integer, s1 As String, PalMsg As String
> ' All
>> variables must be defined(first)
>> PalMsg.Visible = False
>> s1 = ""
>> s = InputLine.Text
>> For i = Len(s) To 1 Step -1
>> s1 = s1 & Mid(s, i, 1)
>> Next i
>> ReversedTextBox.Text = s1
>> If UCase(s) = UCase(s1) Then
>> PalMsg.Text = "The above IS a palindrome"
>> Else
>> PalMsg.Text = "The above is NOT a palindrome"
>> End If
>> PalMsg.Visible = True
>> End Sub
Tom Lake
I'm just not quite getting it... I have inserted the code from the
beginning, re-added the PalMsg as String to dim that value. And then I made
sure the properties of each text box has the right (name) to match the .vb
coded values... and I still get compile errors. Based onthe code below, 2
errors;Value of type 'System.Windows.Forms.TextBox' cannot be converted to
'String' & Value of type 'String' cannot be converted to
'System.Windows.Forms.TextBox' ...this would be the s = InputLine and the
ReversedTextBox = s1 lines in the code. I seem to have a problem with the
compiler if I leave the .TextBox items there, and removing them reduced the
number of compiler errors.
I think I'm getting close though. --Basil
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim s As String, i As Integer, s1 As String, PalMsg As String
PalMsg = False
s1 = ""
s = InputLine
For i = Len(s) To 1 Step -1
s1 = s1 & Mid(s, i, 1)
Next i
ReversedTextBox = s1
If UCase(s) = UCase(s1) Then
PalMsg = "The above IS a palindrome"
Else
PalMsg = "The above is NOT a palindrome"
End If
PalMsg = True
End Sub