Front Office Football Central  

Go Back   Front Office Football Central > Archives > FOFC Archive
Register FAQ Members List Calendar Mark Forums Read Statistics

Reply
 
Thread Tools
Old 03-05-2005, 08:54 PM   #1
Airhog
Captain Obvious
 
Join Date: Aug 2001
Location: Norman, Oklahoma
VB6 question

I have 2 Simple Questions



Code:
If (TxtDiceSides.Text < 2) Or (TxtDiceSides.Text > 100) Or (TxtDiceNumber.Text < 1) Or _ (TxtDiceNumber.Text > 6) Or (TxtDiceSides.Text = "") Or (TxtDiceNumber.Text = "") Then Error2 = MsgBox("Please input a number from 2-100", vbOKOnly, "error") End If

Question 1. If I have a blank value in txtdicenumber.text or a letter then I get a type mismatch error. How can I alter this statment so it doesnt give me that error?

Question 2. The program is supposed to generate a random number for a certain number of dices with a certain number of sides on each dice. Right now I have a subroutine for each Dice from 1-6. And I just call each one as they are needed. I know there is probably a better way to roll the dice for each text box, then move to the next text box. Can you give me a nudge in the right direction here? Im not sure how or If I can use a loop here to increment the text box to place the number in.
__________________

Thread Killer extraordinaire


Yay! its football season once again!

Airhog is offline   Reply With Quote
Old 03-05-2005, 09:19 PM   #2
Wolfpack
Pro Rookie
 
Join Date: Feb 2003
Location: Raleigh, NC
I've done a diceroller myself in VB, though I didn't make it robust enough to handle letters being inputted. At any rate, to address that, here's a link I found in a Google search with some suggestions:

http://www.vbcity.com/forums/topic.asp?tid=3785

As to the second point about controlling all the separate textboxes, I'd actually advise not doing so. It's easier to have one textbox output and just daisy-chain all the rolls into it, unless you have something specific in mind for each die. A for loop like the following would work:
Code:
For I = 1 To varNumberOfDice varDiceRolled = Int((Rnd * varNumberOfSides) + varLowestValue) If I = 1 Then strDiceRolled = varDiceRolled Else strDiceRolled = strDiceRolled & ", " & varDiceRolled End If Next lblDiceRolled.Caption = strDiceRolled

I used variants (for something simple like this, no harm in it) to handle the aspects of the rolling and then a label made to look like a textbox to display the output. I also have an additional feature to total up the dice rolled, but you didn't mention anything for that, so I left it out for brevity. The other advantage to "stringing" the numbers out in a label is that you can roll a very large number of dice, though it does make it difficult to pick out the one you are looking for. You could change the logic of the output so that it puts one die on each line, so there's that.

One thing I'd like to do is add features to roll different combinations of dice, but it would probably mean a redesign to handle something like that.
Wolfpack is offline   Reply With Quote
Old 03-05-2005, 09:29 PM   #3
Buccaneer
Head Coach
 
Join Date: Oct 2000
Location: Colorado
In regards to #1, probably something along the lines of checking for Null value like varchar() = vbNull - but that's more of a database check.
Buccaneer is offline   Reply With Quote
Old 03-05-2005, 10:28 PM   #4
Airhog
Captain Obvious
 
Join Date: Aug 2001
Location: Norman, Oklahoma
Wolfpack: I want it to show each dice, since I modeled after dice used for D&D. But I plan to play around with it some more.

Buccaneer: I checked around and read that null value is equal to zero in VB. That is different from an Empty string. I will look at some more null value examples and try to piece together what I am doing wrong.
__________________

Thread Killer extraordinaire


Yay! its football season once again!
Airhog is offline   Reply With Quote
Old 03-05-2005, 11:16 PM   #5
GoldenEagle
Grizzled Veteran
 
Join Date: Dec 2002
Location: Little Rock, AR
If Text = "" Then msgBox Error

This code screams for a case statement.
__________________
Xbox 360 Gamer Tag: GoldenEagle014
GoldenEagle is offline   Reply With Quote
Old 03-06-2005, 02:17 AM   #6
21C
College Prospect
 
Join Date: Jul 2001
Location: Newcastle, Australia
You can also adjust it to read:

If Val(TxtDiceSides.Text) < 2 etc.

You are comparing the contents of a string/text (TxtDiceSides.Text) to an integer (2). The Val will convert the string to a number.

Val(2) = 2
Val(147) = 147
but
Val(" ") = 0
Val("F") = 0
21C is offline   Reply With Quote
Old 03-06-2005, 07:46 AM   #7
Shaun Sullivan
PureSim
 
Join Date: Nov 2002
Location: Mount Pleasant, SC
dim lSides as long
lSides = val(TxtDiceSides.Text)

dim lDice as long
lDice = val(TxtDiceNumber.Text)

if (lSides < 2) or (lSides > 100) or (lDice < 1) or (lDice > 6) then
' Do your "invalid" processing here...
end if
Shaun Sullivan is offline   Reply With Quote
Old 03-06-2005, 08:16 AM   #8
Airhog
Captain Obvious
 
Join Date: Aug 2001
Location: Norman, Oklahoma
Shaun Sullivan: that makes sense I think. Ill try that out. Thanks
__________________

Thread Killer extraordinaire


Yay! its football season once again!
Airhog is offline   Reply With Quote
Old 03-06-2005, 08:41 AM   #9
Greyroofoo
Pro Starter
 
Join Date: Nov 2003
Location: Alabama
numerical variables are automatically initialized to 0 in vb and strings are created blank. My only question is why there are so many "Or"s

how much could I get VB6 for anyways?

