Log in

View Full Version : Visual Basic help


Jess
January 27th, 2013, 03:09 PM
I have this code
Public Class splitterForm

Dim txtName As Object
Dim output As Object

Private Sub splitSentence(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAnalyze.Click
Dim fullName, firstName, lastName As String
Dim m, n As Integer
fullName = txtName.Text
n = fullName.IndexOf(" ")
firstName = fullName.Substring(0, n)
lastName = fullName.Substring(n + 1)
m = lastName.Length
output.AppendText("First Name: " & firstName & vbCrLf)
output.AppendText("Your last name has " & m & " letters." & vbCrLf))
Dim fullName As String = StrReverse(fullName)
output.AppendText("This is your full name reversed: " & fullName & vbCrLf))
End Sub
End Class

I'm trying to follow an example in the textbook, to create a popup with a textbox where I put in my name and it generates some results, but every time I run it, I don't get what I should. It says there were some build errors. I don't understand AT ALL what I'm missing. I'm using Visual Basic 2010 at the moment, have it open...am I supposed to do something with the design?

I added in

Dim txtName As Object
Dim output As Object


because it says they weren't declared. It doesn't say this in the book, so I'm a bit confused

ethanf93
January 27th, 2013, 04:18 PM
I added in

Dim txtName As Object
Dim output As Object


Looking at the code, it looks like it assumes those two variables refer to parts on a form- you should delete them from where you added them and go to the "design view" for your form, and add a text field (on the properties set the Name to txtName) and a label (I think?) which you should set the Name to output.

If you already have the text field and the label (or whatever it is) then all you need to do is select them and use the Properties view to rename them.

On a side note you'd generally want to copy paste the build errors themselves (they're there to help understand what went wrong) but unfortunately they're not always helpful (as you've probably discovered here.)