I don't know what's wrong with my code. What do these errors mean?
http://i179.photobucket.com/albums/w...x/VBErrors.jpg
Printable View
I don't know what's wrong with my code. What do these errors mean?
http://i179.photobucket.com/albums/w...x/VBErrors.jpg
1. You have two methods with the same name and the same number and type of parameters.
2. GetUpperBound is a member of an array, not of a String. A String has a Length property, which is 1 greater than the index of the last character.
3. You can get a Char by index from a String but you cannot set a Char by index.
4. See 2.
5. You can't ReDim a String, only arrays.
6. See 3.
It seems that you are trying to treat a String object like an array of Chars. They are not the same thing. If you want an array of Chars then create an array of Chars, which you can do by calling ToCharArray on your String. Once you're done editing, you can create a New String from the Char array by passing the array to the constructor.
Having said that, that may or may not be the best way to achieve your aim. If you provide a full and clear explanation of what you're trying to achieve then we can possibly provide better advice.
It looks like that class assignment for Hangman that we've seen on these boards at least twice before.
I hate that assignment. VB is an object oriented language: teach them about objects and how to model their domain. Don't teach them how to write spaghetti code in a form's code behind!!!!! Graaaaaaah!!!!!!!! :mad: :mad: :mad:
While I agree in principle, teaching someone how to model their domain when they can't even work with Strings is just not going to happen. Learning proper design must come later, but I do think it gets left too late in many, if not most, instances. It doesn't get addressed at all in far too many cases, often because the teachers don't know how to do it themselves.
Well, I was referring to the assignment itself rather than xdcx's issues. It guides (forces) students into coding a mass of logic into a code-behind form.
And I'd still be happy to have students learning about classes and then working out these issues inside the class. Then again, I am not a teacher :)
I looked at both of the ones you've seen before and neither of them helped with my problem. the problem that i"m having is in a different location of the coding. i"m dealing with the btnguessL_click not the btnguessW_click
what I want to know is how to redimension the array to do what it wants me to do? how do i make strLettersGuessed a member of string? why does it tell me that "Property 'Chars' is 'Read Only' " ?
You don't make 'strLettersGuessed' a member of String. 'strLettersGuessed' IS a String. If you want an array then you need to create an array, not a String. I think you might need to do some reading about arrays.
http://www.startvbdotnet.com/language/arrays.aspx
http://www.homeandlearn.co.uk/net/vbnet.html#Arrays
It tells you that property Chars is ReadOnly for the exact reason that I already told you in my first post. You can get a Char from a String by index, e.g.The 'ch' variable now contains the value "W"c, i.e. an upper case W. This part:vb.net Code:
Dim str As String = "Hello World" Dim ch As Char = str(6)is actually shorthand for this:Code:str(6)
You get a Char value from a String by index using the Chars property. Because it is the default property for the String class, you can omit the property name and just index the String itself directly. What you cannot do is this:Code:str.Chars(6)
That is trying to use the Chars property to set a character in the String. That's not allowed. The Chars property is ReadOnly, i.e. you can get a value but you can't set a value. Again, you are using a String, not an array. If you want an array then you need to create an array.vb.net Code:
Dim ch As Char = "W"c Dim str As String = "the quick brown fox" str(6) = ch