Need Help

Heldelance

New member
Joined
Mar 1, 2006
Messages
2
Programming Experience
Beginner
Hi people. I'm new to VB.NET, I've only started learning it recently.

I need help with a couple of things in VB.NET, I haven't been able to figure them out thus far.

Anyway, my first problem.

I'm trying to make it so that when you enter a name in the Name field, you cannot enter numbers.

Next problem is...

I'm trying to make a character creation thing for my class project. I can't figure out how to make it so that if you put a stat up, like Strength, the remaining points goes down.

If anyone has any suggestions to those, please help me out.
 
i'm only going to give you the answer to the numerical input problem...
in the textbox's KeyPress event put:
VB.NET:
    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        e.Handled = IsNumeric(e.KeyChar)
    End Sub

but for the 2nd problem you'll need to actually do this yourself as we dont do homework for people
first off I would make a class that has the number items (Strength, Armor, Life, etc...) and have these as integer properties (be sure to make these properties Friend or Public when declaring them)
then i would make a method (sub) for each property one of which will be Increased, so obviously you'd have StrengthIncrease
now in each of these you'll want to be able to pass a value of how much the strength will be increased in which you'll have the math use this number to determin how much the strength is increased by and you would also have a Select Case check to determin how much of the other's are being decreased, from the method you simply set the other item's property's to the new amount

i hope this makes sense, if it sounds confusing you'll probably want to do a quick search on how classes work and from there i (anyone on the forum) can help with the logic
 
VB.NET:
e.Handled = Char.IsDigit(e.KeyChar)
would be preferable in my opinion. That doesn't stop you entering characters like &*^%$# though. You might prefer something like
VB.NET:
e.Handled = Not Char.IsLetter(e.KeyChar) AndAlso e.KeyCode <> Keys.Space AndAlso Not Char.IsControl(e.KeyChar)
which will allow letters and spaces only without rejecting control characters.
 
Thanks for the replies guys.
I was able to make my code work properly and now have a simple DnD style character creation program. :p
 
Back
Top