|
Glad to hear you're making progress.
Here's a version I knocked up that populates the Image1() array from files on disk.
It also does the shuffle and (I think!) it works - just done some quick checking and can't see duplicates. It's got some constants in that I used to get spacing for the images. It also has hard coded file path to where I put the bitmap files.
It's been a bit of fun going back to VB6 - I've been using C# for the last few years (with a little bit of VB.NET).
If you decide to try VB.NET be warned it's only superficially the same as VB6 - it's really a very different language.
Option Explicit
Private Const OFFSET_X As Integer = 600
Private Const OFFSET_Y As Integer = 600
Private Const CARD_WIDTH As Integer = 1305
Private Const CARD_HEIGHT As Integer = 1425
Private Const COL_SPACE As Integer = 150
Private Const ROW_SPACE As Integer = 150
'---------------------------------------------------------------------------------------
' Initialise the Image1() control array when the Form is loaded.
' Has to be done somewhere and this seems sensible place.
'---------------------------------------------------------------------------------------
Private Sub Form_Load()
' Need to fill the Image() control array with bitmap pictures of cards
' Assume that we have 52 bitmaps - Card_1.bmp to Card_52.bmp.
' This makes it possible to fill the control array in a loop
Dim left As Long
Dim top As Long
Dim fileroot As String
Dim i As Integer
Dim j As Integer
Dim index As Integer
fileroot = "C:\VB6_Progs\Cards\Card_" 'This is where I store the bitmaps
SetImageZero (fileroot) 'Sets Image1(0) with dummy picture and makes it invisible
For i = 0 To 12 'NOTE: Using 0-12 and 0-3 makes calculation of index simpler
top = i * (CARD_HEIGHT + COL_SPACE) + OFFSET_Y
For j = 0 To 3
left = j * (CARD_WIDTH + ROW_SPACE) + OFFSET_X
index = 4 * i + j + 1
Load Image1(index) 'Create the image control for the card
Image1(index).left = left
Image1(index).top = top
Image1(index).Picture = LoadPicture(fileroot & index & ".bmp") 'Set picture for Image1(i)
Image1(index).Visible = True
Next j
Next i
End Sub
'--------------------------------------------------
' When the button is clicked, shuffle the cards
'--------------------------------------------------
Private Sub Start_Click()
ShuffleCardNumbers
End Sub
'--------------------------------------------------------------
' Helper subroutines that can be called from anywhere as needed
'--------------------------------------------------------------
Private Sub ShuffleCardNumbers()
' This shuffles the card image pictures
Dim swap As Integer
Dim posn1 As Integer
Dim posn2 As Integer
Randomize
For swap = 0 To 100
' Get two random positions
posn1 = Int((52 * Rnd) + 1)
posn2 = Int((52 * Rnd) + 1)
' Swap pictures at these positions
If (posn1 <> posn2) Then
Image1(0).Picture = Image1(posn1).Picture
Image1(posn1).Picture = Image1(posn2).Picture
Image1(posn2).Picture = Image1(0).Picture
End If
Next swap
Form1.Refresh
End Sub
Private Sub SetImageZero(ByVal fileroot As String)
Image1(0).Picture = LoadPicture(fileroot + "0.bmp")
Image1(0).Width = CARD_WIDTH
Image1(0).Height = CARD_HEIGHT
Image1(0).left = 0
Image1(0).top = 0
Image1(0).Visible = False
End Sub
Regards
David R
|
|
|
|
|
Thank you very much! I appreciate it!
Yvonne
|
|
|
|
|
Should there be a -1 somewhere in the code, making the array of images to go back one integer?
|
|
|
|
|
This doesn't work, but this is what I'm trying to say:
' Shuffle the deck - end value (100)
Card1 = 0
Card2 = 1
Counter = 0
If Card1 <> Card2 And Counter <= 100 Then
' Get two random image positions
3 Card1 = Int((52 * Rnd) + 1)
Card2 = Int((52 * Rnd) + 1)
' Swap images at these positions
Set tmpImage = Image1(Card1)
Set Image1(Card1) = Image1(Card2)
Set Image1(Card2) = tmpImage
Counter = Counter + 1
ElseIf Card1 = Card2 Then GoTo 3
End If
|
|
|
|
|
I clicked 'Post Message' when I meant to click 'Preview'
I was going to add that you should look at how Dave K gets random number sequence.
It's really how you should do it as well.
Regards
David R
|
|
|
|
|
Thanks for your comments and explanation of your code. It was so easy to understand and made much more sense than what I had. I was trying to do it much more difficult by saying "if one value does not equal the other value, than go ahead and display the images...."
I appreciate it. Thanks.
Yvonne
|
|
|
|
|
Attempting to read Progress 9.1E database from VB.Net. Connection is working and I am able to choose any table within the database. Canned Gridview, Dataset etc. will read the entire query result. The following code will only read the first record of the query ...
Public Class Requisition_Main
Private Sub BTNRefresh1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNRefresh1.Click
Dim DataRead As String = "DSN=[myodbc];Uid=[myusername];Pwd=[mypassword];server=[mydataserver]"
Dim con As New Odbc.OdbcConnection(DataRead)
Dim RecordNum As Odbc.OdbcDataReader
Dim AcctName As Odbc.OdbcDataReader
Dim GLAccount As String = Chr(34) + "gl-mstr_0" + Chr(34) + "." + Chr(34) + "gl-acc1" + Chr(34) + _
", " + Chr(34) + "gl-mstr_0" + Chr(34) + "." + Chr(34) + "gl-acc2" + Chr(34) + _
", " + Chr(34) + "gl-mstr_0" + Chr(34) + "." + Chr(34) + "gl-acc3" + Chr(34) + _
", " + Chr(34) + "gl-mstr_0" + Chr(34) + "." + Chr(34) + "gl-acc4" + Chr(34)
con.Open()
Dim recordcount As New Odbc.OdbcCommand("Select count(" + Chr(34) + "gl-mstr_0" + Chr(34) + "." + Chr(34) + "gl-acc1" + Chr(34) + _
") AS RecNum FROM PUB." + Chr(34) + "gl-mstr" + Chr(34) + " " + Chr(34) + "gl-mstr_0" + Chr(34) + _
" WHERE (" + Chr(34) + "gl-mstr_0" + Chr(34) + "." + Chr(34) + "fisc-yr" + Chr(34) + "=" & InputBox1.Text.ToString() & ")", con)
'
'recordcount = "Select count("gl-mstr_0"."gl-acc1") AS RecNum FROM PUB."gl-mstr" "gl-mstr_0" WHERE ("gl-mstr_0"."fisc-yr"=2004)"
'
RecordNum = recordcount.ExecuteReader()
RecordNum.Read()
CountTextBox.Text = RecordNum(0)
'
'CountTextBox.Text now equals "3918"
'
Dim cmd1 As New Odbc.OdbcCommand("Select " + GLAccount + " FROM PUB." + Chr(34) + "gl-mstr" + Chr(34) + _
" " + Chr(34) + "gl-mstr_0" + Chr(34) + " WHERE (" + Chr(34) + "gl-mstr_0" + Chr(34) + "." + Chr(34) + _
"fisc-yr" + Chr(34) + "=" & InputBox1.Text.ToString() & " and " + Chr(34) + "gl-mstr_0" + Chr(34) + "." + Chr(34) + _
"gl-acc1" + Chr(34) + "=" & InputBox2.Text.ToString() & ") ORDER BY " + GLAccount + "", con)
'
'cmd1 = "Select "gl-mstr_0"."gl-acc1", "gl-mstr_0"."gl-acc2", "gl-mstr_0"."gl-acc3", "gl-mstr_0"."gl-acc4" FROM PUB."gl-mstr" "gl-mstr_0" WHERE -
' ("gl-mstr_0"."fisc-yr"=2004 and "gl-mstr_0"."gl-acc1"=101) ORDER BY "gl-mstr_0"."gl-acc1", "gl-mstr_0"."gl-acc2", "gl-mstr_0"."gl-acc3", "gl-mstr_0"."gl-acc4""
'
AcctName = cmd1.ExecuteReader()
If AcctName.HasRows Then
AcctName.Read()
TxtGLmstrGLacc1.Text = AcctName.Item("gl-acc1").ToString
TxtGLmstrGLacc2.Text = AcctName.Item("gl-acc2").ToString
TxtGLmstrGLacc3.Text = AcctName.Item("gl-acc3").ToString
TxtGLmstrGLacc4.Text = AcctName.Item("gl-acc4").ToString
End If
AcctName.Close()
cmd1.Dispose()
End Sub
End Class
Any insight would be greatly appreciated.
|
|
|
|
|
Hi,
You made a simple mistake:
If AcctName.HasRows Then
AcctName.Read() <-- this will only read one row
End If
You have to loop the read method:
If AcctName.HasRows Then
While AcctName.Read() <-- this way it keeps reading (one row at a time) until it finds no more rows.
TxtGLmstrGLacc1.Text = AcctName.Item("gl-acc1").ToString 'however this (as you wrote it) will simply replace the result with each read, so it would look like you're only getting the last row
TxtGLmstrGLacc2.Text &= AcctName.Item("gl-acc2").ToString 'try something like this instead; it will add the result of each consecutive read.
TxtGLmstrGLacc3.Text &= AcctName.Item("gl-acc3").ToString
TxtGLmstrGLacc4.Text &= AcctName.Item("gl-acc4").ToString
End While
End If
My advice is free, and you may get what you paid for.
|
|
|
|
|
Great help ... I missed that one
|
|
|
|
|
I have a formula that returns a value as single. In the case that it returns something like 9.3416666666666666666666666666667, I need to use 9.34166 (5 places of precision without rounding). When using Math.Round or Format("#.#####"), the last digit is being rounded to 7 (9.34167).
Is there an easy way to accomplish this?
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
I have a corny method of making the result a string, doing string comp. of where the decimal place to return the correct thing and recasting backing into a single.
Seems like a cheesy way to do it though
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
You'd have to write your own little function to do that. You'd raise 10 to the number of decimal places you need, call it multiplier, then multiply the value in question by this multiplier, truncate the value to an integer, then divide the result by the multiplier.
Private Function RoundOff(ByVal num As Double, ByVal decimalPlaces As Integer) As Double
Dim multiplier As Double = Math.Pow(10, decimalPlaces)
Dim result As Double = Math.Truncate(num * multiplier) / multiplier
Return result
End Function
|
|
|
|
|
Brilliant!
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Dave, I beleive that credit should be given where it is due.
You have helped me yesterday, and I see you do give of yourself a lot on here, so may I just say thanks.
------------------------------------
"I am always serious about what I do, not necessarily about how I do it."
Tom Baker
|
|
|
|
|
Can I do it with the SQLdataadapter?
I've tried this code -
Dim adapterGIS As SqlDataAdapter = New SqlDataAdapter( _
queryString, connectionGIS)
Dim tblCRW_GIS_Data As DataTable
tblCRW_GIS_Data = dsCRW.Tables("CRW_GIS_Data")
adapterGIS.UpdateCommand = New SqlCommand("ALTER TABLE CRW_GIS_Data ADD (reception1 string(7)", connectionGIS)
adapterGIS.Update(tblCRW_GIS_Data)
without success. No errors, but no new column either.
Thanks
|
|
|
|
|
You can do something like this:
Using SqlConn As New SqlConnection(ConnectString), cmd As New SqlCommand("ALTER TABLE [dbo].[Setup] ADD [TestCol] [nchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL", SqlConn)
SqlConn.Open()
cmd.ExecuteNonQuery()
'populate your datatable after the column change
SqlConn.Close()
End Using
Take your raw sql statement (meaning: "ALTER TABLE CRW_GIS_Data ADD (reception1 string(7)") and run in it SQL first and fix the errors. String (use CHAR, VARCHAR, etc) is not supported in SQL.
Cheers!
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Thanks that looks like it.
Something odd though.... The query checks out in management studio 08 (SQL).
I let it run for 20 minutes and it was still executing. I killed it. Seems an awful long time to add one column. The table only has 30,000 records in it
|
|
|
|
|
Got it. An application from the previous day had been orphaned and had the table locked. Thanks again.
|
|
|
|
|
I have 2 collection objects in a LogRequest class. One is a dictionary(string, myStruct) and the other is a list(of String). In a continuous thread, I am updating the myStruct data in m_dict and possibly adding items to m_List, depending on what type of data it is.
I also have a tcp listener that accepts client requests for this data. I make the data available through 2 different properties; Data, which gets the m_dict data and StateData, which gets the list data.
Currently I am using the SyncLock in the thread during the update and when the data is retrieved for the m_dict but I am not sure what to do with locking the list. Do I use a separate lock obj or is it already locked bc it was locked at the beginning of the update? Would using the same lock obj in both retrieving routines cause a deadlock?
Public Class LogRequest
While loop
SyncLock lock_obj
For i = 0 to x (however many myStructs need to be updated in m_dict)
Dim data as myStruct= m_dict.Item(name)
data.Value = 'new value'
data.Time = 'new time'
if data.IsState then
m_List.Add("")
End if
m_dict(name) = date
Next
End While
Public ReadOnly Property Data() as string
Get SyncLock lock_obj
For each kvp as KeyValuePair(of String, myStruct) in m_dict
...builds output string
Next
Return string to client
End get
End Property
Public ReadOnly Property StateData() as string
Get
SyncLock ?? 'I dont know what to lock here
For each s as string in m_List
....builds output string
Next
Return string ot client
End SyncLock
End Get
End Property
modified on Thursday, April 9, 2009 11:00 AM
|
|
|
|
|
It doesn't look like there's a foreign key relationship between the two lists that has to be maintained, so you would probably use two lock objects, one for each list.
|
|
|
|
|
Dave, Thanks for responding...
What do mean by "foreign key relationships"
so basically I can do a lock inside of a lock
SyncLock for the dictionary
for loop through the dictionary
synclock for the list
update the list
end synclock
next
end synclock
then use the corresponding synclocks in each property
(I thought that doing this would somehow cause a deadlock)
|
|
|
|
|
This would work and not result in a deadlock. Keep in mind that the dictionary would not be readable by outside threads until the entire for loop was finished though. If this is an issue, you can move the synclock inside the loop around the update for the dictionary, freeing the object for reads by other threads until an update actually needs to be made to the dictionary.
By "foreign key rel", I mean that the data in one list does not depend on data existing in the other and being managed as a single unit.
|
|
|
|
|
The data that gets put into m_list comes from the structure that was just read from m_dict.
ex.
If data.IsState then
m_list.Add('new value', 'new time', data.ID, data.GetTextValue)
End if
where GetTextValue is a function that gets a corresponding text string to the data value
Dave Kreskowiak wrote: Keep in mind that the dictionary would not be readable by outside threads until the entire for loop was finished though.
I was aware of that and thought moving the SyncLock around just the m_dict = data line but I thought that reading it
data = m_dict(name)
would also need the lock and figured just to put it around the whole thing
modified on Thursday, April 9, 2009 2:47 PM
|
|
|
|
|
Is it possible to send arguments to a click once app? I can start a click once app programatically, but am unable to send the app any arguments.
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|