Last edited by Greyroofoo : 03-06-2005 at 08:42 AM. Reason: added question
Greyroofoo is offline   Reply With Quote
Old 03-06-2005, 09:11 AM   #10
Airhog
Captain Obvious
 
Join Date: Aug 2001
Location: Norman, Oklahoma
Shaun: Worked like a charm. I see now how that relationship works, and I think I was just trying to get too much use from the TXTnumber.text string.

GE: You think? I think its easier to just define all of the variable in the beginning. Especially since each result gives the same error message.
__________________

Thread Killer extraordinaire


Yay! its football season once again!
Airhog is offline   Reply With Quote
Old 03-06-2005, 12:57 PM   #11
sterlingice
Hall Of Famer
 
Join Date: Apr 2002
Location: Back in Houston!
Quote:
Originally Posted by Greyroofoo
numerical variables are automatically initialized to 0 in vb and strings are created blank. My only question is why there are so many "Or"s

how much could I get VB6 for anyways?

A while back, Microsoft was giving away free copies of VB.Net but I went to the page and saw this: "Due to overwhelming demand, supplies of the complimentary Not For Resale copies of Visual Basic .NET 2003 Standard Edition* are now exhausted. Tens of thousands were claimed by developers. If you wish to explore Visual Basic .NET on a trial basis, visit the Visual Studio .NET 2003 Hosted Experience."

Many of which I saw on ebay despite their not-for-resale tag (so beware if you buy a copy there).

If you have to have vb.6, then I don't know what to say. But I bought my copy of vb.net Student Edition for $100 which seemed pretty reasonable to me.

SI
__________________
Houston Hippopotami, III.3: 20th Anniversary Thread - All former HT players are encouraged to check it out!

Janos: "Only America could produce an imbecile of your caliber!"
Freakazoid: "That's because we make lots of things better than other people!"


sterlingice is offline   Reply With Quote
Old 03-09-2005, 08:49 PM   #12
Mr. Wednesday
Pro Starter
 
Join Date: Jul 2003
Location: South Bend, IN
Quote:
Originally Posted by Airhog
Buccaneer: I checked around and read that null value is equal to zero in VB. That is different from an Empty string. I will look at some more null value examples and try to piece together what I am doing wrong.
That is not correct. A null value is a null value -- it is distinct from anything else, actually a separate variable type enumeration for a variant. It's definitely not equal to zero. It's something that may actually be set explicitly using the Null keyword (unlike a couple of other variant types, missing and empty, that may only be set using hackery).
__________________
Hattrick - Brays Bayou FC (70854) / USA III.4
Hockey Arena - Houston Aeros / USA II.1

Thanks to my FOFC Hattrick supporters - Blackout, Brillig, kingfc22, RPI-fan, Rich1033, antbacker, One_to7, ur_land, KevinNU7, and TonyR (PM me if you support me and I've missed you)
Mr. Wednesday is offline   Reply With Quote
Old 03-09-2005, 08:52 PM   #13
Mr. Wednesday
Pro Starter
 
Join Date: Jul 2003
Location: South Bend, IN
Quote:
Originally Posted by Airhog
Question 1. If I have a blank value in txtdicenumber.text or a letter then I get a type mismatch error. How can I alter this statment so it doesnt give me that error?
Check for an empty string or other non-numeric input prior to checking against a numeric value. Your problem was that you would trip an error on one of the range checks prior to the check that would actually pick up an empty string (never mind never checking for non-numeric input).

Note that it's not enough to move the check for an empty string to the head of the comparison list, unlike with C or C++, because VB doesn't do short-circuit logical operators.
__________________
Hattrick - Brays Bayou FC (70854) / USA III.4
Hockey Arena - Houston Aeros / USA II.1

Thanks to my FOFC Hattrick supporters - Blackout, Brillig, kingfc22, RPI-fan, Rich1033, antbacker, One_to7, ur_land, KevinNU7, and TonyR (PM me if you support me and I've missed you)
Mr. Wednesday is offline   Reply With Quote
Old 03-09-2005, 08:59 PM   #14
Airhog
Captain Obvious
 
Join Date: Aug 2001
Location: Norman, Oklahoma
Quote:
Originally Posted by Mr. Wednesday
That is not correct. A null value is a null value -- it is distinct from anything else, actually a separate variable type enumeration for a variant. It's definitely not equal to zero. It's something that may actually be set explicitly using the Null keyword (unlike a couple of other variant types, missing and empty, that may only be set using hackery).

I could have swore that I read that somewhere. Thanks for the Clarification
__________________

Thread Killer extraordinaire


Yay! its football season once again!
Airhog is offline   Reply With Quote
Old 03-10-2005, 12:15 AM   #15
Mr. Wednesday
Pro Starter
 
Join Date: Jul 2003
Location: South Bend, IN
Quote:
Originally Posted by 21c
You can also adjust it to read:

If Val(TxtDiceSides.Text) < 2 etc.

You are comparing the contents of a string/text (TxtDiceSides.Text) to an integer (2). The Val will convert the string to a number.

Val(2) = 2
Val(147) = 147
but
Val(" ") = 0
Val("F") = 0
Be careful with Val, it is not locale-aware (less of a problem with integer values than floating point values). Alternatively, consider using Clng with some error handling to do something sensible for the cases that give a type mismatch.
__________________
Hattrick - Brays Bayou FC (70854) / USA III.4
Hockey Arena - Houston Aeros / USA II.1

Thanks to my FOFC Hattrick supporters - Blackout, Brillig, kingfc22, RPI-fan, Rich1033, antbacker, One_to7, ur_land, KevinNU7, and TonyR (PM me if you support me and I've missed you)
Mr. Wednesday is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is On
Forum Jump


All times are GMT -5. The time now is 07:31 PM.



Powered by vBulletin Version 3.6.0
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.