kRod 49 Junior Poster

I am hoping this is not inappropriate to do on here if it is I apologize in advance and will let the thread die a slow agonizing death.

Here goes:
I have a little TextBox app that's supposed to only allow numeric’s positive and negative and allow 2 decimal places. I have tested it and it seems to work as intended. What I'd like is for you all to try and break it. The max characters functionality needs some work but it's not the focus of my TextBox.

Numbers_Only_Form

'K. W. 4/19/2012
'TextBox Control For
'Numerics/Money entry
'1 Decimal Point
'2 Decimal Places
'Allows The BackSpace
'Handles enter key by Moving to the Next control
'Set Max characters checked - this sets it to 4 if not checked allows 10 characters
'The button just multiplies the textbox value by 5

Public Class Form1

    Private maxSize As Boolean = False
    Private numMaxSize As Integer

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If T1.Text <> "" Then
            If CDbl(T1.Text) > 0 Or CDbl(T1.Text) < 0 Then
                MsgBox(CDbl(T1.Text) * 5)
                T1.Clear()
            End If
        End If
        GetNextControl(Button1, False).Focus()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'Add Handler for all the Numeric only TextBoxes on the Form
        For Each ctrl As Control In Me.Controls
            If TypeOf ctrl Is TextBox Then
                AddHandler ctrl.KeyPress, AddressOf Boxkeypress
            End If
        Next ctrl
        T1.MaxLength = 10
    End Sub

    Private Sub Boxkeypress(ByVal sender …
kRod 49 Junior Poster
kRod 49 Junior Poster

I may be off the edge of the map here but Why are you using the cmd.ExecuteReader to Insert values into a table when you should be using cmd.ExecuteNonQuery?

Nutster commented: I should have caught that. The wrong function is being called for an operation that does not return any rows. +3
AndreRet commented: Same here, should have seen that coming :) +12
kRod 49 Junior Poster

You want to call the DataGridVidew EndEdit() method when your cell leave event is fired.

kRod 49 Junior Poster

Well the first thing I see you are asking the sub to compare column 6 to column 4 are you aware datagridview columns are a zero based index so column 4 should be 3 and column 6 should be 5. Are you getting any errors or is nothing happening? Have you stepped thru each line of the sub to see if you are getting values into your variables.

kRod 49 Junior Poster

I would use a dataadapter to fill a dataset. Set the table from the Dataset as the DataSource of a BindingSource then set the BindingSource as the DataGridViews DataSource. Then you just call DataAdapter's update method when you update, add or delete records in your DataGridView. This will reflect all changes back to your DataBase Table.

kRod 49 Junior Poster

Your updated xmlwill only have 1 table now if that is what you are desiring. I ran the code and it displays the way I understand you want. I added a little updating code to it

Public Class Form1
    Dim bs As New BindingSource
    Dim editFlag As Boolean = False
    Dim filepath As String = "text.xml"
    Dim deflection_dataset As New DataSet

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            deflection_dataset.ReadXml(filepath)
            bs.DataSource = deflection_dataset.Tables(0)
            Deflections_datagrid.DataSource = bs
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    End Sub

    Private Sub btnSaveChanges_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveChanges.Click
        If editFlag Then
            Try
                deflection_dataset.WriteXml("Text.xml")
                editFlag = False
                MsgBox("Changes to the XML have been SAVED", MsgBoxStyle.Information, "SUCCESS")
            Catch ex As Exception
                MsgBox("CHANGES HAVE NOT BEEN SAVED", MsgBoxStyle.Critical, "FAILURE")
            End Try

        End If

    End Sub


    Private Sub Deflections_datagrid_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Deflections_datagrid.CellEndEdit
        editFlag = True
        bs.ResetBindings(False)

    End Sub
End Class
kRod 49 Junior Poster

One thing I see, your xml file when read into a dataset creates 4 data tables. I'm not sure what you want displayed, but if you want all the data from the xml file displayed in the datagridview you'll have to change the structure of your xml.

kRod 49 Junior Poster

Not to beat a dead horse, but you could just call this Sub like the following:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call DoControls(Me)
    End Sub

    Private Sub DoControls(ByVal ctrlCont As Control)
        For Each ctrl As Control In ctrlCont.Controls
            If TypeOf ctrl Is CheckBox Then
                If TypeOf ctrl Is CheckBox AndAlso DirectCast(ctrl, CheckBox).Checked Then
                    If ctrl.Tag Is "Test" Then
                        DirectCast(ctrl, CheckBox).Checked = False
                    End If
                End If
            End If

            'If the ctrl has children, 
            'recall this Sub
            If ctrl.HasChildren Then
                DoControls(ctrl)
            End If
        Next
    End Sub
