I am done with designing the windows form::
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ComboBox2.Visible = False
Label2.Visible = False
ComboBox3.Visible = False
Label3.Visible = False
ComboBox4.Visible = False
Label4.Visible = False
ComboBox5.Visible = False
Label5.Visible = False
DateTimePicker1.Visible = False
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
If (ComboBox1.Text = "BY-ELECTION") Then
ComboBox2.Visible = True
Label2.Visible = True
DateTimePicker1.Visible = False
ElseIf (ComboBox1.Text = "GENERAL ELECTION") Then
ComboBox2.Visible = False
Label2.Visible = False
ComboBox3.Visible = False
Label3.Visible = False
ComboBox4.Visible = False
Label4.Visible = False
ComboBox5.Visible = False
Label5.Visible = False
DateTimePicker1.Visible = True
End If
End Sub
Private Sub ComboBox4_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox4.SelectedIndexChanged
If ComboBox4.SelectedValue = "" And ComboBox2.Text = "MP" Then
DateTimePicker1.Visible = True
End If
If (ComboBox4.Text = "MVITA") And ComboBox2.Text = "MCA" Then
Label5.Visible = True
ComboBox5.Visible = True
ComboBox5.Items.Clear()
ComboBox5.Items.Add("MAJENGO")
ComboBox5.Items.Add("MAKADARA")
ComboBox5.Items.Add("SHIMANZI")
ComboBox5.Items.Add("TONONOKA")
ComboBox5.Items.Add("TUDOR")
DateTimePicker1.Visible = False
End If
End Sub
Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.SelectedIndexChanged
If (ComboBox3.Text = "MOMBASA") And ComboBox2.Text = "MP" Or (ComboBox3.Text = "MOMBASA") And ComboBox2.Text = "MCA" Then
Label4.Visible = True
ComboBox4.Visible = True
ComboBox4.Items.Clear()
ComboBox4.Items.Add("CHANGAMWE")
ComboBox4.Items.Add("JOMVU")
ComboBox4.Items.Add("KISAUNI")
ComboBox4.Items.Add("LIKONI")
ComboBox4.Items.Add("MVITA")
ComboBox4.Items.Add("NYALI")
End If
End Sub
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
If ComboBox2.Text = "GOVERNORSHIP" Or ComboBox2.Text = "SENATOR" Then
Label3.Visible = True
ComboBox3.Visible = True
Label5.Visible = False
ComboBox5.Visible = False
DateTimePicker1.Visible = True
ComboBox4.Visible = False
Label4.Visible = False
ElseIf ComboBox2.Text = "MP" Or ComboBox2.Text = "MCA" Then
Label3.Visible = True
ComboBox3.Visible = True
DateTimePicker1.Visible = False
Label6.Visible = False
ComboBox4.Visible = False
Label4.Visible = False
ComboBox5.Visible = False
Label5.Visible = False
End If
End Sub
Private Sub ComboBox5_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox5.SelectedIndexChanged
Label6.Visible = True
DateTimePicker1.Visible = True
End Sub
and i am stuck at the command button.
My windows form has 5 combobox with items assigned to them but in this illustration i am going to use one item for example:
Combobox2 has item MCA
Combobox3(labeled COUNTY) has item MOMBASA
Combobox4(labeled CONSTITUENCY) has item MVITA
Combobox5(labeled WARD) has item SHIMANZI
I want if i select item MCA in combobox2 and click the button GENERATE a table:
will be created and saved in the path C:\Users\Administrator\Documents\ and populated in the following format
cell A2 = item selected in combobox3
cell B2= item selected in combobox4
cell C2=item selected in combobox5
cell H2 to be populated with random input be based on gender(male/female) and letters(ABCD only) in that order. ie cell H2= MALE,D
You can refer to the following code to generate DataTable.
Dim dt As DataTable = New DataTable
dt.Columns.Add("COUNTY")
dt.Columns.Add("CONSTITUENCY")
dt.Columns.Add("WARD")
dt.Rows.Add(ComboBox3.SelectedItem.ToString, ComboBox4.SelectedItem.ToString, ComboBox5.SelectedItem.ToString)
Then use the following code to export the data table to Excel:
Dim excelFilePath As String = "excel path"
Dim excelApp = New Excel.Application()
excelApp.Workbooks.Add()
Dim workSheet As Excel._Worksheet = excelApp.ActiveSheet
For i = 0 To dt.Columns.Count - 1
workSheet.Cells(1, i + 1) = dt.Columns(i).ColumnName
Next
For i = 0 To dt.Rows.Count - 1
For j = 0 To dt.Columns.Count - 1
workSheet.Cells(i + 2, j + 1) = dt.Rows(i)(j)
Next
Next
If Not String.IsNullOrEmpty(excelFilePath) Then
Try
workSheet.SaveAs(excelFilePath)
excelApp.Quit()
MessageBox.Show("Excel file saved!")
Catch ex As Exception
Throw New Exception("ExportToExcel: Excel file could not be saved! Check filepath." & vbLf & ex.Message)
End Try
End If
Result of the test looks like:
Related
This is the question I'm having difficulty figuring out. I'm unable to get splash screens to show up on my previous two questions I was able to complete the coding and design, but this one is throwing me for a loop.
This is what I have so far
Public Sub New()
InitializeComponent()
label2.Visible = False
label3.Visible = False
label4.Visible = False
comboBox1.Items.Add("Uber")
comboBox1.Items.Add("Subway")
comboBox1.Items.Add("Bus")
End Sub
Private Sub comboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
If comboBox1.SelectedIndex = 0 Then
label2.Visible = True
label3.Visible = True
label4.Visible = True
End If
If comboBox1.SelectedIndex = 1 Then
label2.Visible = True
label3.Visible = True
label4.Visible = False
End If
If comboBox1.SelectedIndex = 2 Then
label2.Visible = True
label3.Visible = True
label4.Visible = False
End If
End Sub
I have an access databasetable with addresses and a table with addresstypes.
When i add a new relation there's different groupboxes with additional information that should be displayed according to the addresstype.
For example: a patient has only basic address info.
A doctor needs a reference number too, so if i click on relation type "doctor" the address groupbox should appear but also the groupbox with doctor reference textbox.
An instance should also get the instance groupbox + address groupbox etc etc.
Addresses can also be "multiple types" so if an address is A: a doctor, and B an instance, both boxes should appear.
My current code looks like this:
Public Class NewRelationForm
'groupboxen disablen on load
Me.grpKiesUwRelatietype.Visible = True
Me.grpBasisData.Visible = False
Me.grpDataBI.Visible = False
Me.grpFoto_Nota.Visible = False
Me.grpHuisartsData.Visible = False
Me.grpPartijData.Visible = False
Me.grpVerwijzerdata.Visible = False
End Sub
'KNOPPEN en Functies!
Private Sub NewRelationForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Tbl_TypeTableAdapter1.Fill(Me.PatientenDatabaseDataSetX1.tbl_Type)
Me.Tbl_OnderzoeksTypesTableAdapter.Fill(Me.PatientenDatabaseDataSetX1.tbl_OnderzoeksTypes)
Me.Tbl_RelatiesTableAdapter.Fill(Me.PatientenDatabaseDataSetX.tbl_Relaties)
End Sub
Private Sub btnAddRelation_Click(sender As Object, e As EventArgs) Handles btnAddRelation.Click
FormMakeRelationType.Show()
End Sub
Private Sub lboxRelatieTypes_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lboxRelatieTypes.SelectedIndexChanged
End Sub
'Private Sub lboxRelatieTypes_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lboxRelatieTypes.SelectedIndexChanged
''If ComboBox1.SelectedIndex = 1 Then
'' grpBasisData.Visible = True
'' grpFoto_Nota.Visible = True
'' grpFoto_Nota.Location = New Point(720, 120)
''End If
'End Sub
End Class
I could really use a pointer in how to do this, i've tried if else, i've tried select case, but i can't find "the right way".
I'm a beginner
edit1: This is a pic from the winform: https://imgur.com/a/80pKnjR
and this is the access db (names in the db are changed for privacy purposes
https://www.dropbox.com/sh/4gudk8lwxtjahiq/AACz69ocFWIlU7hiTlQxbviLa?dl=0
I found it...
based on an article in stackoverflow: How to show hidden text boxes when items are selected in a combo box
If someone knows how to make this piece of code "easier to handle" or "more compact" i'm very open to ideas.
Also: i can only select one , the rest of the groupboxes dissappear , so it needs some finetuning but i'm 90% there!
Private Sub lboxRelatieTypes_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lboxRelatieTypes.SelectedIndexChanged
If lboxRelatieTypes.Text.Trim.Contains("Patiƫnt") = True Then
Me.grpBasisData.Visible = True
Me.grpDataBI.Visible = False
Me.grpFoto_Nota.Visible = True
Me.grpHuisartsData.Visible = False
Me.grpPartijData.Visible = False
Me.grpVerwijzerdata.Visible = False
ElseIf lboxRelatieTypes.Text.Trim.Contains("Verwijzer") = True Then
Me.grpBasisData.Visible = True
Me.grpDataBI.Visible = False
Me.grpFoto_Nota.Visible = True
Me.grpHuisartsData.Visible = False
Me.grpPartijData.Visible = False
Me.grpVerwijzerdata.Visible = True
ElseIf lboxRelatieTypes.Text.Trim.Contains("Betalende Instantie") = True Then
Me.grpBasisData.Visible = True
Me.grpDataBI.Visible = True
Me.grpFoto_Nota.Visible = True
Me.grpHuisartsData.Visible = False
Me.grpPartijData.Visible = True
Me.grpVerwijzerdata.Visible = False
ElseIf lboxRelatieTypes.Text.Trim.Contains("Huisarts") = True Then
Me.grpBasisData.Visible = True
Me.grpDataBI.Visible = False
Me.grpFoto_Nota.Visible = True
Me.grpHuisartsData.Visible = True
Me.grpPartijData.Visible = False
Me.grpVerwijzerdata.Visible = False
ElseIf lboxRelatieTypes.Text.Trim.Contains("Huisarts" & "Betalende Instantie") = True Then
Me.grpBasisData.Visible = True
Me.grpDataBI.Visible = True
Me.grpFoto_Nota.Visible = True
Me.grpHuisartsData.Visible = True
Me.grpPartijData.Visible = False
Me.grpVerwijzerdata.Visible = False
End If
'Dim curitem As String = lboxRelatieTypes.SelectedItems.ToString()
'Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\GoogleDrive\EINDWERK VBNET\PatientenDatabase.accdb")
'con.Open()
'Dim sql As String = String.Format("select * from tbl_Relaties where Rel_Type='{0}'", curitem)
'Dim command As New OleDbCommand(sql, con)
'Dim reader As OleDbDataReader = command.ExecuteReader()
'If curitem.Contains "Huisarts" Then
' End If
'con.Close()
I make a code example, which show the textbox in the groupbox based on the listbox.
Form_Load event:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\PatientenDatabase.mdb")
con.Open()
Dim sql As String = "select Type_Naam from tbl_type"
Dim command As New OleDbCommand(sql, con)
Dim reader As OleDbDataReader = command.ExecuteReader()
While reader.Read()
ListBox1.Items.Add(reader.GetString(0))
End While
con.Close()
End Sub
Listboxindexchanged event:
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
Dim curItem As String = ListBox1.SelectedItem.ToString()
Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\PatientenDatabase.mdb")
con.Open()
Dim sql As String = String.Format("select * from tbl_Relaties where Rel_Type='{0}'", curItem)
Dim command As New OleDbCommand(sql, con)
Dim reader As OleDbDataReader = command.ExecuteReader()
If reader.HasRows Then
While reader.Read()
txtID.Text = reader.GetValue(0).ToString()
txtType.Text = reader.GetValue(1).ToString()
txtName.Text = reader.GetValue(2).ToString()
txtVoo.Text = reader.GetValue(3).ToString()
txtAdress.Text = reader.GetValue(4).ToString()
End While
Else
txtID.Text = String.Empty
txtType.Text = String.Empty
txtName.Text = String.Empty
txtVoo.Text = String.Empty
txtAdress.Text = String.Empty
End If
con.Close()
End Sub
Final result:
Besides, I only make a few column code and you can follow the above code to complete the rest of the code.
I'm working on this assignment where I need to have an array inside of a structure. The array consists of imported values from a text file:
2,3
3,4
4,4
5,5
5,4
6,3
3,6
9,9
10,10
1,5
2,5
3,5
1,4
2,4
3,4
4,4
I'm getting these errors:
Severity Code Description Project File Line Suppression State
Error BC30456 'real' is not a member of 'Form1.complexNumber()'. WindowsApplication3 e:\users\gabe\documents\visual studio 2015\Projects\Lab7_Gabriel_Carnes\WindowsApplication3\Form1.vb 68 Active
Severity Code Description Project File Line Suppression State
Error BC30311 Value of type 'Form1.complexNumber' cannot be converted to 'String'. WindowsApplication3 e:\users\gabe\documents\visual studio 2015\Projects\Lab7_Gabriel_Carnes\WindowsApplication3\Form1.vb 69 Active
I've tried moving the structure to be within a method instead of at form level but it then gives an error about not being able to be within a method.
Code:
Public Class Form1
Dim Real1, Real2, Imag1, Imag2 As Double
Dim Answer As String
Private Structure complexNumber
Public real As String
Public imag As String
End Structure
' Dim strValues() As fileInport =
' IO.File.ReadAllLines("Input.txt")
Dim Values(15) As complexNumber
Dim ValuesString As String
Dim line, data() As String
Dim inputs() As String =
IO.File.ReadAllLines("Input.txt")
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
lblBy.Visible = False
lblMinus.Visible = False
lblPlus.Visible = False
lblTimes.Visible = False
lblAnswer.Text = ""
For i As Integer = 0 To 15
line = inputs(i)
data = line.Split(","c)
Values(i).real = data(0)
Values(i).imag = data(1)
'Values(i) = (strValues(i))
Next
End Sub
'ALL TEXT FILE VALUE CALCULATIONS
Private Sub btnFileAdd_Click(sender As Object, e As EventArgs) Handles btnFileAdd.Click
'ComplexMath.MathFunctions.Add(Values(0).real, Values(0).imag, Values(1).real, Values(1).imag)
'lstFileResults.Items.AddRange = Values(15)
ValuesString = Values.real(15)
TextBox1.Text = Values(15)
lblBy.Visible = False
lblTimes.Visible = False
lblMinus.Visible = False
lblPlus.Visible = True
End Sub
Private Sub btnFileSubtract_Click(sender As Object, e As EventArgs) Handles btnFileSubtract.Click
lblBy.Visible = False
lblTimes.Visible = False
lblPlus.Visible = False
lblMinus.Visible = True
End Sub
Private Sub btnFileMultiply_Click(sender As Object, e As EventArgs) Handles btnFileMultiply.Click
lblBy.Visible = False
lblPlus.Visible = False
lblMinus.Visible = False
lblTimes.Visible = True
End Sub
Private Sub btnFileDivide_Click(sender As Object, e As EventArgs) Handles btnFileDivide.Click
lblTimes.Visible = False
lblPlus.Visible = False
lblMinus.Visible = False
lblBy.Visible = True
End Sub
'ALL USER VALUE CALCULATIONS
Private Sub btnUserAdd_Click(sender As Object, e As EventArgs) Handles btnUserAdd.Click
Real1 = Val(txtReal1.Text)
Real2 = Val(txtReal2.Text)
Imag1 = Val(txtImag1.Text)
Imag2 = Val(txtImag2.Text)
Answer = ComplexMath.MathFunctions.Add(Real1, Imag1, Real2, Imag2)
lblAnswer.Text = Answer
lblBy.Visible = False
lblTimes.Visible = False
lblMinus.Visible = False
lblPlus.Visible = True
End Sub
Private Sub btnUserSubtract_Click(sender As Object, e As EventArgs) Handles btnUserSubtract.Click
Real1 = Val(txtReal1.Text)
Real2 = Val(txtReal2.Text)
Imag1 = Val(txtImag1.Text)
Imag2 = Val(txtImag2.Text)
Answer = ComplexMath.MathFunctions.Subtract(Real1, Imag1, Real2, Imag2)
lblAnswer.Text = Answer
lblBy.Visible = False
lblTimes.Visible = False
lblPlus.Visible = False
lblMinus.Visible = True
End Sub
Private Sub btnUserMultiply_Click(sender As Object, e As EventArgs) Handles btnUserMultiply.Click
Real1 = Val(txtReal1.Text)
Real2 = Val(txtReal2.Text)
Imag1 = Val(txtImag1.Text)
Imag2 = Val(txtImag2.Text)
Answer = ComplexMath.MathFunctions.Multiply(Real1, Imag1, Real2, Imag2)
lblAnswer.Text = Answer
lblBy.Visible = False
lblPlus.Visible = False
lblMinus.Visible = False
lblTimes.Visible = True
End Sub
Private Sub btnUserDivide_Click(sender As Object, e As EventArgs) Handles btnUserDivide.Click
Real1 = Val(txtReal1.Text)
Real2 = Val(txtReal2.Text)
Imag1 = Val(txtImag1.Text)
Imag2 = Val(txtImag2.Text)
Answer = ComplexMath.MathFunctions.Multiply(Real1, Imag1, Real2, Imag2)
lblAnswer.Text = Answer
lblTimes.Visible = False
lblPlus.Visible = False
lblMinus.Visible = False
lblBy.Visible = True
End Sub
End Class
I'm quite new to Visual Basic. I'm developing a simple Student Registration System that has a profile of Students with a photo in it. I managed to get the image addition code online and I tried to figure it out and use it for my program. All is set except the sql insert statement that will insert the photo into the "Image" field of the "Students" table of my database. When I click the save button, I keep getting Insert into syntax error but I can't seem to figure out exactly what the error in the sql statement is. I would appreciate it if I can get help with it. This is the whole code for the profile but I have put a comment where the sql statement is so you can go straight there. Thanks and Thanks again
Imports System.IO
Imports System.Data.OleDb
Public Class Profile
Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim da As New OleDb.OleDbDataAdapter
Dim sql As String
Dim conString As String
Dim inc As Integer
Dim maxrows As Integer
Dim dsNewRow As DataRow
Dim SID As String
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles txtNationality.SelectedIndexChanged
End Sub
Private Sub GroupBox1_Enter(sender As Object, e As EventArgs) Handles GroupBox1.Enter
End Sub
Private Sub ProfileRecords()
txtFirstName.Text = ds.Tables("StudentRegSYS").Rows(inc).Item(1)
txtMiddleName.Text = ds.Tables("StudentRegSYS").Rows(inc).Item(2)
txtLastName.Text = ds.Tables("StudentRegSYS").Rows(inc).Item(3)
txtGender.Text = ds.Tables("StudentRegSYS").Rows(inc).Item(4)
txtNationality.Text = ds.Tables("StudentRegSYS").Rows(inc).Item(5)
txtLevel.Text = ds.Tables("StudentRegSYS").Rows(inc).Item(6)
txtFaculty.Text = ds.Tables("StudentRegSYS").Rows(inc).Item(7)
txtProgramme.Text = ds.Tables("StudentRegSYS").Rows(inc).Item(8)
txtAcademicPeriod.Text = ds.Tables("StudentRegSYS").Rows(inc).Item(9)
txtDateRegistered.Text = ds.Tables("StudentRegSYS").Rows(inc).Item(10)
maxrows = ds.Tables("StudentRegSYS").Rows.Count
txtFirstName.ReadOnly = True
txtMiddleName.ReadOnly = True
txtLastName.ReadOnly = True
txtGender.Enabled = False
txtFaculty.Enabled = False
txtLevel.ReadOnly = True
txtNationality.Enabled = False
txtProgramme.Enabled = False
txtAcademicPeriod.ReadOnly = True
txtDateRegistered.ReadOnly = True
End Sub
Private Sub Profile_Load(sender As Object, e As EventArgs) Handles MyBase.Load
SID = Login.txtstudentid.Text
btneditcancel.Visible = False
btneditsave.Visible = False
btnbrowseimage.Visible = False
txtimagepath.Visible = False
Try
conString = "Provider = Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Yaw Biney\Documents\Visual Studio 2015\Projects\Student Registration System\Student Registration System\StudentRegSYS.accdb"
con = New OleDbConnection(conString)
con.Open()
sql = "select * from Students Where SID='" + SID + "'"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "StudentRegSYS")
con.Close()
Catch EXP As Exception
MessageBox.Show(EXP.ToString)
End Try
con.Open()
ProfileRecords()
txtNationality.Items.Add("Ghanaian")
txtNationality.Items.Add("Togolese")
txtNationality.Items.Add("Gabonese")
txtNationality.Items.Add("Ivorian")
txtNationality.Items.Add("Burkinabe")
txtNationality.Items.Add("Nigerian")
txtNationality.Items.Add("Beninois")
txtFaculty.Items.Add("Informatics")
txtFaculty.Items.Add("Engineering")
txtFaculty.Items.Add("Business")
txtProgramme.Items.Add("Bsc. Information Technology")
txtProgramme.Items.Add("Bsc. Telecom Engineering")
txtProgramme.Items.Add("Bsc. Computer Engineering")
txtProgramme.Items.Add("BA. Business Administration")
txtProgramme.Items.Add("Diploma in Information Technology")
txtProgramme.Items.Add("Diploma in Business Studies")
txtwelcomemsg.Text = "Welcome " & txtLastName.Text & ", " & txtFirstName.Text & " " & txtMiddleName.Text
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles txtMiddleName.TextChanged
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
btneditcancel.Visible = True
btneditsave.Visible = True
btnbrowseimage.Visible = True
txtimagepath.Visible = True
txtFirstName.ReadOnly = False
txtMiddleName.ReadOnly = False
txtLastName.ReadOnly = False
txtGender.Enabled = True
txtFaculty.Enabled = True
txtLevel.ReadOnly = False
txtNationality.Enabled = True
txtProgramme.Enabled = True
txtAcademicPeriod.ReadOnly = False
txtDateRegistered.ReadOnly = False
End Sub
Private Sub btneditcancel_Click(sender As Object, e As EventArgs) Handles btneditcancel.Click
btneditcancel.Visible = False
btneditsave.Visible = False
btnbrowseimage.Visible = False
txtimagepath.Visible = False
txtFirstName.ReadOnly = True
txtMiddleName.ReadOnly = True
txtLastName.ReadOnly = True
txtGender.Enabled = False
txtFaculty.Enabled = False
txtLevel.ReadOnly = True
txtNationality.Enabled = False
txtProgramme.Enabled = False
txtAcademicPeriod.ReadOnly = True
txtDateRegistered.ReadOnly = True
End Sub
Private Sub btneditsave_Click(sender As Object, e As EventArgs) Handles btneditsave.Click
Dim cb As New OleDb.OleDbCommandBuilder(da)
Try
ds.Tables("StudentRegSYS").Rows(inc).Item(1) = txtFirstName.Text
ds.Tables("StudentRegSYS").Rows(inc).Item(2) = txtMiddleName.Text
ds.Tables("StudentRegSYS").Rows(inc).Item(3) = txtLastName.Text
ds.Tables("StudentRegSYS").Rows(inc).Item(4) = txtGender.Text
ds.Tables("StudentRegSYS").Rows(inc).Item(5) = txtNationality.Text
ds.Tables("StudentRegSYS").Rows(inc).Item(6) = txtLevel.Text
ds.Tables("StudentRegSYS").Rows(inc).Item(7) = txtFaculty.Text
ds.Tables("StudentRegSYS").Rows(inc).Item(8) = txtProgramme.Text
ds.Tables("StudentRegSYS").Rows(inc).Item(9) = txtAcademicPeriod.Text
ds.Tables("StudentRegSYS").Rows(inc).Item(10) = txtDateRegistered.Text
da.Update(ds, "StudentRegSYS")
MessageBox.Show("Profile updated successfully")
Catch ex As Exception
MessageBox.Show("Error: " & ex.ToString())
End Try
'Error seems to be from here on going'
Try
Dim MemStream As New MemoryStream
Dim DataPic_Update As Byte()
Me.picboxprofilepic.Image.Save(MemStream, Imaging.ImageFormat.Jpeg)
DataPic_Update = MemStream.GetBuffer()
MemStream.Read(DataPic_Update, 0, MemStream.Length)
Dim cmd As OleDbCommand = New OleDbCommand("INSERT INTO Students (Image) VALUES(#Image)", con)
Dim photo As OleDbParameter = New OleDbParameter("#Image", SqlDbType.Image)
photo.Value = DataPic_Update
cmd.Parameters.Add(photo)
cmd.ExecuteNonQuery()
MessageBox.Show("Record Is Added")
Catch ex As Exception
MessageBox.Show("Error: " & ex.ToString())
End Try
btneditcancel.Visible = False
btneditsave.Visible = False
btnbrowseimage.Visible = False
txtimagepath.Visible = False
txtFirstName.ReadOnly = True
txtMiddleName.ReadOnly = True
txtLastName.ReadOnly = True
txtGender.Enabled = False
txtFaculty.Enabled = False
txtLevel.ReadOnly = True
txtNationality.Enabled = False
txtProgramme.Enabled = False
txtAcademicPeriod.ReadOnly = True
txtDateRegistered.ReadOnly = True
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Change_Password.Show()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnbrowseimage.Click
OpenFileDialog1.Filter = "jpeg|*.jpg|bmp|*.bmp|all files|*.*"
If OpenFileDialog1.ShowDialog = System.Windows.Forms.DialogResult.OK Then
Me.picboxprofilepic.Image = System.Drawing.Image.FromFile(OpenFileDialog1.FileName)
txtimagepath.Text = OpenFileDialog1.FileName
End If
End Sub
End Class
Alright, so the program is set up where you have a set of radio buttons with 5 states, and another set of 5 with 5 capitals. There's a button which tells you if they match or not. However I have to do it a certain way where clicking a radio button assigns a variable to both 'strCapital' and 'strChoice' and you compare them to see if they match.
I've tried to figure everything out (since it sounds easy in theory) but I've hit a wall.
Option Explicit On
Option Strict On
Option Infer Off
Public Class frmMain
Dim strCapital As String
Dim strChoice As String
Dim strLittleRock As String
Dim strSpringfield As String
Dim strFrankfort As String
Dim strSalem As String
Dim strMadison As String
Private Sub radArkansas_CheckedChanged(sender As Object, e As EventArgs) Handles radArkansas.CheckedChanged
strCapital = strLittleRock
End Sub
Private Sub radIllinois_CheckedChanged(sender As Object, e As EventArgs) Handles radIllinois.CheckedChanged
strCapital = strSpringfield
End Sub
Private Sub radSpringfield_CheckedChanged(sender As Object, e As EventArgs) Handles radSpringfield.CheckedChanged
strChoice = strSpringfield
End Sub
Private Sub btnVerify_Click(sender As Object, e As EventArgs) Handles btnVerify.Click
If strCapital = strChoice Then
lblMsg.Text = "Correct"
ElseIf strCapital <> strChoice Then
lblMsg.Text = "Incorrect"
End If
End Sub
Private Sub radLittleRock_CheckedChanged(sender As Object, e As EventArgs) Handles
radLittleRock.CheckedChanged
strChoice = strLittleRock
End Sub
End Class
EDIT: Also I forgot to mention the main problem which is always a bad thing. Basically whenever I run it and enter something incorrect (checking Arkansas and Springfield for example) it always says it's correct.
I did something similar... you can modify this code:
Private Sub btnAmIRight_Click(sender As Object, e As EventArgs) Handles btnAmIRight.Click
' displays if submission is correct
' declare variables
Dim strAmIRight As String
Dim dblMatch As Double
If rbtnAlabama.Checked = True And rbtnMontgomery.Checked = True Then
dblMatch = 1
ElseIf rbtnAlaska.Checked = True And rbtnJuneau.Checked = True Then
dblMatch = 1
ElseIf rbtnArizona.Checked = True And rbtnPhoenix.Checked = True Then
dblMatch = 1
ElseIf rbtnArkansas.Checked = True And rbtnLittleRock.Checked = True Then
dblMatch = 1
ElseIf rbtnCalifornia.Checked = True And rbtnSacramento.Checked = True Then
dblMatch = 1
ElseIf rbtnColorado.Checked = True And rbtnDenver.Checked = True Then
dblMatch = 1
ElseIf rbtnConnecticut.Checked = True And rbtnHartford.Checked = True Then
dblMatch = 1
ElseIf rbtnDelaware.Checked = True And rbtnDover.Checked = True Then
dblMatch = 1
ElseIf rbtnFlorida.Checked = True And rbtnTallahassee.Checked = True Then
dblMatch = 1
ElseIf rbtnGeorgia.Checked = True And rbtnAtlanta.Checked = True Then
dblMatch = 1
Else
dblMatch = 0
End If
' assign code to variable
If dblMatch = 1 Then
strAmIRight = "Correct"
ElseIf dblMatch = 0 Then
strAmIRight = "Try Again"
End If
' display result
lblResult.Text = strAmIRight.ToString
End Sub