Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm working on a very extensive program for a friend and myself. It's basically a character generator for our books to help us create minor characters more easily and faster. I have all of our made up creatures going to different areas of the program to generate different things from names to birth and death dates to hair and eye colors, etc. My main problem is that I want to use wild card statements.

 

What I want to do is have the statement see if my species textbox has Human, Dragon, Nymph, Elf, or other specific words in the box. The below code is the generalized code that I attempted to use to reprogram one of my buttons. A similar code would be used on several of my other buttons like my height regenerate button, death age, etc.

 

Dim a, b As Double

If TextBox12.Text Like "%Human" Then

humandeathage()

deathmonth()

deathday()

deathyear()

a = Val(TextBox41.Text) 'mature

b = Val(TextBox42.Text) 'death age

If a > b Then

humanmatureage()

ElseIf TextBox41.Text = "Died before fully mature" Then

If b > 14 Then

humanmatureage()

End If

End If

 

ElseIf TextBox12.Text Like "%Elf" Then

elfdeathage()

deathmonth()

deathday()

deathyear()

a = Val(TextBox41.Text) 'mature

b = Val(TextBox42.Text) 'death age

If a > b Then

elfmatureage()

ElseIf TextBox41.Text = "Died before fully mature" Then

If b > 140 Then

elfmatureage()

End If

End If

 

ElseIf TextBox12.Text Like "%Dragon" Then

 

ElseIf TextBox12.Text Like "%Nymph" Then

 

End If

 

burialcrematemonth()

burialcremateday()

burialcremateyear()

 

This part of the code does work to some degree, but it only sends me to the human part when I'm trying to generate an elf. Did I write the code wrong? Or is there a better statement I can use to acheive what I want? :confused: My Dad keeps telling me to use case statements, but I forgot how to use them :o . My Dad also works in VB6 and C++. I work in VB.Net. I learned VB.Net as a senior in high school, but I didn't get very far in the course before I graduated. I had taken QBasic the year before (my school was behind in the programming department :rolleyes: ) so I had to start over for the most part in VB.Net the next year. I opted to continue programming at least as a hobby. I haven't taken a programming class in a year and a half so I've kind of forgotten quite a bit. There are no classes available for VB.Net in my area, either. :mad: I would post the whole program, but it's over 15 mb already. I have pictures in the bin folder that the program calls to that's caused the large size. I suppose I can just post the bin folder without the pictures if needed.

 

My program is a big mess, really, but that was the way I learned to program. Unfortunately, I don't now many lines of code. I only learned how to call to a second form or call pictures just in this past month after coming to this site. If I did post my source code, I'd be amazed if anyone could figure it out. :eek: My program also does other little things like random numbers, dates, times, etc that I had had originally in several other programs I wrote some time ago. It's quite extensive, as I've said.

Posted
Why are you using a TextBox for the race? Why not put all the possible races in a ComboBox and do a Select Case on the SelectedIndex of it?

 

I still consider myself very much a beginner. My programming teacher was learning VB.Net along with the rest of us so my partner and I were the guinea pigs for various programs before the rest of the class did it. We never got beyond labels, textboxes, pictureboxes, and other very basic stuff. I did what I knew how to do. Although I am open to new ideas to make my programming go faster and be much simpler. I have no idea how to use a ComboBox and I forgot how to use Select Case. SelectedIndex I have no idea about. :o Unfortunately, I have to leave for 2 classes in about an hour so I can't play with the ComboBox and figure it out. I'll have to wait until later today (it's morning for me here) to play with that. That probably will make a lot of things easier, though. :) Thanks. I still want to figure out wild card statements, though. I have several different places where I want to put them, and I have yet to figure them out. They're just not working for me. :mad:

  • Administrators
Posted

wild cards as such are not directly supported by the .Net string handling routines. If you just want to check if a string ends with a particular value you can always just call the .EndsWith(...) method of the string variable.

For more complex string matching you will probably want to investigate regular expresions as a more powerful tool.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted
wild cards as such are not directly supported by the .Net string handling routines. If you just want to check if a string ends with a particular value you can always just call the .EndsWith(...) method of the string variable.

For more complex string matching you will probably want to investigate regular expresions as a more powerful tool.

 

Oo, thanks. That .EndsWith worked. Took me a few minutes to figure it, but it now works. :D That solved a lot of problems for me. If I could take a class for this and learn more, I would, but classes aren't available and books are rare. I have one book, but it had little on wild cards and I had no clue what else to look up. :confused: Anyway, thanks again. :)

Posted
but it had little on wild cards and I had no clue what else to look up
As PlausiblyDamp mentioned, regular expressions would do the trick. I would go that route if I started running into more complex needs for wild cards. If there isn't anything about them in your book, there are several good beginner's tutorials that can be easily found on the web.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...