R
ReptileMikael
Guest
im building a program to pull a name from a excel sheet but each name has a different number of enteries so the higher number has a higher probability to be pulled
ID FirstName LastName Enteries
1 Bob T 250
2 Tim L 1000
so Tim should have a very high chance to be pulled and Bob a lower chance to be pulled this is what i have so far.
can someone point me in the right direction?
Public Class Form1
Dim rand As New Random
Dim CurWidth As Integer = Width
Dim CurHeight As Integer = Height
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
FileLoad()
End Sub
Sub FileLoad()
Dim MyConnection As OleDb.OleDbConnection
Dim DtSet As DataSet
Dim MyCommand As OleDb.OleDbDataAdapter
Dim dir As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Dim FullFileName As String = dir & "\results.xlsx"
MyConnection = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FullFileName + ";Extended Properties=Excel 12.0")
MyCommand = New OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection)
DtSet = New DataSet
MyCommand.Fill(DtSet)
DataGridView1.DataSource = DtSet.Tables(0)
MyConnection.Close()
End Sub
Private Sub BTN_GetWin_Click(sender As Object, e As EventArgs) Handles BTN_GetWin.Click
FindRandRow()
GetsData()
SelectRow()
DeleteRow()
End Sub
Private Function FindRandRow() As DataGridViewRow
Return DataGridView1.Rows(rand.Next(0, DataGridView1.RowCount - 1))
End Function
Private Sub GetsData()
Dim myRow As DataGridViewRow = FindRandRow()
Dim FullName As String
FullName = myRow.Cells("FirstName").Value.ToString() & " " & myRow.Cells("LastName").Value.ToString()
NameTB.Text = FullName
IDTB.Text = myRow.Cells("PatronID").Value.ToString()
End Sub
Private Sub SelectRow()
For Each row In DataGridView1.Rows
Dim cell As DataGridViewCell = row.Cells("PatronID")
Dim cell2 As DataGridViewCell = row.Cells("Firstname")
If cell.Value.ToString().Equals(IDTB.Text) = True Then
DataGridView1.CurrentCell = cell2
Exit For
End If
Next
End Sub
Private Sub DeleteRow()
For x As Integer = DataGridView1.Rows.Count - 1 To 0 Step -1
If DataGridView1.Rows(x).Cells("PatronID").Value = IDTB.Text Then
DataGridView1.Rows.Remove(DataGridView1.Rows(x))
End If
Next
End Sub
Continue reading...
ID FirstName LastName Enteries
1 Bob T 250
2 Tim L 1000
so Tim should have a very high chance to be pulled and Bob a lower chance to be pulled this is what i have so far.
can someone point me in the right direction?
Public Class Form1
Dim rand As New Random
Dim CurWidth As Integer = Width
Dim CurHeight As Integer = Height
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
FileLoad()
End Sub
Sub FileLoad()
Dim MyConnection As OleDb.OleDbConnection
Dim DtSet As DataSet
Dim MyCommand As OleDb.OleDbDataAdapter
Dim dir As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Dim FullFileName As String = dir & "\results.xlsx"
MyConnection = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FullFileName + ";Extended Properties=Excel 12.0")
MyCommand = New OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection)
DtSet = New DataSet
MyCommand.Fill(DtSet)
DataGridView1.DataSource = DtSet.Tables(0)
MyConnection.Close()
End Sub
Private Sub BTN_GetWin_Click(sender As Object, e As EventArgs) Handles BTN_GetWin.Click
FindRandRow()
GetsData()
SelectRow()
DeleteRow()
End Sub
Private Function FindRandRow() As DataGridViewRow
Return DataGridView1.Rows(rand.Next(0, DataGridView1.RowCount - 1))
End Function
Private Sub GetsData()
Dim myRow As DataGridViewRow = FindRandRow()
Dim FullName As String
FullName = myRow.Cells("FirstName").Value.ToString() & " " & myRow.Cells("LastName").Value.ToString()
NameTB.Text = FullName
IDTB.Text = myRow.Cells("PatronID").Value.ToString()
End Sub
Private Sub SelectRow()
For Each row In DataGridView1.Rows
Dim cell As DataGridViewCell = row.Cells("PatronID")
Dim cell2 As DataGridViewCell = row.Cells("Firstname")
If cell.Value.ToString().Equals(IDTB.Text) = True Then
DataGridView1.CurrentCell = cell2
Exit For
End If
Next
End Sub
Private Sub DeleteRow()
For x As Integer = DataGridView1.Rows.Count - 1 To 0 Step -1
If DataGridView1.Rows(x).Cells("PatronID").Value = IDTB.Text Then
DataGridView1.Rows.Remove(DataGridView1.Rows(x))
End If
Next
End Sub
Continue reading...