iFrolox commented: Worked :) Thank you +2
kRod 49 Junior Poster

You'll need to brush up on Registry Coding and use

To disable the Windows key, follow these steps:
1.Click Start, click Run, type regedt32, and then click OK.
2.On the Windows menu, click HKEY_LOCAL_ MACHINE on Local Machine.
3.Double-click the System\CurrentControlSet\Control folder, and then click the Keyboard Layout folder.
4.On the Edit menu, click Add Value, type in Scancode Map, click REG_BINARY as the Data Type, and then click OK.
5.Type 00000000000000000300000000005BE000005CE000000000 in the Data field, and then click OK.
6.Close Registry Editor and restart the computer.
To enable the Windows key, follow these steps:
1.Click Start, click Run, type regedt32, and then click OK.
2.On the Windows menu, click HKEY_LOCAL_ MACHINE on Local Machine.
3.Double-click the System\CurrentControlSet\Control folder, and then click the Keyboard Layout folder.
4.Right-click the Scancode Map registry entry, and then click Delete. Click Yes.
5.Close Registry Editor and restart the computer.

Danger Will Robinson, Danger!

kRod 49 Junior Poster

Try this

Click Here

kRod 49 Junior Poster

Please see attached doc file. I'm not having any luck formatting this at all.

    Dim dr As DataRow = FrmSamplDataSet.Tables(0).NewRow
    dr.Item(1) = "Tony's Express"
    dr.Item(2) = "(999) 863-9854"
    FrmSamplDataSet.Tables(0).Rows.Add(dr)
    Me.TblShippersTableAdapter.Update(FrmSamplDataSet)
kRod 49 Junior Poster

As G Waddell said you should look around. On this very website Click Here

This is also a good place to begin Click Here

kRod 49 Junior Poster

Please disregard my previous post

Public Class Form1
  ''declare my array
  'Dim Pboxes() As PictureBox = {pb1, pb2, pb3, pb4, pb5, pb6, pb7, pb8}

  'Dim TBoxes() As TextBox = {tb1, tb2, tb3, tb4, tb5, tb6, tb7, tb8}

  'Used Lists
  Dim lstPBoxes As New List(Of PictureBox)
  Dim lstTBoxes As New List(Of TextBox)

  Private Sub Test()
    'call a function
    Call ClearBoxes()
  End Sub

  Public Sub ClearBoxes()

    'created so TextBox cooresponding
    'to the PictureBox could be accessed
    Dim i As Integer = 0

    'Loop the PictureBox List
    For Each lp In lstPBoxes
      lp = CType(lp, PictureBox) ' Needed so you have an object to test
      If Not lp.Image Is Nothing Then
        '(Pboxes(i).Image Is Nothing) Then '<<<<<< Nullref at this point
        i = lstPBoxes.IndexOf(lp)
        lp.Image.Dispose()
        lp.Image = Nothing
        CType(lstTBoxes(i), TextBox).Text = Nothing
      End If

    Next

  End Sub

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    'Fill PictureBox List
    lstPBoxes.Add(pb1)
    lstPBoxes.Add(pb2)
    lstPBoxes.Add(pb3)
    lstPBoxes.Add(pb4)
    lstPBoxes.Add(pb5)
    lstPBoxes.Add(pb6)
    lstPBoxes.Add(pb7)
    lstPBoxes.Add(pb8)
    lstPBoxes.Add(pb9)

    'Fill TextBox List
    lstTBoxes.Add(tb1)
    lstTBoxes.Add(tb2)
    lstTBoxes.Add(tb3)
    lstTBoxes.Add(tb4)
    lstTBoxes.Add(tb5)
    lstTBoxes.Add(tb6)
    lstTBoxes.Add(tb7)
    lstTBoxes.Add(tb8)


    Call Test()

  End Sub

End Class
kRod 49 Junior Poster

How did you get away with creating a Class with NO NAME? I just attempted to recreate your code and I had to assume you were using a Form as you had textboxes and pictureboxes and it will not let me in vs2008 sp1 create a class with no name. Anyway, assuming you are using a form You must create a PictureBox Object to test

For i As Integer = 0 To 7
      If Not CType(Pboxes(i), PictureBox) Is Nothing Then
        '      (Pboxes(i).Image Is Nothing) Then '<<<<<< Nullref at this point
        Pics(i).Image.Dispose()
        Pics(i).Image = Nothing
      End If
      Txt(i).Text = Nothing
    Next i
