Begginnerdev 256 Junior Poster

You can do a mass uncheck by looping through the form for each checkbox:

For Each cb As CheckBox in Me.Controls
    cb.Checked = False
Next

I think this is what you are wanting?

Begginnerdev 256 Junior Poster

Do you have any code in the CheckBox_CheckChanged event?

Do you have a sub procedure called CheckBox1_CheckChanged that handles the CheckChanged event of the checkbox?

It is possible that something else is checking that checkbox.

Is the checkbox a custom control that has been extended from the CheckBox control?

Begginnerdev 256 Junior Poster

It would depend on the database you are using. (Looks like Access)

Data.SQLClient is microsoft's library for Access and SQLServer.

You can use OLEDB or one of numereous others.

Begginnerdev 256 Junior Poster

Something like:

"SELECT MAX(ColumnName) As MaxValue From Table "

Then pass that query to a datatable and pull into a textbox

Dim da As New SQLDataAdapter("SELECT MAX(ColumnName) As MaxValue From Table ",MySQLConnection)
Dim ds As New DataSet

da.fill(ds,"Max")

If Not IsNothing(ds.Tables("Max")) And ds.Tables("Max").Rows.Count > 0 Then
    TextBox1.Text = ds.Tables("Max").Rows(0)("MaxValue")
End If
Begginnerdev 256 Junior Poster

It would be easier to do a SELECT with an inner join.

Something like:

"SELECT SEGDATA.AdminNo, Paperslist.PaperNo InnerJoin SEGDATA on PapersList.Module1 = SEGDATA.ModuleCode"

But my SQL is a little lacking

I hope this points you in the right direction.

Reverend Jim commented: Nothing lacking there. +12
Begginnerdev 256 Junior Poster

Simply place the following code in your clear or insert command.

MyCheckBox.Checked = False

But note that this will fire any CheckChanged event handler for that CheckBox.

Begginnerdev 256 Junior Poster

You can parse the last six characters of the string to get the last six.

Just parse the selected item, or parse when the item is being inserted into the combobox.

For example:

Private Sub LoadData(ByVal lstString As List(Of String))
    Try
        For Each s As String In lstString
            ComboBox1.Items.Add(s)

            'You can parse here for reference before the selected index change.
            'dicLastSix is a Dictionary(Of String, String)
            'This will give you a reference before the item is selected in the cobobox/
             dicLastSix.Add(s, GetLastSix(s))
        Next
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub

Private Function GetLastSix(ByVal str As String) As String
    'Modify this function to return what you want in the case of an exception being thrown.
    Try
        If str.Length - 7 > 0 Then '0 index have to subtract 7 for 6 items
            Return str.IndexOf(str, str.Length - 7, str.Length - 1)
        Else
            Return str.IndexOf(str, 0, str.Length - 1)
        End If
    Catch ex As Exception
        MsgBox(ex.ToString)
        Return String.Empty
    End Try
End Function

Private Sub IndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ComboBox1.SelectedIndexChanged
    Try
        'Geting the last 6 from caling the function
        If Not IsNothing(TryCast(sender, ComboBox)) Then
            Dim s As String = CStr(TryCast(sender, ComboBox).SelectedItem)
            MsgBox("Last Six: " & GetLastSix(s))
        End If
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub
Begginnerdev 256 Junior Poster

If you know the type of data that is being stored in the datagridviews, just simply declare that type of list:

    'If Data is a String
 Dim myList As New List(Of String)
    'If Data is a integer
 Dim myList As New List(Of Integer)

 mylist.Add(DataGridView2.Rows(z).Cells(0).Value)
 mylist.Add(DataGridView1.Rows(i).Cells(0).Value)
 mylist.Add(DataGridView1.Rows(i).Cells(1).Value)

Then enumerate through the list!

For Each s As String in myList
    'Do Work
Next

For Each i As Integer in myList
    'Do Work
Next
Begginnerdev 256 Junior Poster

Have you verified the logic of the select?

I see (1) AND (2) OR (3) OR (4)

If this statement gets qualified, you can have a maximum of 3 outcomes.

(1) and (2) are true
(3) is true
(4) is true

Is this correct?

Begginnerdev 256 Junior Poster

I have checked to see if the code was simply setting a flag beforehand. To my astonishment it is deleting the record and nothing else!

I am starting to think that the application is possessed by the evil MS Casper.

Anyone know the number to the Ghost Busters?

Begginnerdev 256 Junior Poster

Hello my fellow Daniwebies!

I have a curious, possibly unique, and odd problem for everyone!

We support an ASP.NET application which is using VB.NET for code behind.
We use LINQ to SQL and classed object for the data retreival.

