loading array to ran access file
loading array to ran access file
loading array to ran access file
loading array to ran access file
loading array to ran access file
loading array to ran access file loading array to ran access file loading array to ran access file loading array to ran access file loading array to ran access file loading array to ran access file loading array to ran access file loading array to ran access file
loading array to ran access file loading array to ran access file
loading array to ran access file
Go Back  Xtreme Visual Basic Talk > > > loading array to ran access file


Reply
 
Thread Tools Display Modes
  #1  
Old 12-23-2003, 12:01 AM
skipunk skipunk is offline
Freshman
 
Join Date: Oct 2003
Posts: 35
Default stuck on a array


I'm working on a program/game that picks random cards and displays them in the correct picture box.

one approach that i have done was create separate functions for each of the card colors. There are 5 colors and 10 cards in each color. Right now I'm just testing with 3 cards each.

What I have done is have a card chosen at random then I have used the StartsWith to see which card to display. What I'm trying to do is read the entire string of that array and then display it in the correct picturebox. Below is what I'm working on so far

Code:
Dim cards(15) As String Dim i As Integer Dim fn As String Randomize() cards(0) = "red0.jpg" cards(1) = "red1.jpg" cards(2) = "red2.jpg" cards(3) = "orange0.jpg" cards(4) = "orange1.jpg" cards(5) = "orange2.jpg" cards(6) = "yellow0.jpg" cards(7) = "yellow1.jpg" cards(8) = "yellow2.jpg" cards(9) = "white0.jpg" cards(10) = "white1.jgp" cards(11) = "white2.jpg" cards(12) = "blue0.jpg" cards(13) = "blue1.jpg" cards(14) = "blue2.jpg" i = Int(Rnd() * 14) 'randomly picks number between 0 and 14 inclusive If cards(i).StartsWith("blue") Then fn = cards(i).Length ' this is where i'm having problems. I want to read the name given to the array then assign it to fn. picBlueCard.Image = Image.FromFile(fn) ElseIf cards(i).StartsWith("white") Then fn = cards(i).Length picWhiteCard.Image = Image.FromFile(fn) ElseIf cards(i).StartsWith("yellow") Then fn = cards(i).Length picYellowCard.Image = Image.FromFile(fn) ElseIf cards(i).StartsWith("orange") Then fn = cards(i).Length picOrangeCard.Image = Image.FromFile(fn) ElseIf cards(i).StartsWith("red") Then fn = cards(i).Length picRedCard.Image = Image.FromFile(fn) End If
Reply With Quote
  #2  
Old 12-23-2003, 02:02 AM
passel's Avatar
passelloading array to ran access file passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,028
Default

.Net questions should be asked in the .Net section of the board.

Can't you just say.
fn = cards(i)
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #3  
Old 12-23-2003, 07:59 AM
Iceplug's Avatar
Iceplugloading array to ran access file Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Also,
i = Int(Rnd() * 14) 'randomly picks number between 0 and 14 inclusive
That will never give you 14.
cards(10) = "white1.jgp" <-- that looks like it might give you problems.

Also, you should consider using the VB.NET functionality instead of the old Microsoft.VisualBasic stuff... since you can do much more with the VB.NET System stuff.
For example:
Instead of randomize, you can do
Dim Ri As System.Random = New System.Random
then
i = Ri.Next(0, 14) 'and that gives you a number from 0 to 14.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #4  
Old 12-23-2003, 08:20 AM
skipunk skipunk is offline
Freshman
 
Join Date: Oct 2003
Posts: 35
Default

I'll try to give those two a try when I get home tonight. I'm just right now using some of the old VB stuff since i'm still running into trouble finding what i'm looking for in .NET. I can update the code later on once I get functionality. The stuff I do find is for databases, which I'm comfortable doing but seem to be stuck doing something basic.

I'll tinker around a bit more and see what I can come up with.

Thanks again
Reply With Quote
  #5  
Old 12-24-2003, 08:08 AM
skipunk skipunk is offline
Freshman
 
Join Date: Oct 2003
Posts: 35
Default

Quote:
Originally Posted by Iceplug

cards(10) = "white1.jgp" <-- that looks like it might give you problems.



