![]() |
![]() |
#1 | ||
Captain Obvious
Join Date: Aug 2001
Location: Norman, Oklahoma
|
VB6 question
I have 2 Simple Questions
Code:
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! |
||
![]() |
![]() |
![]() |
#2 |
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:
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. |
![]() |
![]() |
![]() |
#3 |
Head Coach
Join Date: Oct 2000
Location: Colorado
|
In regards to #1, probably something along the lines of checking for Null value like varchar(
|
![]() |
![]() |
![]() |
#4 |
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! |
![]() |
![]() |
![]() |
#5 |
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 |
![]() |
![]() |
![]() |
#6 |
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 |
![]() |
![]() |
![]() |
#7 |
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 |
![]() |
![]() |
![]() |
#8 |
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! |
![]() |
![]() |
![]() |
#9 |
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 |
![]() |
![]() |
![]() |
#10 |
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! |
![]() |
![]() |
![]() |
#11 | |
Hall Of Famer
Join Date: Apr 2002
Location: Back in Houston!
|
Quote:
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!" |
|
![]() |
![]() |
![]() |
#12 | |
Pro Starter
Join Date: Jul 2003
Location: South Bend, IN
|
Quote:
__________________
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) |
|
![]() |
![]() |
![]() |
#13 | |
Pro Starter
Join Date: Jul 2003
Location: South Bend, IN
|
Quote:
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) |
|
![]() |
![]() |
![]() |
#14 | |
Captain Obvious
Join Date: Aug 2001
Location: Norman, Oklahoma
|
Quote:
I could have swore that I read that somewhere. Thanks for the Clarification ![]()
__________________
Thread Killer extraordinaire Yay! its football season once again! |
|
![]() |
![]() |
![]() |
#15 | |
Pro Starter
Join Date: Jul 2003
Location: South Bend, IN
|
Quote:
__________________
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) |
|
![]() |
![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
|
|