IfElse with multiple Statements Vb.net - vb.net

How can I use IfElse with multiple Statements to get print different datas if the ComboBox change the item:
For example:
Sub Vesselget()
If vesselcmb.SelectedItem = "Cairebelle Jayde" Then
vesselprint.Text = "CBJ"
ElseIf
vesselcmb.SelectedItem = "Colan James" Then
vesselprint.Text = "CNJ"
ElseIf
vesselcmb.SelectedItem = "Felicity Mackenzie" Then
vesselprint.Text = "FEM"
ElseIf
vesselcmb.SelectedItem = "Lauren Danrya" Then
vesselprint.Text = "LAD"
ElseIf
vesselcmb.SelectedItem = "Mackenzie Maria" Then
vesselprint.Text = "MAM"
ElseIf
vesselcmb.SelectedItem = "Sophia Shay" Then
vesselprint.Text = "SSH"
End If
End Sub

There's a number of ways to do this. If you defined a common data source between the controls, as the combobox selected a different item, this would be reflected in the vesselprint textbox if bound to same datasource. Neater for larger data sets.
If you don't want to use a datasource and prefer to code it all yourself, you can write your first example as:
If vesselcmb.SelectedItem = "Cairebelle Jayde" Then
vesselprint.Text = "CBJ"
ElseIf vesselcmb.SelectedItem = "Colan James" Then
vesselprint.Text = "CNJ"
ElseIf vesselcmb.SelectedItem = "Felicity Mackenzie" Then
vesselprint.Text = "FEM"
ElseIf vesselcmb.SelectedItem = "Lauren Danrya" Then
vesselprint.Text = "LAD"
ElseIf vesselcmb.SelectedItem = "Mackenzie Maria" Then
vesselprint.Text = "MAM"
ElseIf vesselcmb.SelectedItem = "Sophia Shay" Then
vesselprint.Text = "SSH"
End If
So you were nearly there, just lose the line breaks. Or alternatively you could use do this:
Private Function GetVesselPrint(SelectedItem As String) As String
Select Case SelectedItem
Case "Cairebelle Jayde"
Return "CBJ"
Case "Colan James"
Return "CNJ"
Case "Cairebelle Jayde"
Return "CBJ"
Case "Felicity Mackenzie"
Return "FEM"
Case "Lauren Danrya"
Return "LAD"
Case "Mackenzie Maria"
Return "MAM"
Case "Sophia Shay"
Return "SSH"
Case Else
Return Nothing
End Select
End Function
which you would call like this:
vesselprint.Text = GetVesselPrint(vesselcmb.SelectedItem)

So Guys, I used the old methods that I know and fixed my problem. It has been a long time since I programmed in VB.net.
Dim CBJ As String = "CBJ"
Dim CNJ As String = "CNJ"
Dim FEM As String = "FEM"
Dim LAD As String = "LAD"
Dim MAM As String = "MAM"
Dim SSH As String = "SSH"
If vesselcmb.SelectedItem = "Cairebelle Jayde" Then
vesselprint.Text = CBJ
End If
If vesselcmb.SelectedItem = "Colan James" Then
vesselprint.Text = CNJ
End If
If vesselcmb.SelectedItem = "Felicity Mackenzie" Then
vesselprint.Text = FEM
End If
If vesselcmb.SelectedItem = "Lauren Danrya" Then
vesselprint.Text = LAD
End If
If vesselcmb.SelectedItem = "Mackenzie Maria" Then
vesselprint.Text = MAM
End If
If vesselcmb.SelectedItem = "Sophia Shay" Then
vesselprint.Text = SSH
End If

Related

VBA - IF statements with AND not working