This does give me problems I get an unexpected handle error on this card. Any reasons why? Would I be better off in breaking the cards up into their own functions? I figured this would be better especially when I move towards having the cards only being listed one time for each game.

Any suggestions?

Thanks in advance
Reply With Quote
  #6  
Old 12-24-2003, 04:20 PM
passel's Avatar
passelloading array to ran access file passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,028
Default

Iceplug was pointing out a bit of dyslexia (look closely at the spelling of
jpg).
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #7  
Old 12-25-2003, 03:12 PM
skipunk skipunk is offline
Freshman
 
Join Date: Oct 2003
Posts: 35
Default

doh. that's what i get for doing this late at night.

usually the stupid mistakes that make you go nuts.

thanks again
Reply With Quote
  #8  
Old 12-27-2003, 01:27 PM
skipunk skipunk is offline
Freshman
 
Join Date: Oct 2003
Posts: 35
Default loading array to ran access file

I'm trying to load an array into a random access file. when I test my code i get 'object reference not set to an instance of an object. I've tried changing from a string to object and still have the same problems.

Code:
Structure intCards <VBFixedString(20)> Public setCards As String End Structure Private Function initilaize() Dim setCards(14) As String Dim udtCards As intCards Dim intCardNum, i As Integer setCards(0) = "red0.jpg" setCards(1) = "red1.jpg" setCards(2) = "red2.jpg" setCards(3) = "orange0.jpg" setCards(4) = "orange1.jpg" setCards(5) = "orange2.jpg" setCards(6) = "yellow0.jpg" setCards(7) = "yellow1.jpg" setCards(8) = "yellow2.jpg" setCards(9) = "white0.jpg" setCards(10) = "white1.jpg" setCards(11) = "white2.jpg" setCards(12) = "blue0.jpg" setCards(13) = "blue1.jpg" setCards(14) = "blue2.jpg" 'open file FileOpen(1, "MainCards.data", OpenMode.Random, OpenAccess.ReadWrite, OpenShare.Shared, _ Len(udtCards)) 'load array to file For intCardNum = 0 To 14 udtCards.setCards = setCards(i) 'where I get my error FilePut(1, udtCards, intCardNum + 1) Next intCardNum FileClose(1) End Function
Reply With Quote
  #9  
Old 12-27-2003, 04:10 PM
skipunk skipunk is offline
Freshman
 
Join Date: Oct 2003
Posts: 35
Default

ok I fixed my problem above. I don't know why they taught us in my VB .NET class to use fileopen, etc, but switched to the system.io

This is where I'm at so far

Code:
recNbr = 0 Do Until defCards.Peek = -1 For i = 0 To 14 setCards = defCards.ReadLine recCards(i) = setCards 'I get my error here recNbr += 1 Next i Loop defCards.Close()

I'm wanting to load the file into an array so I can generate a random number and and load the card associated with that number. Can this be done or is there a way to generate a random number and then pull the record number from the file that was created?

this is how I have my file being created:

Code:
Dim myFile As String = "MainCards.dat" If File.Exists(myFile) And myFile.Length > 0 Then Else Dim defCards As New StreamWriter(myFile, True) nowCards(0) = "red0.jpg" nowCards(1) = "red1.jpg" nowCards(2) = "red2.jpg" nowCards(3) = "orange0.jpg" nowCards(4) = "orange1.jpg" nowCards(5) = "orange2.jpg" nowCards(6) = "yellow0.jpg" nowCards(7) = "yellow1.jpg" nowCards(8) = "yellow2.jpg" nowCards(9) = "white0.jpg" nowCards(10) = "white1.jpg" nowCards(11) = "white2.jpg" nowCards(12) = "blue0.jpg" nowCards(13) = "blue1.jpg" nowCards(14) = "blue2.jpg" For i = 0 To 14 defCards.WriteLine(nowCards(i)) Next i defCards.Close()

the codes are a bit messy. I haven't had a chance to clean them up yet. if I can get the part above working then I'll be in the clear (hopefully :-))

thanks in advance
Reply With Quote
  #10  
Old 12-28-2003, 11:19 PM
AndreRyan AndreRyan is offline
Contributor
 
