Results 1 to 11 of 11

Thread: [RESOLVED] Problem with checkbox & radio buttons...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Location
    Ireland
    Posts
    85

    Resolved [RESOLVED] Problem with checkbox & radio buttons...

    Half the problem solved, but now I need,

    If GlassRadioButton.Checked = True Then
    , well here's where im stuck, I need Glass to get added to a string or something, so it can be called in myAddNew

    ?

    vb.net Code:
    1. "VALUES"
    2. Dim myValue As Integer ' Base value of frames        
    3. Dim myValue1 As Integer ' Glass or plastic value        
    4. Dim myValue2 As Integer ' Scratch Coating value        
    5. Dim myValue3 As Integer ' UV value        
    6. Dim totalCost As Integer ' Total value        
    7. Dim deposit As Integer ' Deposit value, 20% of total        
    8. myValue = 50 'Base value of frames, always 50        
    9. If GlassRadioButton.Checked = True Then            
    10.     myValue1 = 30        
    11. ElseIf
    12.     PlasticRadioButton.Checked = True Then            
    13.     myValue1 = 15        
    14. End If        
    15. If CheckBox1.Checked = True Then            
    16.     myValue2 = 10        
    17. Else            
    18.     myValue2 = 0        
    19. End If        
    20. If CheckBox2.Checked = True Then            
    21.     myValue3 = 15        
    22. Else            
    23.     myValue3 = 0        
    24. End If        
    25. totalCost = myValue + myValue1 + myValue2 + myValue3 'Gets total by adding all values        
    26. deposit = totalCost * 0.2 'Divides total by 0.2 to find the 20% deposit        
    27. TextBox1.Text = totalCost 'Displays total        
    28. TextBox2.Text = deposit 'Displays deposit        
    29. TextBox3.Text = totalCost - deposit 'Subtracts the deposit from total, to find balance        
    30. PrintButton.Enabled = True        
    31. ViewButton.Enabled = True        
    32. myAddNew(8) 'CALLS ADDNEW METHOD WHEN ADD BUTTON IS CLICKED
    Last edited by Kielo; Mar 24th, 2010 at 11:03 AM. Reason: Fixed Highlight Tags

  2. #2
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Problem with checkbox & radio buttons...

    have you set a break point and steped though the code? Set it on the first line myValue = 50 then step though line by line and watch what happens to the different values.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  3. #3
    Fanatic Member Megalith's Avatar
    Join Date
    Oct 2006
    Location
    Secret location in the UK
    Posts
    879

    Re: Problem with checkbox & radio buttons...

    ok redone the OP code so its clearer
    Code:
    Dim myValue As Integer ' Base value of frames        
    Dim myValue1 As Integer ' Glass or plastic value        
    Dim myValue2 As Integer ' Scratch Coating value        
    Dim myValue3 As Integer ' UV value        
    Dim totalCost As Integer ' Total value        
    Dim deposit As Integer ' Deposit value, 20% of total        
    myValue = 50 'Base value of frames, always 50        
    If GlassRadioButton.Checked = True Then            
        myValue2 = 30        
    ElseIf 
        PlasticRadioButton.Checked = True Then            
        myValue2 = 15        
    End If        
    If CheckBox1.Checked = True Then            
        myValue2 = 10        
    Else            
        myValue2 = 0        
    End If        
    If CheckBox2.Checked = True Then            
        myValue3 = 15        
    Else            
        myValue3 = 0        
    End If        
    totalCost = myValue + myValue1 + myValue2 + myValue3 'Gets total by adding all values        
    deposit = totalCost * 0.2 'Divides total by 0.2 to find the 20% deposit        
    TextBox1.Text = totalCost 'Displays total        
    TextBox2.Text = deposit 'Displays deposit        
    TextBox3.Text = totalCost - deposit 'Subtracts the deposit from total, to find balance        
    PrintButton.Enabled = True        
    ViewButton.Enabled = True        
    myAddNew(8) 'CALLS ADDNEW METHOD WHEN ADD BUTTON IS CLICKED
    If debugging is the process of removing bugs, then programming must be the process of putting them in.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Location
    Ireland
    Posts
    85

    Re: Problem with checkbox & radio buttons...

    Figured it, I had myValue2 being used in 2 different places, when it should have been myValue1 for Glass or Plastic...

    Wondering how can I make it now so that these values get saved to use in myAddNew?

    I had it working as GPTextBox and if I typed glass or plastic in, I had it in myAddNew as GPTextBox.Text corrosponding to Material

  5. #5
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Problem with checkbox & radio buttons...

    what is myAddNew a procedure you wrote? What is 8 in the call?
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  6. #6
    Fanatic Member Megalith's Avatar
    Join Date
    Oct 2006
    Location
    Secret location in the UK
    Posts
    879

    Re: Problem with checkbox & radio buttons...

    Okay, for some reason... the Radio button doesn't work when the checkboxes do
    ok well not sure what you mean by not work? is this you click one radio button then when you click another one they both are selected?
    If debugging is the process of removing bugs, then programming must be the process of putting them in.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Location
    Ireland
    Posts
    85

    Re: Problem with checkbox & radio buttons...

    It's working fine now Megalith, my problem was I had a checkbox updating the myValue2 data... and also had a radio button updating it... overlap of error!

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Location
    Ireland
    Posts
    85

    Re: Problem with checkbox & radio buttons...

    Quote Originally Posted by GaryMazzone View Post
    what is myAddNew a procedure you wrote? What is 8 in the call?
    Add Code:
    1. Private Sub myAddNew(ByVal CusRef As Integer)
    2.         Dim ConnectionString As String
    3.         Dim SQLString As String
    4.         Dim whichButtonDialogResult As DialogResult
    5.         Dim dbCommand As System.Data.OleDb.OleDbCommand
    6.         Dim Connection As System.Data.OleDb.OleDbConnection
    7.         ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data "
    8.         ConnectionString += "Source=" & "Opticians.accdb "
    9.         Connection = New System.Data.OleDb.OleDbConnection(ConnectionString)
    10.         SQLString = "INSERT INTO SpecSalesTable (CustomerID, EyeTestID, FrameID, DateOfSale, GlassOrPlastic, ScratchCoating, UVFilter, TotalCost, DepositPaid) "
    11.         SQLString += "Values ('" & CustomerIDTextBox.Text & "','" & EyeTestIDTextBox.Text & "','" & StockTextBox.Text & "',#" & Date.Today & "#,'" & GlassPlasticTextBox.Text & "','" & ScratchTextBox.Text & "','" & UVTextBox.Text & "','" & TextBox1.Text & "','" & TextBox2.Text & "')"
    12.         whichButtonDialogResult = MessageBox.Show("Are You Sure You Want To Place This Order?", "Add Record", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
    13.         If whichButtonDialogResult = DialogResult.Yes Then
    14.             Connection.Open()
    15.             If CBool(ConnectionState.Open) Then
    16.                 dbCommand = New System.Data.OleDb.OleDbCommand(SQLString, Connection)
    17.                 Try
    18.                     dbCommand.ExecuteNonQuery()
    19.                     MessageBox.Show("Order placed, SpecSalesTable Updated! ")
    20.                 Catch ex As Exception
    21.                     MessageBox.Show(" Error placing order... ")    'IF ERROR DISPLAYS MESSAGE
    22.                 End Try
    23.  
    24.             End If
    25.  
    26.         End If
    27.  
    28.         Connection.Close()
    29.     End Sub

    If I'm being completely honest, I don't understand what the 8 is there for, just needed an integer or else I got errors from it

  9. #9
    New Member
    Join Date
    Oct 2006
    Location
    Ontario
    Posts
    12

    Re: Problem with checkbox & radio buttons...

    Code:
    	Dim totalCost As Integer ' Total value
            Dim deposit As Integer ' Deposit value, 20% of total
    
            totalCost= 50 'Base value of frames, always 50
    
            Select Case GPCboBx.Text ' Combobox Text
                Case "Glass"
                    totalCost += 30
                Case "Plastic"
                    totalCost += 15
            End Select
    
            Select Case ScratchCboBx.Text ' Combobox Text
                Case "Yes"
                    totalCost += 10
            End Select
    
            Select Case UVCboBx.Text ' Combobox Text
                Case "Yes"
                    totalCost += 15
            End Select
    
            deposit = totalCost * 0.2 'Divides total by 0.2 to find the 20% deposit
    
            TextBox1.Text = totalCost 'Displays total
            TextBox2.Text = deposit 'Displays deposit
            TextBox3.Text = totalCost - deposit 'Subtracts the deposit from total, to find balance
    
            PrintButton.Enabled = True
            ViewButton.Enabled = True
            myAddNew(8) 'CALLS ADDNEW METHOD WHEN ADD BUTTON IS CLICKED
    Then create variables in your "myAddNew" method for the values you wish to use in it.

  10. #10
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Problem with checkbox & radio buttons...

    Lets start with these two lines (really the second one I guess)
    Code:
    SQLString = "INSERT INTO SpecSalesTable (CustomerID, EyeTestID, FrameID, DateOfSale, GlassOrPlastic, ScratchCoating, UVFilter, TotalCost, DepositPaid) "
    SQLString += "Values ('" & CustomerIDTextBox.Text & "','" & EyeTestIDTextBox.Text & "','" & StockTextBox.Text & "',#" & Date.Today & "#,'" & GlassPlasticTextBox.Text & "','" & ScratchTextBox.Text & "','" & UVTextBox.Text & "','" & TextBox1.Text & "','" & TextBox2.Text & "')"
    GlassPlasticTextBox : We are not using this any more so
    in the Dim section lets decalare a new variable

    vb.net Code:
    1. DIM glassOrPlasting as STRING = String.Empty

    Next we text the radiobuton

    vb.net Code:
    1. IF GlassRadioButton.Checked = True Then
    2.    glassOrPlastic = "Glass Lens"
    3. ELSEIF PlasticRadioButton.Checked = True Then
    4.    glassOrPlastic = "Plastic Lens"
    5. ELSE
    6.    glassOrPlastic = "What do you mean?"
    7. END IF

    Now you replace GlassPlasticTextBox.Text with the glassOrPlastic variable

    Does this give you an idea to carry on with?
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Location
    Ireland
    Posts
    85

    Re: Problem with checkbox & radio buttons...

    Gary, can't thank you enough...!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width