Any help would be great. I cant seem to get the ELSEIF with the AND to work.
I am using a user-form. When they press the button the user form appears with check boxes. I am having trouble when both check boxes are checked. individually they work fine,
I am not sure what i am doing wrong. any help would be greatly appreciated
If Intact.Value = True Then
storDate = Sheets("escalation").Cells(Selection.Row, 2)
storProject = Sheets("escalation").Cells(Selection.Row, 3)
StorBill = Sheets("escalation").Cells(Selection.Row, 4)
storIntact = "Intact"
With objWord.ActiveDocument
.formfields("text2").Result = storDate
.formfields("Text3").Result = storProject
.formfields("Text4").Result = StorBill
.formfields("Text9").Result = storIntact
End With
ElseIf Compugen.Value = True Then
storDate = Sheets("escalation").Cells(Selection.Row, 2)
storProject = Sheets("escalation").Cells(Selection.Row, 3)
StorBill = Sheets("escalation").Cells(Selection.Row, 4)
storCompugen = "Compugen"
With objWord.ActiveDocument
.formfields("text2").Result = storDate
.formfields("Text3").Result = storProject
.formfields("Text4").Result = StorBill
.formfields("Text9").Result = storCompugen
End With
ElseIf Intact.Value And Compugen.Value = True Then
storDate = Sheets("escalation").Cells(Selection.Row, 2)
storProject = Sheets("escalation").Cells(Selection.Row, 3)
StorBill = Sheets("escalation").Cells(Selection.Row, 4)
storIntact = "Intact"
storDate1 = Sheets("escalation").Cells(Selection.Row, 2)
storProject1 = Sheets("escalation").Cells(Selection.Row, 3)
StorBill1 = Sheets("escalation").Cells(Selection.Row, 4)
storCompugen = "Compugen"
With objWord.ActiveDocument
.formfields("text2").Result = storDate
.formfields("Text3").Result = storProject
.formfields("Text4").Result = StorBill
.formfields("Text9").Result = storIntact
.formfields("text5").Result = storDate1
.formfields("Text6").Result = storProject1
.formfields("Text7").Result = StorBill1
.formfields("Text8").Result = storCompugen
End With
End If
Thanks in advance
Try changing the order. Otherwise as soon as one condition is met the If clause is exited.
If Intact.Value And Compugen.Value Then
'code
ElseIf Intact.Value Then
'code
ElseIf Compugen.Value Then
'code
End If
If Intact.Value = True is true then the first, not the third block will run.
Similarly if Intact.Value = True is not true and Compugen.Value = True is true, then the second block will run.
So you can see that the third block is not reachable.
The solution is to put the Intact.Value = True And Compugen.Value = True case first in the group.
Finally, Foo.Value = True is a tautology of the simpler Foo.Value. You can drop all the explicit = True comparisons.

Save in excel from visual basic studio

I need to save from Visual Studio 2015 in Excel, the routine I have currently works for me but does not save the information as required, ie every time I press the save button you must add the information one underneath the other, which makes the code Is simply replacing the cell that was previously saved. Copy the code I use to save. I hope you can help me.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.add
oSheet = oBook.WorkSheets(1)
oSheet.Range("A9").Value = "Supply Ducts"
oSheet. Range("C5:E5"). Merge(True)
oSheet. Range("A5:B5"). Merge(True)
oSheet.Range("A5").Value = "Project Name:"
oSheet. Range("C6:E6"). Merge(True)
oSheet. Range("A6:B6"). Merge(True)
oSheet.Range("A6").Value = "Engineering Name:"
oSheet. Range("C7:E7"). Merge(True)
oSheet. Range("A7:B7"). Merge(True)
oSheet.Range("A7").Value = "Company Name:"
oSheet.Range("A10").Value = "tramo"
oSheet.Range("B10").Value = "Caudal de Diseño PCM"
oSheet.Range("C10").Value = "Velocidad de Diseño pie/min"
oSheet.Range("D10").Value = "Factor de Fricción"
oSheet.Range("E10").Value = "Diámetro Equivalente in"
oSheet.Range("F10").Value = "Alto del Ducto in"
oSheet.Range("G10").Value = "Ancho del Ducto in"
oSheet.Range("H10").Value = "Longitud del Ducto mts"
oSheet.Range("I10").Value = "Longitud del Ducto Equivalente ft"
oSheet.Range("J10").Value = "Espesor"
oSheet.Range("K10").Value = "Calibre"
oSheet.Range("L10").Value = "Kg Ductos"
oSheet.Range("M10").Value = "M2 Aislante"
oSheet.Range("N10").Value = "Delpa P in.c.a."
oSheet.Range("A09").End(XlDirection.xlDown).Offset(1, 0) = Tramo
oSheet.Range("B09").End(XlDirection.xlDown).Offset(1, 0) = Qdiseño
oSheet.Range("C09").End(XlDirection.xlDown).Offset(1, 0) = Velocidad2
oSheet.Range("D09").End(XlDirection.xlDown).Offset(1, 0) = FactorFriccion
oSheet.Range("E09").End(XlDirection.xlDown).Offset(1, 0) = Diameduct
oSheet.Range("F09").End(XlDirection.xlDown).Offset(1, 0) = Larcduct
oSheet.Range("G09").End(XlDirection.xlDown).Offset(1, 0) = Anchduct
oSheet.Range("H09").End(XlDirection.xlDown).Offset(1, 0) = Longducto
oSheet.Range("I90").End(XlDirection.xlDown).Offset(1, 0) = (Longducto * 3.28084)
oSheet.Range("J90").End(XlDirection.xlDown).Offset(1, 0) = espesor
oSheet.Range("K09").End(XlDirection.xlDown).Offset(1, 0) = calibre
oSheet.Range("L09").End(XlDirection.xlDown).Offset(1, 0) = (Anchduct + Larcduct) * espesor * Longducto * 11.64
oSheet.Range("M09").End(XlDirection.xlDown).Offset(1, 0) = (Anchduct + Larcduct + 4) * Longducto * 0.1016
oSheet.Range("N09").End(XlDirection.xlDown).Offset(1, 0) = ((Longducto * 3.28084 * FactorFriccion) / 100) * 1.05
oExcel.Visible = True
oExcel.UserControl = True
oBook.SaveAs(Environ("UserProfile") & "\desktop\Ductos1.xls")
End Sub