kRod 49 Junior Poster

Have you thought of using an XML file instead of the CSV. You could take advantage of the DataSet.Read and DataSet.Write methods.

themaj commented: dell +1
kRod 49 Junior Poster

How about saving the required info to an XML/CSV file or a access/sqlServer datatable Then when the app opens fill your list view you select and query for the Info and fill the for.

kRod 49 Junior Poster

What are the Primary Keys for your MS ACCESS Tables? Are they AutoNumbers?
Why are variables with names that sound like Numbers and Dates wrapped in single quotes?
If you are not entering all the values for all fields you need to specify the fields that the values correspond to, in the same order that appear in the MS ACCESS table.

You should set a Break Point at the start of your Sub btnConfirm_Click and step through it catch the values of sqlInsertOrder, sqlInsertProduct, and sqlInsertOrderProduct variables. When you copy them paste them into the Query Design Window of MS ACCESS and see if they execute.

kRod 49 Junior Poster

For insert query Click Here
For Executing The Command Click Here
You might want to have a go at this >>Click Here
Lots of helpful info on that site

kRod 49 Junior Poster

I found this Click Here Might be a solution. I would just call the Forms mouse enter and leave subs from the Panels mouse enter and leave subs.

kRod 49 Junior Poster

Hi Jim, I ran what you had set up in your test and tried TableLayoutPanel1.SendToBack and Me.BringToFront neither worked, Bummer.

Now for my question since you're getting the Panel MouseEnter event to fire isn't that the same as the Mouse entering the form or do you need the event Argument of the Form enter event. I’m just thinking out loud here.

kRod 49 Junior Poster

Thank you for the informed reply TnTinMN. I am going to look into using a dictionary. There are NO duplicates. This file was created from a Registry app I found online to list all registered file extensions on the user’s computer I just tweaked it to get the other 2 fields. It's a labor of love learning vb.net by myself. Pretty much my fav hobby. I just started with the Lambda/LINQ portion. I did time the searches and there wasn't much difference as there are only ~1000 records. I may test it on my zip code database and see if there is a significant time difference or what I was mostly concerned with overhead.
Again Thank You for your time
KROD

kRod 49 Junior Poster

Hello all. I have a question on searching a List(Of CLass). I am not sure how it is labeled List<OF T> or List(Of Class) However you label it here is the Class EXT

Public Class EXT
  Implements IComparable

  Private m_extension As String
  Private m_exe As String
  Private m_description As String

  'Public Sub New()
  'End Sub

  Public Sub New(ByVal eExtension As String, _
                 ByVal eDescription As String, ByVal eExecutable As String)

    m_extension = eExtension
    m_description = eDescription
    m_exe = eExecutable

  End Sub

  Public Property EXTENSION() As String
    Get
      Return m_extension.ToLower
    End Get
    Set(ByVal value As String)
      m_extension = value
    End Set
  End Property

  Public Property DESCRIPTION() As String
    Get
      Return m_description
    End Get
    Set(ByVal value As String)
      m_description = value
    End Set
  End Property

  Public Property EXECUTABLE() As String
    Get
      Return m_exe
    End Get
    Set(ByVal value As String)
      m_exe = value
    End Set
  End Property

  Public Function ToArray() As String()
    Dim ret(2) As String
    ret(0) = m_extension
    ret(1) = m_description
    ret(2) = m_exe

    Return ret
  End Function

  Public Function CompareTo(ByVal obj As Object) As Integer _
                                                 Implements System.IComparable.CompareTo

    Dim other As EXT = DirectCast(obj, EXT)
    Return Me.EXTENSION.CompareTo(other.EXTENSION)

  End Function

End Class

Here is a sample the CSV file there are over 936 records.

EXTENSION,DESCRIPTION,EXECUTABLE
.flac,Music,C:\Program Files\JetAudio\jetaudio.exe
.flv,Flash Video file,C:\Program Files\Combined Community Codec Pack\MPC\mpc-hc.exe
.....

I have lstExt which is a List Of EXT. I fill it from a CSV file and display it on a DataGridView through a BindingSource. I have a textbox which the user …

kRod 49 Junior Poster

This is a simple function to determine if all the textboxes on a form have input or have not had there text property set to nothing. It creates a control variable, uses it to loop through all the control, when it finds a control that is of type TextBox it converts the variable to a TextBox That way it can check its Text Property. I know there are better explainations on MSDN about how it works.