Join Date: Jan 2002
Posts: 489
Default

What's the declaration of all the variables you're using?
__________________
If you're a beginner or have little experience don't launch into something beyond your abilities, for example don't start game programming by trying to make a 3D first person shooter if you have no idea how to use DirectX and/or OpenGL or how to keep track of objects in a 2D plane let alone a 3D one.
Reply With Quote
  #11  
Old 12-30-2003, 09:39 AM
skipunk skipunk is offline
Freshman
 
Join Date: Oct 2003
Posts: 35
Default

Quote:
Originally Posted by AndreRyan
What's the declaration of all the variables you're using?



here is a part of the code that I'm working on. If I can get the file to load into an array then the rest should fall into place.



Code:
'This is part of a click event Private Sub btnDraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDraw.Click Dim i As Integer Dim myFile As String = "MainCards.dat" Dim defCards As New StreamReader(myFile) Dim fn, setCards, recCards() As String Dim ri As New Random() Dim recNbr As Int32 recNbr = 0 Do Until defCards.Peek = -1 For i = 0 To 14 setCards = defCards.ReadLine recCards(i) = setCards recNbr += 1 Next i Loop defCards.Close() i = ri.Next(0, 14) 'pick a random number. use number to find recNbr in file

Code:
'this code is part of it's own function called Private Function initilaize() Dim nowCards(14) As Object Dim intCardNum, i As Integer Dim myFile As String = "MainCards.dat" If File.Exists(myFile) And myFile.Length > 0 Then 'do nothing Else Dim defCards As New StreamWriter(myFile, True) nowCards(0) = "red0.jpg" nowCards(1) = "red1.jpg" nowCards(2) = "red2.jpg" nowCards(3) = "orange0.jpg" nowCards(4) = "orange1.jpg" nowCards(5) = "orange2.jpg" nowCards(6) = "yellow0.jpg" nowCards(7) = "yellow1.jpg" nowCards(8) = "yellow2.jpg" nowCards(9) = "white0.jpg" nowCards(10) = "white1.jpg" nowCards(11) = "white2.jpg" nowCards(12) = "blue0.jpg" nowCards(13) = "blue1.jpg" nowCards(14) = "blue2.jpg" For i = 0 To 14 defCards.WriteLine(nowCards(i)) Next i defCards.Close() End If
Reply With Quote
  #12  
Old 12-30-2003, 11:45 PM
AndreRyan AndreRyan is offline
Contributor
 
Join Date: Jan 2002
Posts: 489
Default

Code:
Dim nowCards(14) As Object
Don't use the Object class unless you don't know what the incoming data is. Use the String object.
Code:
Dim nowCards(14) As String

So you want to randomly arrange the cards in a second array?
Code:
Dim i As Short, Cards(14) As String, R As Integer, C As Short For i = 0 To 14 'Loop through the card records R = Ri.Next(0, 14) 'Get a random number If Cards(R) = String.Empty Then 'If the random position is empty Cards(R) = recCards(i) 'set the card Else 'If the position has something in it, just add the card to the array For C = 0 To 14 If Cards(C) = String.Empty Then Cards(C) = recCards(i) Next End If Next
__________________
If you're a beginner or have little experience don't launch into something beyond your abilities, for example don't start game programming by trying to make a 3D first person shooter if you have no idea how to use DirectX and/or OpenGL or how to keep track of objects in a 2D plane let alone a 3D one.
Reply With Quote
Reply


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

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Standards and Practices loquin Tutors' Corner 10 07-28-2006 01:16 PM
Installation Problem - PLs help urgenlty dpdsouza Installation / Documentation 4 12-02-2004 08:09 PM
Array and String Functions rhawke General 5 07-10-2003 03:33 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
loading array to ran access file
loading array to ran access file
loading array to ran access file loading array to ran access file
loading array to ran access file
loading array to ran access file
loading array to ran access file loading array to ran access file loading array to ran access file loading array to ran access file loading array to ran access file loading array to ran access file loading array to ran access file
loading array to ran access file
loading array to ran access file
 
loading array to ran access file
loading array to ran access file
 
-->