Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,573 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,920 people online right now. Registration is fast and FREE... Join Now!




arrays matching numbers

 
Reply to this topicStart new topic

arrays matching numbers

sherrill
2 Apr, 2008 - 06:48 PM
Post #1

New D.I.C Head
*

Joined: 27 Mar, 2008
Posts: 9

everything works but i can't seem to get the matching off the numbers calculate to work...any suggetions?

vb

Public Class frmMain

Const intMAX_VALUES As Integer = 4 ' Array upper subscript
Dim intSelect(intMAX_VALUES) As Integer ' Loop counter
Private rand As New Random(9) ' Random generator

Private Sub btnInput_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInput.Click

' Enter the five numbers into list box.
Dim intCount As Integer

' Get input and display in list box.
For intCount = 0 To intMAX_VALUES
intSelect(intCount) = GetIntInput()
Next

' Display the input values.
For intCount = 0 To intMAX_VALUES
lblInput1.Text = CStr((intSelect(intCount)))
lblInput2.Text = CStr((intSelect(intCount)))
lblInput3.Text = CStr((intSelect(intCount)))
lblInput4.Text = CStr((intSelect(intCount)))
lblInput5.Text = CStr((intSelect(intCount)))
Next

End Sub

Private Sub btnGen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGen.Click

' Generates random numbers
Dim intNumber(4) As Integer

' Generates five numbers
intNumber(0) = rand.Next(9)
intNumber(1) = rand.Next(9)
intNumber(2) = rand.Next(9)
intNumber(3) = rand.Next(9)
intNumber(4) = rand.Next(9)

' Enters random numbers into labels.
lblNum1.Text = CStr(intNumber(0))
lblNum2.Text = CStr(intNumber(1))
lblNum3.Text = CStr(intNumber(2))
lblNum4.Text = CStr(intNumber(3))
lblNum5.Text = CStr(intNumber(4))

End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

' Ends the applicattion
Me.Close()
End Sub

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click

' Clears all the labels for user input
lblInput1.Text = ""
lblInput2.Text = ""
lblInput3.Text = ""
lblInput4.Text = ""
lblInput5.Text = ""

' Clears all the labels for random numbers
lblNum1.Text = ""
lblNum2.Text = ""
lblNum3.Text = ""
lblNum4.Text = ""
lblNum5.Text = ""

End Sub

Private Sub btnMatch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMatch.Click

' Calculate the numbers that match
Dim intCount As Integer
Dim intWin As Integer = 0 ' All digits match
Dim intMatch1 As Boolean = False
Dim intMatch2 As Boolean = False
Dim intMatch3 As Boolean = False
Dim intMatch4 As Boolean = False
Dim intMatch5 As Boolean = False

' Looks for matching numbers
For intCount = 0 To intMAX_VALUES
If intInput(0) = intNumber(intCount) And intMatch1 = False Then
intWin = intWin + 1
intMatch1 = True
End If
If inInput(1) = intNumber(intCount) And intMatch2 = False Then
intWin = intWin + 1
intMatch2 = True
End If
If intInput(2) = intNumber(intCount) And intMatch3 = False Then
intWin = intWin + 1
intMatch3 = True
End If
If intInput(3) = intNumber(intCount) And intMatch4 = False Then
intWin = intWin + 1
intMatch14 = True
End If
If intInput(4) = intNumber(intCount) And intMatch5 = False Then
intWin = intWin + 1
intMatch5 = True
End If
Next

' Message box proclaiming grand prize winner
If intWin = 5 Then
MessageBox.Show("Grand Prize Winner", "Congradulations")
End If

End Sub

End Class


form entry user numbers
Public Class frmEntry

Dim intSelect As Integer = 0 ' Class level variable

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

' Check input textbox for numeric, if it is store in class level variable
If EntriesValid(txtSelect) Then
intSelect = CInt(txtSelect.Text)
Me.Close()
End If

End Sub

Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click

' Closes data entry form
Me.Close()

End Sub

Function EntriesValid(ByVal aTxtObject As TextBox) As Boolean

' Check input for numeric number
Dim InputsOK As Boolean = True
If IsNumeric(aTxtObject.Text) Then
errError.SetError(aTxtObject, "")
Else
errError.SetError(aTxtObject, "User input must be numeric")
InputsOK = False
End If
Return InputsOK

End Function

Public Function GetInput() As Integer

' Function to return class level variable, note variable is not global
Return intSelect
End Function

End Class

module
Module EntryModule

Public Function GetIntInput() As Integer

' GetIntInput function to create an instance of entry form
' ShowDialog the form and wait for form to close
' The GetInput function will return the input value and pass to calling function

Dim entryForm As New frmEntry
entryForm.ShowDialog()
Return entryForm.GetInput()
End Function

End Module


EDIT: Please use code tags => code.gif

This post has been edited by PsychoCoder: 2 Apr, 2008 - 08:08 PM
User is offlineProfile CardPM
+Quote Post

KeyWiz
RE: Arrays Matching Numbers
3 Apr, 2008 - 05:19 PM
Post #2

D.I.C Regular
Group Icon

Joined: 26 Oct, 2006
Posts: 428


Dream Kudos: 125
My Contributions
What version of Visual Basic are you using? I have tried pasting your code into both VB6 and VB2005 Express and both show multiple errors and ommisions, even when I add all the elements and forms you name.

But I would guess that your proble may be in your here
CODE

    Public Function GetInput() As Integer  
  
        ' Function to return class level variable, note variable is not global  
        Return intSelect  
    End Function  


You are returning intSelect, but you declared intSelect as an Array so you need to return intSelect(MyVal), passing MyVal either by reference or by value into the GetInput Funtion

You might be Over-Designing here. If I understand your intent you need to compare Values entered to Values generated Randomly, correct?
Basically it appears as if you are trying to make a simple Lottery simulator, correct?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 12:01AM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month