Error code "Can't finde project or library" in vba

I'm making a vba project with some userforms. I want the people to click the macro button, then need to choose their initials, then by togglebutton click the weeks they want to go on holiday and then click transfer. So far i've done, that if they click one their initials, the value will be printed to a cell. The next userform (userform2), will need to look for the value, to determin wich row the values will be printed in.
But i get an error, on my Select case code.
Private Sub CommandButton1_Click()
Dim score As Integer, result As String
score = ActiveSheet.Range("A19").Value
Select Case score
Case Is = "CTK"
result = Something
Case Is = "MogM"
result = Something1
Case Is = "KSJI"
result = Something2
Case Is = "TSLR"
result = Something3
Case Is = "JOHQ"
result = Something4
Case Is = "OLGJ"
result = Something5
Case Is = "CBJN"
result = Something6
Case Is = "JVLK"
result = Something7
Case Is = "JFP"
result = Something8
Case Is = "EVAD"
result = Something9
Case Is = "TKUP"
result = Something10
Case Else
MsgBox ("Didn't find anyone with these init")
Range("A20").Value = result
End Select
End Sub
Private Sub ToggleButton1_Click()
End Sub
I solved the coding, but now i got a new question. Is it possible to simplify it?
Private Sub CommandButton1_Click()
Dim score As Integer, result As String
score = ActiveSheet.Range("A19").Value
Select Case score
Case Is = "1"
result = "CTK"
Case Is = "2"
result = "MogM"
Case Is = "3"
result = "KSJI"
Case Is = "4"
result = "TSLR"
Case Is = "5"
result = "JOHQ"
Case Is = "6"
result = "OLGJ"
Case Is = "7"
result = "CBJN"
Case Is = "8"
result = "JVLK"
Case Is = "9"
result = "JFP"
Case Is = "10"
result = "EVAD"
Case Is = "11"
result = "TKUP"
Case Else
MsgBox ("Didn't find anyone with these init")
End Select
Range("A20").Value = result
'CTK opportunities
If result = "CTK" And ToggleButton1 = True Then Range("B4").Value = "X"
If result = "CTK" And ToggleButton2 = True Then Range("C4").Value = "X"
If result = "CTK" And ToggleButton3 = True Then Range("D4").Value = "X"
If result = "CTK" And ToggleButton4 = True Then Range("E4").Value = "X"
If result = "CTK" And ToggleButton5 = True Then Range("F4").Value = "X"
If result = "CTK" And ToggleButton6 = True Then Range("G4").Value = "X"
If result = "CTK" And ToggleButton7 = True Then Range("H4").Value = "X"
If result = "CTK" And ToggleButton8 = True Then Range("I4").Value = "X"
If result = "CTK" And ToggleButton9 = True Then Range("J4").Value = "X"
If result = "CTK" And ToggleButton10 = True Then Range("K4").Value = "X"
If result = "CTK" And ToggleButton11 = True Then Range("L4").Value = "X"
If result = "CTK" And ToggleButton12 = True Then Range("M4").Value = "X"
'Next person
Unload Me
End Sub