Private Function ValidateInput() As Boolean

    Dim ret As Boolean = True

    For Each cnt In Me.Controls
      If TypeOf (cnt) Is TextBox Then
        If CType(cnt, TextBox).Text = "" Or CType(cnt, TextBox).Text Is Nothing Then
          ret = False
        End If
      End If
    Next

    Return ret

  End Function

Microsoft says >> Click Here

If your controls are in a Container on the Form you would have to iterate the Container to get the TextBoxes in the Container.

kRod 49 Junior Poster

Any chance we could see a sample of your CSV File? I am curious why you are tab delimiting and there are 2 tabs between Chocolate and the number 10 which I am guessing is the count. You could make your coding life a lot easier if you had a Orders Class and then add each order to a list(Of Orders). Or a simple DataTable with all your orders would be a more manageable. Also could you post the code you have so far I'd like to look at it and see what your thought process is?

kRod 49 Junior Poster

When your program is running how many forms would the user have open at one time? Are any of these Child forms? If they are not child forms you can use the following
Form Wide Variable Dim sef As frmDailySales >>frmDailySales is a Form.
Then in the event you want to open that form use

 Private Sub lnkEnterSales_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkEnterSales.LinkClicked

    If sef Is Nothing OrElse sef.IsDisposed = True Then
      sef = New frmDailySales
    End If

    If sef.Visible = False Then
      sef.Show()
      sef.whoCalled = Me 'Pass the Calling Form
      Me.Hide()
    End If

  End Sub

The frmDailySales will open. The form(frmSalesMain) that called frmDailySales will hide
The frmDailySales will have a variable>> Public whoCalled as Form
When you close frmDailySales

 Private Sub frmDailySales_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
    whoCalled.Show()
  End Sub

frmSalesMain will again be visible.

If I didn't explain this well enough let me know and I will help where you need it.

kRod 49 Junior Poster

You have no Single quotes around KMBPartNo

Dim SelectQry = "SELECT * FROM TblSupplierQuotes where TenderNo='" & Me.txtTenderRef.Text & "' AND KMBPartNo='" & Me.lbKMBPartNo.Text & "';"
kRod 49 Junior Poster

I assuming the Return from

Private Function Req(ByVal Site As String, ByVal Met As String, Optional ByVal P As String = "") As String

is the source you are trying to put in a RichTextBox? If so just create a read only property in the YouTube Class and access it after the login and use it for your RichTextBox text. rtbSource is the RichTextBox.

Private m_resp As String

  Public ReadOnly Property Source() As String
    Get
      Return m_resp
    End Get

  End Property



Private Function Req(ByVal Site As String, ByVal Met As String, Optional ByVal P As String = "") As String
    Dim Response As String = String.Empty
    Try
      Dim R As HttpWebRequest = CType(HttpWebRequest.Create(Site), HttpWebRequest)
      R.Method = Met
      R.CookieContainer = Containa
      R.AllowAutoRedirect = True
      R.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20100101 Firefox/12.0"
      R.ContentType = "application/x-www-form-urlencoded"
      R.ServicePoint.Expect100Continue = False
      If Met = "POST" Then
        R.ContentLength = P.Length
        Dim Wr As New StreamWriter(R.GetRequestStream(), System.Text.Encoding.Default)
        Wr.Write(P)
        Wr.Close()
      End If

      Dim Re As New StreamReader(R.GetResponse.GetResponseStream())
      Response = Re.ReadToEnd
      Re.Close()
    Catch
    End Try
  **  m_resp = Response**
    Return Response
  End Function


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim Nick As String = txtUserName.Text
    Dim Pw As String = txtPassword.Text
    Dim B As New Youtube

    lblInfo.Text = ">> Trying to log in ..."
    If B.Login(Nick, Pw) Then

      lblInfo.Text = ">>> Login successfully!"
    Else
      lblInfo.Text = ">>> Login failed!"

    End If
    rtbSource.Text = B.Source
  End Sub

If this is wrong let me know.

kRod 49 Junior Poster

Sorry to hear that didn't work. According to all the documentation this should have worked. When I was having trouble with Visual Studio 2008 Add New Data Source everytime I would try to add a data source I would get an error that said "Procedure Not Available". I solved it by installing Service Pack 1 for VS.Net 2008 Professional. You can download it Here--> Click Here If that is not your version There are links to the version you have.

Have you tried to create a completely new project and add your datasource and see if it would allow you to update your database?

kRod 49 Junior Poster