I have an object called...myObject which is being deleted:

Public Shared Sub Delete(ByVal moIn As myObject)
    Try
       Dim db As New DataBaseDataContext()

       db.myTable.Attach(myObject)
       db.myTable.DeleteOnSubmit(myObject)
       db.SubmitChanges()

       db = Nothing
    Catch ex As Exception
        Throw ex 'Exception is handled on front end
    End
End Sub

The code fires successfully and the object is 'deleted'.

Here is the odd thing: When checking from SQL Server, the deleted row is still in the database BUT not inside the application.

In other words; The object is deleted locally and never retreived - even if the application is restarted.

What in the world is going on here?

Begginnerdev 256 Junior Poster

If you are storing large amounts of data, which it looks like you are, I suggest a database backend.

A table for students, classes and a junction table:

tblClasses
ID | Class | Comments
Auto | VarChar | VarChar

tblStudents
ID | Name | StudentNumber
Auto | VarChar | VarChar

tblLink
ID | tblStudent_ID | tblClassesID
Auto| Integer (FK) | Integer (FK)

Classes will look like:

0,SEG-AMK EG1832 Mechanics and Materials 286 1.5,EG1832
1,SEG-AMK EG1833 Electrical Principles 375 1.5,EG1833 EG1952 EG1903

Students will look like:

0,John Doe, 130019K
1,Woody Woodpecker,130020D

Your Junction Table will look like

0,1,0 - Woody is taking Mechanics and Materals 286
0,1,1 - Woody is taking Electrical Principles 375
0,0,0 - John is taking Mechanics and Materials 286

Begginnerdev 256 Junior Poster

Are you wanting to remove the row from the created table, or from the atomic tables?

Begginnerdev 256 Junior Poster

You will have to set the name of the button, or loop through the forms controls:

NT.Name="MyButton1"

Or

For Each m As MyButton in Me.Controls
    m.Dispose 'NOTE: m MUST INHERIT CONTROL
Next
Begginnerdev 256 Junior Poster

Some questions before code can be written:

Do both gridviews contain the same row count for data?

Have you tried reading in from both csv files, concatinating them together for the third gridview?

Is it possible that you are placing more controls on the form than are needed? (See question 2)

Begginnerdev 256 Junior Poster

One question would be - What differs from test data to live data.

Does the data format change, or just values?

Begginnerdev 256 Junior Poster

Using Dispose() waits for the garbage collector service.

You can simply write:

cmd = Nothing

And the object will be destroyed.

Begginnerdev 256 Junior Poster

Don't forget to mark as solved!

Begginnerdev 256 Junior Poster

One thing to take into consideration in packet loss /size of image.

If there is a large amount of packet loss between you and the site - the quality will suffer greatly.

If the size of your picturebox is smaller/larger than the original image there will be stretching or pinching. This causes pixelation.

Begginnerdev 256 Junior Poster

You can try something like this:

Private Sub Button_Click(byval sender as Object, byval e As Eventargs)
    Try
    For Each t As TextBox In Me.Controls
        If t.Name ="txtAdd1" or "txtAdd2" Then
            MsgBox("TextBox Value:" & t.Text & vbCrLF & "TextBox Name:" & t.Name & vbCrLf & "Button Name:" & Cstr(TryCast(sender,Button).Name))
        End If
    Next
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub

This will find either of the textboxes, get the values, and the name of the button that you pressed.

Begginnerdev 256 Junior Poster

You need to create an action lister (event handler) for the button click.

For example:

Private Sub Button_Click(byval sender as Object, byval e As Eventargs)
    Try
         'Place your code here to find the textbox
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub

Add the handler to the button before adding it to the form.

AddHandler Buttonadd5.click, AddressOf Button_Click

This will fire an event handler for when user presses the button.

Begginnerdev 256 Junior Poster

Is the code throwing an exceptions?

From a first glace perspective, we can't tell if it has errors or not.

Have you looked into Try/Catch blocks?

Place your code in them and give a MsgBox for output:

Try
    'Paste your code here
Catch ex As Exception
    MsgBox(ex.ToString)
End Try
Begginnerdev 256 Junior Poster

Not knowing =/= Laziness.

It is a good thing that you are willing to learn!

Begginnerdev 256 Junior Poster

You could take that string returned, split and parse it to what you need.

For example:

Private Function ParseIngredients(ByVal strIngredients As String) As Dictionary(Of String, Double)
    Try
        strIngredients = "(Water (20), Salt(30))" 'When passing the value in delete this, this is just for example.
        Dim dic As New Dictionary(Of String, Double)

        Dim lstIngredients As List(Of String) = strIngredients.Split(",").ToList()
        'lstIngredients(0) = "(Water (20)"
        'lstIngredients(1) = "Salt (30))"

        For Each s As String In lstIngredients

            Dim Key As String = String.Empty
            Dim Value As Double = 0.0
            s = s.Replace("(", "") 'Will return "Water 20)"
            s = s.Replace(")", "") 'Will return "Water 20"

            Key = s.Split(" ").ToList(0) ' Will return Water
            Value = Cdbl(s.Split(" ").ToList(1)) 'Will return 20.0 as Double
            'The key will be set to Water
            'The value will be set to 20

            'Add to dictionary
            dic.Add(Key, Value)
        Next

        Return dic
    Catch ex As Exception
        MsgBox(ex.ToString)
        Return New Dictionary(Of String, Double)
    End Try
End Function

Just pass in the ingredients string and accept the output dictionary.

Iterating through the dictionary can be done as follows:

For Each kvp As KeyValuePair(Of String,Double) In ParseIngredients(IngredientsStringHere)
    DeductFromTotal(kvp.Key,kvp.Value)
Next

I hope this helps!

ddanbe commented: Helpfull +14
Begginnerdev 256 Junior Poster

Place the code in a sub procedure and pass in the item type for the action:

Private Sub DeductFromTotal(ByVal sItemType As String,ByVal dblAmountToSubtract As Double)
    Try
        Dim da As New MySqlDataAdapter(New MySqlCommand("SELECT * FROM Inventory WHERE Item='" & Me.ComboBox1.Text & "'", New MySQLConnection("ConnectionStringHere")) 
        'You don't have to open the connection before using it in the adapter.'
        'The select gets the table structure.'

        Dim ds As New DataSet
        da.Fill(ds, "Inventory")
        If Not IsNothing(ds.Tables("Inventory")) And ds.Tables("Inventory").Rows.Count > 0 Then
            Dim dblCurrentAmount As Double = CDbl(ds.Tables("Inventory").Rows(0)("Amount")) - dblAmountToSubtract '(This dblAmountToSubtract is not declared, what should it be set to?)
            If dblCurrentAmount < 0 Then
                MsgBox("You have used more than what is in stock!" & vbCrLf & "This operation will not be completed", MsgBoxStyle.Exclamation, "ERROR!")
                GoTo DISPOSE
            ElseIf dblCurrentAmount = 0 Then
                MsgBox("You have depleted your stock for this item!" & vbCrLf & "Please restock this item!", MsgBoxStyle.Exclamation, "Oops!")
            End If

            ds.Tables("Inventory").Rows(0)("Amount") = dblCurrentAmount
            da.UpdateCommand = New MySQLCommandBuilder(da).GetUpdateCommand
            da.Update(ds, "Inventory")
            MsgBox("Item Updated!", MsgBoxStyle.Information, "Complete!")
        End If
DISPOSE:
            da = Nothing
            ds = Nothing
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try      
End Sub

Then call it from code (A button click would work)

Private Sub btnSalad_Click(sender As Object, e As EventArgs) Handles btnSalad.Click
    Try
        'Get list of ingredients from table
            For Each s As String In lstIngredients 'List(Of String)
                DeductFromTotal(s,Cdbl(txtIngredient1.Text))
            Next
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub

This begs the question: How are you binding an ingredient list to the item type?

Are you doing something like this?

…
Begginnerdev 256 Junior Poster

Without using any control the only way would be to draw an image and place the image in the background of the form.

If you do not plan to use the Graphics library then your question has met a dead end. :(

Begginnerdev 256 Junior Poster

dblAmountToSubtract will be a variable declared as double that will hold the value to subtract from your total.

For Example:

Dim dblAmountToSubtract As Double = Cdbl(txtAmountUsed.Text)
'This pulls the amount from a text box on a form.

For the command, you can simply replace:

da.UpdateCommand = New OleDb.OleDbCommandBuilder(da).GetUpdateCommand

With

da.UpdateCommand = New MySQLCommandBuilder(da).GetUpdateCommand
Begginnerdev 256 Junior Poster

You will have to change the column names in the dr("column") with the correct column names.

Begginnerdev 256 Junior Poster

The select statment retreives the record from your database table.

For example:

Inventory
Item  | Amount
garlic,10.21
onion,50.13
water,200.23


"SELECT * FROM Inventory WHERE Item='garlic'" 'Would return garlic,10.21

As for the myConnection, you will need a connection to the database to retreive the data from the database.

In this case, my connection would look as follows:

Dim myConnection As New OleDBConnection("MyConnectionStringHere")

For connection strings, see this website.

I hope this clears things up for you!

savedlema commented: Thanks Begginerdev. Please check my reply. +0
Begginnerdev 256 Junior Poster

Nice and fast here

Begginnerdev 256 Junior Poster

You will have to get the current value, subtract, then update to the newest value.

This is assuming your amount colum in as decimal value.

For Example:

       Try
            Dim da As New OleDbDataAdapter(New OleDbCommand("SELECT * FROM Inventory WHERE Item='" & sItemType & "'", myConnection))

            'The select gets the table structure.
            Dim ds As New DataSet

            da.Fill(ds, "Inventory")

            If Not IsNothing(ds.Tables("Inventory")) And ds.Tables("Inventory").Rows.Count > 0 Then
                Dim dblCurrentAmount As Double = CDbl(ds.Tables("Inventory").Rows(0)("Amount")) - dblAmountToSubtract

                If dblCurrentAmount < 0 Then
                    MsgBox("You have used more than what is in stock!" & vbCrLf & "This operation will not be completed", MsgBoxStyle.Exclamation, "ERROR!")
                    GoTo DISPOSE
                ElseIf dblCurrentAmount = 0 Then
                    MsgBox("You have depleted your stock for this item!" & vbCrLf & "Please restock this item!", MsgBoxStyle.Exclamation, "Oops!")
                End If

                ds.Tables("Inventory").Rows(0)("Amount") = dblCurrentAmount

                da.UpdateCommand = New OleDb.OleDbCommandBuilder(da).GetUpdateCommand
                da.Update(ds, "Inventory")

                MsgBox("Item Updated!", MsgBoxStyle.Information, "Complete!")
            End If
DISPOSE:
            da = Nothing
            ds = Nothing
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try 
Reverend Jim commented: Nice complete answer. +12
savedlema commented: Thanks Begginerdev. Please check my reply. +2
Begginnerdev 256 Junior Poster

Why not use a data adapter?

For example:

       Try
            Dim da As New OleDbDataAdapter(New OleDbCommand("SELECT * FROM Rooms WHERE 1=2", _
                                           New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='C:\PATIENT_O\PATIENT_O\Patient-O.accdb'"))) 

                                           'The select gets the table structure.
            Dim ds As New DataSet

            da.Fill(ds, "Rooms")
            Dim dr As DataRow = ds.Tables("Rooms").Rows.Add()

            'Replace these names with the exact names you have.

            dr("[RoomID]") = IIf(String.IsNullOrEmpty(txtRoomID.Text), DBNull.Value, txtRoomID.Text)
            dr("[First Name]") = IIf(String.IsNullOrEmpty(txtroomFName.Text), DBNull.Value, txtroomFName.Text)
            dr("[Middle Name]") = IIf(String.IsNullOrEmpty(txtroomMName.Text), DBNull.Value, txtroomMName.Text)
            dr("[Last Name]") = IIf(String.IsNullOrEmpty(txtroomLName.Text), DBNull.Value, txtroomLName.Text)
            dr("[Room Type]") = IIf(String.IsNullOrEmpty(txtRoomType.Text), DBNull.Value, txtRoomType.Text)
            dr("[Amt/Day]") = IIf(String.IsNullOrEmpty(txtroomAmount.Text), DBNull.Value, txtroomAmount.Text)
            dr("[Comments]") = IIf(String.IsNullOrEmpty(txtroomComment.Text), DBNull.Value, txtroomComment.Text)

            da.InsertCommand = New OleDb.OleDbCommandBuilder(da).GetInsertCommand
            da.Update(ds, "Rooms")

            da = Nothing
            ds = Nothing
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

My eye catches txtRoomComment.text.

If there is a ' character present in that field, you would have been terminating the sql statement.

DataAdapters protect against this.

Begginnerdev 256 Junior Poster

To do this, you will lose ALL server code and ASP.Net code.

To do this, simply remove all the code above and save as html, or load into a browser > view source > save as doc.html

Begginnerdev 256 Junior Poster

There a couple methods you can use:

PrintForm and PrintDocument

Printform sends an image of the active form to the printer. (Simple output)

PrintDocument sends the output to the printer, but you have to specify the output.

PrintDocument sounds like what you are wanting.

Begginnerdev 256 Junior Poster

Do you have any code in the Form_Closing event?

Begginnerdev 256 Junior Poster

Why do I have the odd feeling this is an assignment.....

Do YOU have any code thus far?

Begginnerdev 256 Junior Poster

There is a (very) old forum post on this exact topic.

The (possible) solution can be found here.

Begginnerdev 256 Junior Poster

This works by first selecting the rows from the table, them storing them into a linq query.

You then cycle through the linq query and add new rows to the duplicates table (Just iterating on objects).

One other thing you can possibly do, is to write a custom class to contain the duplicate and create a list for the duplicates.

For example:

Public Class Duplicates
    Private _ID As Integer = -1
    Private _Field1 As String = String.Empty
    Private _Field2 As String = String.Empty

    Public Property ID As Integer
        Get
            Return Me._ID
        End Get
        Set(value As Integer)
            Me._ID = value
        End Set
    End Property

    Public Property Field1 As String
        Get
            Return Me._Field1
        End Get
        Set(value As String)
            Me._Field1 = value
        End Set
    End Property

     Public Property Field2 As String
        Get
            Return Me._Field2
        End Get
        Set(value As String)
            Me._Field2 = value
        End Set
    End Property

    Public Sub New()
    End Sub

    Public Sub New(ByVal iID as Integer)
        If iID > -1 Then Me.ID = iID
    End Sub

    Public Sub New(ByVal iID as Integer, ByVal sField1 As String)
        If iID > -1 Then Me.ID = iID
        If Not String.IsNullorEmpty(sField1) Then Me.Field1 = sField1
    End Sub

    Public Sub New(ByVal iID as Integer, ByVal sField1 As String, ByVal sField2 As String)
        If iID > -1 Then Me.ID = iID
        If Not String.IsNullorEmpty(sField1) Then Me.Field1 = sField1
        If Not String.IsNullorEmpty(sField2) Then Me.Field2 = sField2
    End Sub

End Class

Then you can iterate through the LINQ query and pass the values to the Duplicates Class:


       
Begginnerdev 256 Junior Poster

I suspect a field length on one of your values you are inserting/updating.

For example:

Dim str As String = "Hello World"

If the length of str is greater than the size of the field (varchar or nvarchar) then you will truncate the data.

Begin by looking at all of the string fields that are being inserted/updated and check those first.

Begginnerdev 256 Junior Poster

The number on the end of each function represents the bit count, therefore, represents the maximum value that can be returned by that function ( as Integer )

Int16 - 16bit
Int32 - 32bit
Int64 - 64bit

As for the decimal places, the ToInt32 function returns an integer, which is a whole number. Therefore the decimal value will be rounded.

Begginnerdev 256 Junior Poster

Here is a small extention of the Panel class that allows you to 'collapse' it.

So far, the user can place a control on the parent form and perform a collapse/expantion by:

'Where cpNew is a Collapsible Panel

If Not cpNew.PanelCollapsed Then cpNew.Collapse()

'or

If cpNew.PanelCollapsed Then cpNew.Expand()

I will be changing/improving the control as much as possible.

If anyone has any suggestions/tips they would greatly be appreciated!

Begginnerdev 256 Junior Poster

You could place a timer on SplashScreen1, then do the following:

DIm ss1 As New SplashScreen1

ss1.ShowDialog() 'Will be a modal window and will not show Form2 Until it is closed.
ss1 = Nothing

Form2.Show()

Now, for the timer bit, in the SplashScreen_Load event place a timer.Start.

Private Sub Me_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    Try
        Timer1.Start()
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub

Now place the closing code in the timer.Tick method.

Private iCount As Integer = 0 'Must store value of timer tick.
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
    iCount += 1
    If iCount = 5000 THen Me.Close
End Sub

This will wait as long as you want, then close the form after the given span. (In this example it is 5 seconds)

Begginnerdev 256 Junior Poster

You could try to create a linq table in your dbml file named 'Duplicate' with the same column names and field lengths.

Then, try to cast the object to the type of Duplicate

Begginnerdev 256 Junior Poster

Why dont you just make use of the splash screen setting in the My Application > Application menu?

8ae345254c4c9bb69e810b0ff6e79a04

ddanbe commented: Good advice! +14
Begginnerdev 256 Junior Poster

What exactly does the exception that is thrown state?

Begginnerdev 256 Junior Poster

It would depend on the circumstance.

If the IT department rejected due to a breach of policy, then it is "illegal".

If they rejected due to not wanting to take care of it (Lazy) you can possible find other methods.

Begginnerdev 256 Junior Poster

As per Community Rules we are a help forum.

Therefore, we can not simply answer questions for you.

We can, however, point you to things to help you learn as Moschops has.

Begginnerdev 256 Junior Poster

EDIT This looks like a quiz question.

Are you asking for help on a quiz/test/homework?

Begginnerdev 256 Junior Poster

Are you using some kind of programming language, or just HTML?

Begginnerdev 256 Junior Poster

Welcome to Daniweb!