how to get picture from database to picture box by using textbox lost focus

Private Sub tunjukrekod()
Dim cn As MySqlConnection = New MySqlConnection()
cn.ConnectionString = ("server=localhost; userid=root; password=; database=payrollsystemdb;")
cn.Open()
cmd.Connection = cn
Try
If TextBoxEmployeeID.Text <> "" Then
dt.Clear()
cmd = New MySqlCommand("select * from employeedetail where EmployeeID='" & TextBoxEmployeeID.Text & "'", cn)
da = New MySqlDataAdapter(cmd)
da.Fill(dt)
TextBoxEmployeeID.Text = dt.Rows(0).Item(0)
TextBoxEmployeeName.Text = dt.Rows(0).Item(1)
TextBoxChineseName.Text = dt.Rows(0).Item(2)
If dt.Rows(0).Item(3) = "Active" Then
RadioButtonActiveStatus.Checked = True
ElseIf dt.Rows(0).Item(3) = "Inactive" Then
RadioButtonInactiveStatus.Checked = True
End If
TextBoxbranchID.Text = dt.Rows(0).Item(4)
TextBoxAccessLevel.Text = dt.Rows(0).Item(5)
RichTextBoxAddress.Text = dt.Rows(0).Item(6)
TextBoxTel1.Text = dt.Rows(0).Item(7)
TextBoxTel2.Text = dt.Rows(0).Item(8)
TextBoxMobile.Text = dt.Rows(0).Item(9)
TextBoxEmail.Text = dt.Rows(0).Item(10)
TextBoxICNew.Text = dt.Rows(0).Item(11)
TextBoxICOld.Text = dt.Rows(0).Item(12)
TextBoxPassport.Text = dt.Rows(0).Item(13)
DateTimePickerpassportexpire.Value = dt.Rows(0).Item(14)
TextBoxPermit.Text = dt.Rows(0).Item(15)
DateTimePickerpermitexpire.Value = dt.Rows(0).Item(16)
DateTimePickerBirthDate.Value = dt.Rows(0).Item(17)
TextBoxreligionPD.Text = dt.Rows(0).Item(18)
TextBoxAge.Text = dt.Rows(0).Item(19)
TextBoxracePD.Text = dt.Rows(0).Item(20)
TextBoxcitizenshipPD.Text = dt.Rows(0).Item(21)
TextBoxsexPD.Text = dt.Rows(0).Item(22)
TextBoxmaritalPD.Text = dt.Rows(0).Item(23)
If dt.Rows(0).Item(24) = "yes" Then
RadioButtonyesC.Checked = True
ElseIf dt.Rows(0).Item(24) = "No" Then
RadioButtonnoC.Checked = True
End If
If dt.Rows(0).Item(25) = "yes" Then
RadioButtonYesEOT.Checked = True
ElseIf dt.Rows(0).Item(25) = "No" Then
RadioButtonnoEOT.Checked = True
End If
TextBoxNameSpouse.Text = dt.Rows(0).Item(26)
TextBoxICNewSpouse.Text = dt.Rows(0).Item(27)
TextBoxICOldSpouse.Text = dt.Rows(0).Item(28)
RichTextBoxAddressSpouse.Text = dt.Rows(0).Item(29)
TextBoxIncomeSpouse.Text = dt.Rows(0).Item(30)
TextBoxBranchSpouse.Text = dt.Rows(0).Item(31)
If dt.Rows(0).Item(32) = "yes" Then
RadioButtonyesworking.Checked = True
ElseIf dt.Rows(0).Item(32) = "No" Then
RadioButtonNoworking.Checked = True
End If
TextBoxChildrenSpouse.Text = dt.Rows(0).Item(33)
If dt.Rows(0).Item(34) = "Auto" Then
RadioButtonAutoAuMaSpouse.Checked = True
ElseIf dt.Rows(0).Item(34) = "Manual" Then
RadioButtonManualAuMaSpouse.Checked = True
End If
TextBoxpositionED.Text = dt.Rows(0).Item(35)
TextBoxdepartmentED.Text = dt.Rows(0).Item(36)
TextBoxdivisionED.Text = dt.Rows(0).Item(37)
TextBoxsectionED.Text = dt.Rows(0).Item(38)
TextBoxlocationED.Text = dt.Rows(0).Item(39)
TextBoxgradeED.Text = dt.Rows(0).Item(40)
TextBoxcategoryED.Text = dt.Rows(0).Item(41)
TextBoxworkgroupED.Text = dt.Rows(0).Item(42)
TextBoxformularateED.Text = dt.Rows(0).Item(43)
DateTimePickerjoindateED.Value = dt.Rows(0).Item(44)
DateTimePickerconfirmdateED.Value = dt.Rows(0).Item(45)
DateTimePickerresigneddateED.Value = dt.Rows(0).Item(46)
TextBoxacbankED.Text = dt.Rows(0).Item(47)
If dt.Rows(0).Item(48) = "IC New" Then
RadioButtonICNewACBank.Checked = True
ElseIf dt.Rows(0).Item(48) = "IC Old" Then
RadioButtonICOldACBank.Checked = True
ElseIf dt.Rows(0).Item(48) = "Passport No" Then
RadioButtonPassportNoACBank.Checked = True
ElseIf dt.Rows(0).Item(48) = "Permit No" Then
RadioButtonPermitNoACBank.Checked = True
End If
TextBoxACNoED.Text = dt.Rows(0).Item(49)
TextBoxHRDFundED.Text = dt.Rows(0).Item(50)
If dt.Rows(0).Item(51) = "IC New" Then
RadioButtonICNewHRDFund.Checked = True
ElseIf dt.Rows(0).Item(51) = "IC Old" Then
RadioButtonICOldHRDFund.Checked = True
ElseIf dt.Rows(0).Item(51) = "Passport No" Then
RadioButtonPassportNoHRDFund.Checked = True
ElseIf dt.Rows(0).Item(51) = "Permit No" Then
RadioButtonPermitNoHRDFund.Checked = True
End If
TextBoxProbationED.Text = dt.Rows(0).Item(52)
TextBoxSalaryED.Text = dt.Rows(0).Item(53)
TextBoxNoticeResignED.Text = dt.Rows(0).Item(54)
TextBoxEmployerNamePE.Text = dt.Rows(0).Item(55)
RichTextBoxAddressPE.Text = dt.Rows(0).Item(56)
TextBoxTelNo1PE.Text = dt.Rows(0).Item(57)
TextBoxTelNo2PE.Text = dt.Rows(0).Item(58)
TextBoxFaxPE.Text = dt.Rows(0).Item(59)
TextBoxPICPE.Text = dt.Rows(0).Item(60)
TextBoxPositionPE.Text = dt.Rows(0).Item(61)
DateTimePickerdatejoinPE.Value = dt.Rows(0).Item(62)
TextBoxSalaryPE.Text = dt.Rows(0).Item(63)
DateTimePickerdateresignPE.Value = dt.Rows(0).Item(64)
TextBoxReasonPE.Text = dt.Rows(0).Item(65)
TextBoxEPFNoGD.Text = dt.Rows(0).Item(66)
If dt.Rows(0).Item(67) = "IC New" Then
RadioButtonICNewICTypeEPFGD.Checked = True
ElseIf dt.Rows(0).Item(67) = "IC Old" Then
RadioButtonICOldICTypeEPFGD.Checked = True
ElseIf dt.Rows(0).Item(67) = "Passport No" Then
RadioButtonPassportNoICTypeEPFGD.Checked = True
ElseIf dt.Rows(0).Item(67) = "Permit No" Then
RadioButtonPermitNoICTypeEPFGD.Checked = True
End If
TextBoxInitialGD.Text = dt.Rows(0).Item(68)
TextBoxNKGD.Text = dt.Rows(0).Item(69)
TextBoxepftableGD.Text = dt.Rows(0).Item(70)
TextBoxkwspGD.Text = dt.Rows(0).Item(71)
TextBoxIncomeTaxGD.Text = dt.Rows(0).Item(72)
If dt.Rows(0).Item(73) = "IC New" Then
RadioButtonICNewICTypeIncomeGD.Checked = True
ElseIf dt.Rows(0).Item(73) = "IC Old" Then
RadioButtonICOldICTypeIncomeGD.Checked = True
ElseIf dt.Rows(0).Item(73) = "Passport No" Then
RadioButtonPassportNoICTypeIncomeGD.Checked = True
ElseIf dt.Rows(0).Item(73) = "Permit No" Then
RadioButtonPermitNoICTypeIncomeGD.Checked = True
End If
TextBoxbranchincomeGD.Text = dt.Rows(0).Item(74)
TextBoxpcbcodeGD.Text = dt.Rows(0).Item(75)
TextBoxincometaxdeptGD.Text = dt.Rows(0).Item(76)
TextBoxSocsoNoGD.Text = dt.Rows(0).Item(77)
If dt.Rows(0).Item(78) = "IC New" Then
RadioButtonICNewICTypeSocsoGD.Checked = True
ElseIf dt.Rows(0).Item(78) = "IC Old" Then
RadioButtonICOldICTypeSocsoGD.Checked = True
ElseIf dt.Rows(0).Item(78) = "Passport No" Then
RadioButtonPassportNoICTypeSocsoGD.Checked = True
ElseIf dt.Rows(0).Item(78) = "Permit No" Then
RadioButtonPermitNoICTypeSocsoGD.Checked = True
End If
TextBoxBranchSocsoGD.Text = dt.Rows(0).Item(79)
TextBoxSocsoOfficeGD.Text = dt.Rows(0).Item(80)
TextBoxsocsotypeGD.Text = dt.Rows(0).Item(81)
TextBoxboardofsocsoGD.Text = dt.Rows(0).Item(82)
TextBoxTHAccGD.Text = dt.Rows(0).Item(83)
If dt.Rows(0).Item(84) = "IC New" Then
RadioButtonICNewICTypeTHGD.Checked = True
ElseIf dt.Rows(0).Item(84) = "IC Old" Then
RadioButtonICOldICTypeTHGD.Checked = True
ElseIf dt.Rows(0).Item(84) = "Passport No" Then
RadioButtonPassportNoICTypeTHGD.Checked = True
ElseIf dt.Rows(0).Item(84) = "Permit No" Then
RadioButtonPermitNoICTypeTHGD.Checked = True
End If
TextBoxthcGD.Text = dt.Rows(0).Item(85)
'Dim ms As New MemoryStream(changephoto(CInt(khaiEDForm2.DataGridViewfind.SelectedCells(0).Value)))
'PictureBox1.Image = Image.FromStream(ms)
cmd = New MySqlCommand("select * from salarydetail", cn)
da.SelectCommand = cmd
da.Fill(dtsalary)
End If
Catch ex As Exception
'TextBoxEmployeeName.Focus()
End Try
End Sub
'Function changephoto(ByVal photo As Integer) As Byte()
' Dim cn As MySqlConnection = New MySqlConnection()
' cn.ConnectionString = ("server=localhost; userid=root; password=; database=payrollsystemdb;")
' cn.Open()
' '.CommandText = System.Data.CommandType.Text
' With cmd
' .Connection = cn
' .CommandText = "SELECT Imageblob FROM employeedetail WHERE EmployeeID=" & khaiEDForm2.DataGridViewfind.SelectedRows(0).Cells(0).Value
' End With
' Dim myphoto() As Byte = CType(cmd.ExecuteScalar(), Byte())
' cn.Close()
' Return myphoto
'End Function
Private Sub TextBoxEmployeeID_LostFocus(sender As Object, e As EventArgs) Handles TextBoxEmployeeID.LostFocus
If TextBoxEmployeeID.Text = "" Then
TextBoxEmployeeID.Select()
Else
tunjukrekod()
tunjukdgv()
End If
addrow()
End Sub
How I Can Rewrite the code? because the code cam retrive picture only when from form2 to form1.
I used visual studio express 2014, MySQL Database using PHPMYADMIN, MySQLConnection.
ok . i got the solution ! finally !
dr = cmd.ExecuteReader()
If (dr.HasRows) Then
While (dr.Read())
With Me
'fetch image from database
Dim imgBytes() As Byte = dr("Imageblob") 'image field
Dim image As Bitmap = New Bitmap(New System.IO.MemoryStream(imgBytes)) 'convert binary to image
.PictureBox1.Image = image 'show picture to picture box
End With
End While
Else
MsgBox("No records Found!")
End If