If you put the call to the Youtube class in the Button Click event it should call all the functions/subs. I tried it but as i do not have a YouTube account I couldn't varify that it works only that I failed to log in.

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim Nick As String = txtUserName.Text
    Dim Pw As String = txtPassword.Text
    Dim B As New Youtube

    lblInfo.Text = ">> Trying to log in ..."
    If B.Login(Nick, Pw) Then
      lblInfo.Text = ">>> Login successfully!"
    Else : lblInfo.Text = ">>> Login failed!"
    End If

  End Sub
kRod 49 Junior Poster

Well in a Form project just use labels and textboxes for the console.reads and console.writes
keep the YouTube class and ditch the module Add a Button for the user to click when they have entered the user name and password. Let me know if you need any more help.

kRod 49 Junior Poster
     Dim lines() As String
        lines = TextBox1.Lines
        Dim amper As Integer = 0
        For Each l In lines
          amper = l.IndexOf("@")
          MsgBox(l.Remove(amper, l.Length - amper))
        Next
kRod 49 Junior Poster

You could capture the KeyPress Event of the TextBox and allow the user to only enter what you want. You check the value of the KeyPressEventArgs. I usually use it so I don't have to code the ooops you didn't enter the proper value sub/functions. There is also a nice RegEx pattern you can use to match a good value when the user is finished. Let me know if you are interested.

kRod 49 Junior Poster

Try the following.
1 Right Click on the TableAdapter in the tray below your Form
2 Select Edit Queries In DataSet Designer
3 Right Click on The Name of the DataSet at the top of the DataSet table
4 Click Configure. You should see the select Statement
5 Then Click Advanced
6 Ensure Generate Insert, Update and Delete Statements and Use Optimistic Concurrency is checked
7 Click OK
8 Click Next
9 Make sure all three CheckBoxes are Checked
10 Click Next
11 You should see a list of what was created with checkmarks next to them
12 Click Finish

kRod 49 Junior Poster

How bout you give the StringBuilder a go?
Import SYSTEM.TEXT

    If IO.File.Exists("C:\Customers.txt") = False Then
      IO.File.Create("C:\Customers.txt")
    End If
    Dim FILE_NAME As String = "C:\Customers.txt"

    If System.IO.File.Exists(FILE_NAME) = True Then
      Dim sb As New StringBuilder

      sb.AppendLine("CustomerID           CustomerName")
      For i As Integer = 0 To dgvMain.Rows.Count - 1
        sb.AppendLine(dgvMain.Item(0, i).Value.ToString() & "                " & dgvMain.Item(1, i).Value.ToString())
      Next
      Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
      objWriter.WriteLine(sb.ToString)

      objWriter.Close()
    End If
kRod 49 Junior Poster

Could you post the rest of the Exception? Also did you click 'Generate' the Update Delete etc. When you configured the dataadapter?

kRod 49 Junior Poster

I created a XLXM workbook added a simple macro that open a messagebox and puts the number 2 in B1 cell then saves the workbook as a XLSX file and does not save the 2 in cell B1 of the xlsm file. Here is the code. Hope this helps.

Imports Microsoft.Office.Interop
Imports System.IO



Public Class Form1
  Dim xlApp As Excel.Application
  Dim xlWorkBook As Excel.Workbook
  Dim xlWorkSheet As Excel.Worksheet


  Private Sub releaseObject(ByVal obj As Object)
    Try
      System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
      obj = Nothing
    Catch ex As Exception
      obj = Nothing
    Finally
      GC.Collect()
    End Try
  End Sub



  Private Sub btnMacro_1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMacro_1.Click
    Dim fldr As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments

    xlApp = New Excel.ApplicationClass
    xlApp.DisplayAlerts = False
    xlWorkBook = xlApp.Workbooks.Open(fldr & "\book1.xlsm")
    xlWorkSheet = CType(xlWorkBook.Worksheets(Index:=1), Excel.Worksheet)
    xlApp.Run("Sheet1.RunMe")

    '~~>Save the workbook
    **xlWorkBook.SaveAs(Filename:=fldr & "\BOOK2.xlsx", FileFormat:=51)**

    'xlWorkSheet.SaveAs(fldr & "\TEST.xlsx", FileFormat:=51)

    '~~>Close the WorkBook and DO NOT Save Changes - FALSE
    xlWorkBook.Close(False)

    '~~> Quit the Excel Application
    xlApp.Quit()

    '~~> Clean Up
    releaseObject(xlApp)
    releaseObject(xlWorkBook)



  End Sub


End Class
kRod 49 Junior Poster
kRod 49 Junior Poster

There's a lot missing from your code. It would help if you explain what it is you want to accomplish.

kRod 49 Junior Poster