28-10-2005, 11:52 PM
|
#1 (permalink)
|
|
Broken In
Join Date: Aug 2004
Posts: 101
|
prob in VB6 code
hi.. I am creating a VB6 version of the popular CRAPS game..i think most programmers have come across it..if u dont kno it ..here r the rules..
it involves the player rolling two dies..if the sum of the two dies is 7 or 11 on first throw..the player wins...if the sum is 2,3 or 12..he loses..if it is 4,5,6,8,9 or 10,it becomes the players point and he must continue rolling the die till he makes point again..if he rolls 7 before making a point..he loses.
i used a random no generator to simulate the die rolling and created 6 .gif images to display the die images after they are rolled.
the code i used is
Code:
Dim mdie1 As Integer, mdie2 As Integer, mypoints As Integer
Dim sum As Integer
Option Explicit
Private Sub cmdexit_Click()
End
End Sub
Private Sub cmdplay_Click()
Dim imgpoint1 As Image, imgpoint2 As Image
mypoints = 0
sum = rolldice()
Select Case sum
Case Is = 7, 11
lbldisplay1.Caption = " You Win!!!! "
cmdroll.Enabled = False
cmdplay.Enabled = True
Case Is = 2, 3, 12
lbldisplay1.Caption = " Sorry, You Lose "
cmdroll.Enabled = False
cmdplay.Enabled = True
Case Is = 4, 5, 6, 8, 9, 10
lbldisplay1.Caption = " Roll Again "
mypoints = sum
Frame1.Caption = "Point is " & sum
Call displaydie(imgpoint1, mdie1)
Call displaydie(imgpoint2, mdie2)
cmdroll.Enabled = True
cmdplay.Enabled = False
End Select
End Sub
Private Function rolldice()
Dim die1 As Integer, die2 As Integer, diesum As Integer, img1 As Image, img2 As Image
die1 = 1 + Int(6 * Rnd())
die2 = 1 + Int(6 * Rnd())
Call displaydie(img1, die1)
Call displaydie(img2, die2)
mdie1 = die1
mdie2 = die2
diesum = die1 + die2
rolldice = diesum
End Function
Private Sub displaydie(imgdie As Image, face As Integer)
imgdie.Picture = LoadPicture("c:\dice\" & face & ".gif")
End Sub
Private Sub cmdroll_Click()
sum = rolldice()
Select Case sum
Case mypoints
lbldisplay1.Caption = " You Win!!! "
cmdroll.Enabled = False
cmdplay.Enabled = True
Case 7
lbldisplay1.Caption = " Sorry, You Lose "
cmdroll.Enabled = False
cmdplay.Enabled = True
Case Else
lbldisplay1.Caption = " Roll Again "
cmdroll.Enabled = True
cmdplay.Enabled = False
End Select
End Sub
now the problem is..whenever i run the program.. it gives an error
Code:
Runtime Error 91
Object variable or With variable block not set
and highlights the portion of the code
Code:
imgdie.Picture = LoadPicture("c:\dice\" & face & ".gif")
i cant find the problem..possibly its some sort of syntax error..
can you help me?
--------------------------------------------------------------------------------------
i have another question. i am an engg student and i wish to develop a program of CRAFT using VB6..is that possible.by CRAFT i mean Computerised Relative Allocation of Facilities Technique.its a part of a subject called plant layout that i have ti study.r there any engg or management students who can help me with this problem????
|
|
|
|
Advertisements. Register and be a member of the community to get rid of them.
|
|
Advertisement
|
|
29-10-2005, 01:40 AM
|
#2 (permalink)
|
|
Wise Old Owl
Join Date: May 2005
Location: Chennai, India, Asia, the Earth, the Solar system, the Milky Way, the Local group, this Universe.
Posts: 1,171
|
The error was that you haven't initialized the 'Img1' to anything in RollDice() method.
In the function DisplayDie, instead of receiving an object of type Image, you can receive an object of type "PictureBox" or stdPicture and then assign it the loadpicture()'s output.
__________________
http://myxp.blogspot.com
-----------------------
Winchester 3200+ @2,500MHz
LeadTek 7900GT VOLT MODDED @ 680 core, 1800 mem
2x1GB Transcend DDR400 @ DDR454 2.5,3,3,5,1T
|
|
|
29-10-2005, 11:02 PM
|
#3 (permalink)
|
|
Broken In
Join Date: Aug 2004
Posts: 101
|
i solved the problem..though i am not sure how it worked...i just removed the declarations for img1 and img2 and declared "imgdie" as variant....
neway..thanks for ur reply siriusb....and i would try implementing ur suggestion..
btw..is there any vb variable of type "image"???if there is..why didnt it work?
probably some mistake in declaration
|
|
|
30-10-2005, 09:34 AM
|
#4 (permalink)
|
|
Wise Old Owl
Join Date: May 2005
Location: Chennai, India, Asia, the Earth, the Solar system, the Milky Way, the Local group, this Universe.
Posts: 1,171
|
I've never used the Image class for passing anything. AFAIK, Image is a handle to a graphic displayed in a picturebox or Image control. If u want to pass the grapic of one control to another, you assign this handle value to the other control. So the Image class must be to store this handle temporarily.
__________________
http://myxp.blogspot.com
-----------------------
Winchester 3200+ @2,500MHz
LeadTek 7900GT VOLT MODDED @ 680 core, 1800 mem
2x1GB Transcend DDR400 @ DDR454 2.5,3,3,5,1T
|
|
|
30-10-2005, 11:57 PM
|
#5 (permalink)
|
|
Broken In
Join Date: Aug 2004
Posts: 101
|
ok..i'm facing a new problem now..
i want to create a two dimensional dynamic array that will take its values from a table,in which the user enters the field balues while running the program.
lets say the program i'm trying to create with prompt the user to enter data in a square matrix..from which the array elements then take their values. the no of rows and columns of the matrix will be specified by the user.
can you help me with the code that i need to write for this?
|
|
|
31-10-2005, 12:28 AM
|
#6 (permalink)
|
|
Wise Old Owl
Join Date: May 2005
Location: Chennai, India, Asia, the Earth, the Solar system, the Milky Way, the Local group, this Universe.
Posts: 1,171
|
Just use redim like this:
Code:
dim SquareMatrix() as integer
dim x as integer, y as integer
x=19
y=19
redim SquareMatrix (x,y)
to create an array of 20x20 values.
At any time you can increment the _last_ bound of the matrix thusly:
redim preserve SquareMatrix (x, y+z)
__________________
http://myxp.blogspot.com
-----------------------
Winchester 3200+ @2,500MHz
LeadTek 7900GT VOLT MODDED @ 680 core, 1800 mem
2x1GB Transcend DDR400 @ DDR454 2.5,3,3,5,1T
|
|
|
31-10-2005, 10:29 AM
|
#7 (permalink)
|
|
Broken In
Join Date: Aug 2004
Posts: 101
|
thanx for a prompt reply...but i think i could not properly express what i needed
i am being able to create a dynamic array itself..thats not a prob..
what i want to do is create an event or write a code by which the program will display a blank table in the gui in which the user enters data...the array takes its values from that table.
is it possible?
|
|
|
31-10-2005, 10:53 AM
|
#8 (permalink)
|
|
Wise Old Owl
Join Date: May 2005
Location: Chennai, India, Asia, the Earth, the Solar system, the Milky Way, the Local group, this Universe.
Posts: 1,171
|
Yes, you can do it. Two controls pop into mind: MS Flex Grid control and MS Hierarchical Flex Grid controls. They look like an MS Excel spreadsheet. You can specify the number of rows and cols. Each col can have a label. The controls also have appropriate events to let you know when a user enters or exits a cell.
Or you could also have an array of closely packed, dynamically created array of textbox controls too.
__________________
http://myxp.blogspot.com
-----------------------
Winchester 3200+ @2,500MHz
LeadTek 7900GT VOLT MODDED @ 680 core, 1800 mem
2x1GB Transcend DDR400 @ DDR454 2.5,3,3,5,1T
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|