Read, Get, Compare and Count Rows from GridView VB.net?

i have a little problem and actually i can't get out from his.. I have a column called 'Periodicidade' that gives me how many times must a thing get done.
What i want to do is a validation that it will count how many times exists one of them, and if one of them have the radiobutton fill, it will force the user to fill the others of the same type of periocidade, but in the moment he is counting the total gridview rows, and not the type of same periodicidade. My current code is:
Dim todos_items_periocidade_vazios As Boolean = True
Dim todos_items_periocidade_preenchidos As Boolean = False
Dim periocidade_validada As Boolean = False
'quantas linhas tem a grid
Dim n_linha_grid As Integer = GridView_Manutencao.Rows.Count
Dim periocidade_linha As String
Dim contador_preenchido As Integer = 0
Dim contador_linhas As Integer = 0
'para cada linha verificar
For Each row2 As GridViewRow In GridView_Manutencao.Rows
'percorrer tabela e validar a periocidade da linha encontrada
periocidade_linha = (CType(row2.FindControl("Label_Periodicidade"), Label).Text)
For Each row As GridViewRow In GridView_Manutencao.Rows
If ((CType(row.FindControl("Label_Periodicidade"), Label).Text) = periocidade_linha) Then
contador_linhas = contador_linhas + 1
periocidade_validada = True
If periocidade_validada = True Then
'testar se está vazio ou preenchido
If (CType(row.FindControl("RBList"), RadioButtonList).SelectedValue = "") Then
'percorrer a tabela e verificar se todos os itens estão vazios ou não
For Each row1 As GridViewRow In GridView_Manutencao.Rows
If ((CType(row1.FindControl("Label_Periodicidade"), Label).Text) = periocidade_linha) Then
If (CType(row1.FindControl("RBList"), RadioButtonList).SelectedValue = "") Then
todos_items_periocidade_vazios = True
Else
todos_items_periocidade_vazios = False
End If
End If
Next
Else
For Each row1 As GridViewRow In GridView_Manutencao.Rows
If ((CType(row1.FindControl("Label_Periodicidade"), Label).Text) = periocidade_linha) Then
If (CType(row1.FindControl("RBList"), RadioButtonList).SelectedValue <> "") Then
contador_preenchido = contador_preenchido + 1
todos_items_periocidade_preenchidos = True
Else
todos_items_periocidade_preenchidos = False
End If
End If
Next
End If
End If
End If
Next
valida_comentario()
If contador_preenchido = 0 Then
periocidade_validada = False
tudo_validado = False
ElseIf contador_preenchido < contador_linhas Then
periocidade_validada = False
tudo_validado = False
Else
If valida_comentario() = True Then
If ((todos_items_periocidade_vazios = True) And (todos_items_periocidade_preenchidos = True)) Then
periocidade_validada = True
tudo_validado = True
Lbl_Mensagem.Text = "Registo inserido com sucesso!"
ElseIf ((todos_items_periocidade_vazios = False) And (todos_items_periocidade_preenchidos = True)) Then
periocidade_validada = True
tudo_validado = True
Lbl_Mensagem.Text = "Registo inserido com sucesso!"
Else
periocidade_validada = False
tudo_validado = False
Lbl_Mensagem.Text = "Erro"
End If
Else
tudo_validado = False
periocidade_validada = False
Lbl_Mensagem.Text = "Erro"
End If
End If
Next
Return periocidade_validada
I got the answer, hope to be useful to all of you, thanks, here it goes:
Dim texto_periodicidade As String
Dim valor As String
Dim flag_validacao As Boolean = False
Dim contador_falso As Integer
contador_falso = 0
For Each linha As GridViewRow In GridView_Manutencao.Rows
texto_periodicidade = CType(linha.FindControl("Label_Periodicidade"), Label).Text
valor = CType(linha.FindControl("RBList"), RadioButtonList).SelectedValue
For Each row As GridViewRow In GridView_Manutencao.Rows
If (texto_periodicidade = CType(row.FindControl("Label_Periodicidade"), Label).Text) Then
If (valor = CType(row.FindControl("RBList"), RadioButtonList).SelectedValue) Then
flag_validacao = True
Else
contador_falso = contador_falso + 1
flag_validacao = False
End If
End If
Next row
Next linha
If contador_falso > 0 Then
Lbl_Mensagem.Text = "Complete os restantes valores da periocidade!"
contador_falso = 0
Return False
Else
If valida_comentario() = True Then
contador_falso = 0
Return True
End If
End If