Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Convert BASIC to VB

130 views
Skip to first unread message

Basil Fawlty

unread,
Mar 19, 2005, 7:41:06 PM3/19/05
to
Hi everyone, I could use some help in converting a simple Liberty BASIC
program to a VB.NET 2003 SE program. I know this is VB, I'm sure this is so
simple for you guys that the .NET difference is inconsequential.

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


Tom Lake

unread,
Mar 20, 2005, 2:50:17 AM3/20/05
to
> Many thanks for any and all help, Basil
>

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


Basil Fawlty

unread,
Mar 20, 2005, 1:31:28 PM3/20/05
to
Tom, I tried this, and I'm sure there are a lot of things that your assuming
I know to do... but not all variables were declared, so I added another,
PalMsg, and then during compile it thinks more are undeclared, like
inputline, reveredtextbox, etc... is this because I have not set the
properties in the form to line up with the variable names in the code? Or
is it for some other reason? Below is the code not much different from your
post. Do I need to post more of something else? On a side, what are the
most common areas in this exercise that I need to concentrate on, the VB
code window of the Form Designer gen code (with the idea that the form has
all the elements needed), and the properties to the text boxes? Where else?
Thanks for your help and feedback. --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 ' 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...

Rick Rothstein

unread,
Mar 20, 2005, 2:02:26 PM3/20/05
to

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

Rick Rothstein

unread,
Mar 20, 2005, 2:03:21 PM3/20/05
to
Almost everybody in this newsgroup is using VB6 or lower. While you may
get a stray answer to VB.NET (including VB2003 and VB2005 which has
dropped .NET from its name) questions here, you should ask them in
newsgroups devoted exclusively to .NET programming. Look for newsgroups
with either the word "dotnet" or "vsnet" in their name.

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...

Tom Lake

unread,
Mar 20, 2005, 2:31:16 PM3/20/05
to
>> PalMsg, and then during compile it thinks more are undeclared, like
>> inputline, reveredtextbox, etc... is this because I have not set the
>> properties in the form to line up with the variable names in the code?

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


Basil Fawlty

unread,
Mar 23, 2005, 7:44:31 AM3/23/05
to
"Tom Lake" <tl...@twcny.rr.com> wrote in message
news:8ck%d.106028$H05....@twister.nyroc.rr.com...

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


0 new messages