Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 18013
Number of posts: 55386

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Convert Simple Liberty BASIC program to VB Posted by Basil_Fawlty on 19 Mar 2005 at 5:08 PM
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

Report
Re: Convert Simple Liberty BASIC program to VB Posted by BitByBit_Thor on 20 Mar 2005 at 9:18 AM
: 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
:
:

Visual Basic 6 has a function for this. I assume VB.NET has a similair function. In VB6: Reverse(String)
So basically the code would be: (VB6)
Text1.Text = "Word" 'Word input
Text2.Text = Reverse(Text1.Text)
If Text1.Text = Text2.Text Then
  MsgBox "It's a palindrome!"
End If


So VB.NET should have something alike... Something like strMyString.Reverse perhaps?

Greets...
Richard

Report
Re: Convert Simple Liberty BASIC program to VB Posted by Basil_Fawlty on 23 Mar 2005 at 5:49 AM
: : 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
: :
: :
:
: Visual Basic 6 has a function for this. I assume VB.NET has a similair function. In VB6: Reverse(String)
: So basically the code would be: (VB6)
:
: Text1.Text = "Word" 'Word input
: Text2.Text = Reverse(Text1.Text)
: If Text1.Text = Text2.Text Then
:   MsgBox "It's a palindrome!"
: End If
: 

:
: So VB.NET should have something alike... Something like strMyString.Reverse perhaps?
:
: Greets...
: Richard
:
:

I'm just not quite getting it... below is the code I'm working with. I've 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 on the 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' exist. they would be related to the lines of code: s = InputLine and the ReversedTextBox = s1. 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
Report
Re: Convert Simple Liberty BASIC program to VB Posted by infidel on 23 Mar 2005 at 7:49 AM
: I'm just not quite getting it... below is the code I'm working with. I've 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 on the 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' exist. they would be related to the lines of code: s = InputLine and the ReversedTextBox = s1. 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.

You need to use the .Text property of the textboxes, otherwise VB thinks you're trying to convert a string to a textbox and vice versa.

    Private Sub Button1_Click( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs _
    ) Handles Button1.Click

        Me.TextBox2.Text = StrReverse(Me.TextBox1.Text)

        If Me.TextBox1.Text = Me.TextBox2.Text Then
            MsgBox("Palindrome!")
        End If

    End Sub



infidel

$ select * from users where clue > 0
no rows returned





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.