Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Or a little cleaner

Private Sub FocusChanged(sender As Object, e As EventArgs)

    If CType(sender, TextBox).Focused Then
        CType(sender, TextBox).BackColor = Color.FromArgb(65, 65, 65)
    Else
        CType(sender, TextBox).BackColor = Color.FromArgb(60, 60, 60)
    End If

End Sub

or

Private Sub FocusChanged(sender As Object, e As EventArgs)

    If sender.Focused Then
        sender.Tag = sender.BackColor
        sender.BackColor = Color.LightGray
    Else
        sender.BackColor = sender.Tag
    End If

End Sub    

Which saves the current background colour before setting the focused colour (useful if not all of your textboxes are the same colour). If you are a purist you can do

Private Sub FocusChanged(sender As Object, e As EventArgs)

    Dim txt As TextBox = sender

    If txt.Focused Then
        txt.Tag = txt.BackColor
        txt.BackColor = Color.LightGray
    Else
        txt.BackColor = txt.Tag
    End If

End Sub
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If you want to handle all textboxes the same way you can create two generic handlers such as

    Private Sub TextBox_GotFocus(sender As Object, e As System.EventArgs)
        sender.BackColor = Color.LightGray
    End Sub

    Private Sub TextBox_LostFocus(sender As Object, e As System.EventArgs)
        sender.BackColor = Color.White
    End Sub

then on form load you can attach these handlers to every textbox as

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

        For Each ctrl As TextBox In Me.Controls.OfType(Of TextBox)()
            AddHandler ctrl.GotFocus, AddressOf TextBox_GotFocus
            AddHandler ctrl.LostFocus, AddressOf TextBox_LostFocus
        Next

    End Sub
Begginnerdev commented: I laugh every time I see your picture. +5
iFrolox commented: Thats what i needed +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Or if you can't or don't want to group the controls, set the Tag property of each to some known value then test in a loop like

For Each ctrl As Control In Me.Controls
    If ctrl.Tag = "my value" Then
        ctrl.Enabled = True
    End If
Next
iFrolox commented: Thank you for providing the code +1
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

When you encrypt it you are also encrypting the carriage return and line feed characters. As such, ReadAllLines can't parse the text back into separate lines. You'll have to encrypt and write each line separately to preserve the delimiters.

iFrolox commented: Exactly what i had to do, thank you for the reply. +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I wrote up two skeleton apps. The first is the server that runs the folder watch and the generator. The second is the client app. Both are missing the code to load and process the Excel files (hard to do if you don't know what the processing or data are). I've also attached the zipped project files.

Server App
Imports System
Imports System.Collections

'                                                                                                   
'  Name:                                                                                            
'                                                                                                   
'    EruditioServer (catchy name, don't you think?)                                                 
'                                                                                                   
'  Description:                                                                                     
'                                                                                                   
'    This app monitors the folder given in PRODFILES and watches for rename events on xls files.    
'    It assumes that this will only ever happen when a .tmp file is renamed to .xls upon the        
'    completion of an edit by a user.                                                               
'                                                                                                   
'    When a .tmp is renamed to .xls, this app starts a background thread which takes the newly      
'    edited .xls file, opens it to create a one line summary, then updates a summary file with      
'    that summary.                                                                                  
'                                                                                                   
'  Notes:                                                                                           
'                                                                                                   
'    This code is just a skeleton. It includes no extra code to actually process the Excel files.   
'    That code is left to the implementing programmer to fill in.                                   
'                                                                                                   
'    I understand that all of the .xls files are processed automatically during the night to        
'    ensure that no summaries were missed. It should be an easy matter to add that functionality    
'    into this code by creating a timer which would scan the PRODFILES folder and add all .xls      
' …
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I had a recent exchange with a user. He had posted a lengthy snippet of code as a proposed solution to a question. The code was undocumented and uncommented so I replied that adding some comments might make the mechanics of the code clearer. His response was "I did not realize that it was a requirement of this site to post fully documented code." Clearly there was some disconnect between what I requested and what he thought I requested. It reminded me of a favourite saying from my dad

There is a difference between scratching your [backside] and ripping it to shreds.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Lets try this setup as a possibility. I'm going to make a few assumptions:

  • Excel files are in \server\excel\prod
  • Working files are in \server\excel\work
  • generated text files are in \server\excel\text
  • prod files named datafile-###.xls
  • work files named datafile-###-user.xls

You want only one copy of the FileSystemWatcher (FSW) running. I'm assuming this would be on the server hosting the files. FSW could be set to monitor FileName events and could ignore everything but Rename events. The Filter would be set to "*.xls" in the prod folder. The reason you want to use Rename events only is because you can get multiple Change events for one change and you don't want to trigger multiple times for one change. Also, a Rename is virtually instantaneous. By the time the action causes the trigger the file is available for use.

When a user selects an Excel file via the FileOpenDialog, your code would check to see if there is already a working file for that Excel file. If there is, then the user is told so, and possibly also which user has that file and for how long. If not then a working file is created from that Excel file and opened for editing by the user.

If the user abandons his edits then the working file is deleted. If the user saves the changes, then after the changes are written to the working file, the original (in prod) is deleted and the temp file is renamed to the original name. This triggers …

Eruditio commented: Sound advice. This ended up fixing the problem. +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

When pulling an "all-nighter" means not having to get up to pee.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

My degree was in Computer Science. I don't know what topics get covered in Information Technology these days but I was amazed at how much the curriculum had changed from when I got my degree in 1977 and when my younger son graduated from the same University in 2009. There was a lot more emphasis on programming and numerical analysis back in the 70s.

The earlier advice (learn more programming languages) is sound. If you know only one language your mind gets stuck in one mode of thinking. It's the old "if the only tool you have is a hammer you tend to see every problem as a nail" scenario. You are better off learning a few languages reasonably well than many poorly.

I've found that a good way to learn is by answering questions on this forum. If I see an interesting question that I don't know the answer to I do a little research and a little experimenting.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

This whole writing will likely be ignored.

It very well may be ignored. I am sure it will be by many. Please notice my use of the word "suggestions". These are not rules. I do not feel it is my place to try to impose rules. However, it is my opinion that posting a question in a clear and concise manner greatly increases the odds of getting a complete and accurate answer without a lot of needless back and forth for clarification.

If my suggestions are ignored then so be it. At least I tried.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I've always been a big fan of letting the computer do as much work as it can. Don't bother writing the bubble sort. The following code uses a sorted dictionary. The key is the line number (with the "N" removed) and the value is the rest of the line. No matter what order you add the lines, when you step through the keys you will always get them in sorted order. That is why I made the key Integer. Not all of your code lines are N####. One is N### (three digits). Note that When I output the lines to the ListBox I ensure that the #### portion is four digits.

Public Class Form1

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

        Dim sd As New SortedDictionary(Of Integer, String)

        For Each line As String In System.IO.File.ReadAllLines("D:\temp\sampleCode.txt")

            Dim linenumb As String      'the N#### portion of the line
            Dim linecode As String      'everything other than N####

            If line.StartsWith("N") Then
                linenumb = Split(line)(0).Substring(1)
                linecode = line.Substring(Len(linenumb) + 1)
                sd.Add(CInt(linenumb), linecode)
            End If

        Next

        For Each linenumb As Integer In sd.Keys
            ListBox1.Items.Add(linenumb.ToString("0000") & sd(linenumb))
        Next

    End Sub

End Class
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

This is an excellent, non-technical article on programming that I think every programmer should read at least twice.

gusano79 commented: AMEN +8
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If I hadn't have believed it I wouldn't have seen it. - Ashleigh Brilliant

Just to stir things up seemed a great reward in itself. - Sallust

Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind. - unknown

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

The following will implement the formula, however, it won't give you the result you want unless you convert the angle from degrees to radians. The following code does that by multiplying the angle by PI/180. I'll assume the formula is correct (trig was never my strong suit).

Imports System.Math

Public Class Form1

    '                       dia           1          dia
    'h   =   sh * s  +  ------------   +  -  *   ------------
    '                   2 * tan(ang)      3      2 * tan(ang1)

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

        Dim sh As Double = CDbl(txtsh.Text)
        Dim s As Double = CDbl(txts.Text)
        Dim dia As Double = CDbl(txtdia.Text)
        Dim ang As Double = CDbl(txtang.Text) * PI / 180.0
        Dim ang1 As Double = CDbl(txtang1.Text) * PI / 180.0

        Dim h As Double

        h = sh * s _
          + dia / (2.0 * Tan(ang)) _
          + dia / (2.0 * Tan(ang1) / 3.0)

        txth.Text = h

    End Sub

End Class
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I suspect it is one of those applications that takes highly specialized knowledge. It would be like asking someone with highschool math to solve linear diophantine equations or calculate eigen values.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

There is a checkbox on the Boot tab that says "Make all boot settings permanent". Have you tried selecting that? What settings are you trying to make permanent? What exactly do you mean by "all that crap"?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I created a DataGridView and added four columns. I copied your sample input into d:\temp\testdata.txt and ran the following code:

Public Class Form1

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

        For Each line As String In System.IO.File.ReadAllLines("d:\temp\testdata.txt")
            DataGridView1.Rows.Add(line.Split(","))
        Next

    End Sub

End Class

If ColumnHeadersVisible is set to True you get the output in attachment 1. If False you get attachment 2.

poojavb commented: perfect...short and simple +4
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You might want to have a look at the free log parser tool from Microsoft which can be downloaded here

|-|x commented: looks like this will do what I need. thx +6
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Assuming that every block contains both an email and a password, and they appear in that order, the following code will do it. It processes all lines in the control and splits each line into fields at the "=" character. The "Filter" function returns an array of string with only the lines in RichTextBox1 that contain "="

For Each line As String In Filter(RichTextBox1.Lines, "=")

    Dim fields() As String = line.Split("=")

    Select Case fields(0)
        Case "email"
            RichTextBox2.AppendText(fields(1))
        Case "password"
            RichTextBox2.AppendText(":" & fields(1) & vbCrLf)
    End Select

Next
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Try the following code

Public Class Form1

    Dim Lbut(2) As Button
    Dim Rbut(2) As Button

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

        Dim row As Integer = 0

        For y As Integer = 13 To 113 Step 50
            Lbut(row) = MakeButton(13, y, 75, 23, row, "Left")
            Rbut(row) = MakeButton(93, y, 75, 23, row, "Right")
            row += 1
        Next

    End Sub

    Private Function MakeButton(x As Integer, y As Integer, w As Integer, h As Integer, row As Integer, text As String) As Button

        Dim btn As New Button
        btn.Size = New Size(w, h)
        btn.Location = New Point(x, y)
        btn.Text = text
        btn.Tag = row

        AddHandler btn.Click, AddressOf Button_Click

        Me.Controls.Add(btn)

        Return btn

    End Function

    Private Sub Button_Click(sender As System.Object, e As System.EventArgs)

        Dim btn As Button = sender
        Dim row As Integer = btn.Tag

        If btn.Text = "Left" Then
            Rbut(row).Enabled = Not Rbut(row).Enabled
        End If

    End Sub

End Class
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If you set up a specific folder for files to process then users can deposit completed files into that folder. Once you have processed a file you can move it out of that folder and archive or delete it. Sometimes you just have to train the users to provide data in the proper format in a file with a properly formatted name. I find a cattle prod works well.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If I might add my recommendation:

My laptop has two internal hard drives. The first is partitioned as C (60 gig) and D (400 gig) (approximately). I have Windows 7 Pro and all my applications installed on C. I store no data on C that I am not willing to lose. I use Acronis to iimage my C partition. Acronis is a commercial product but I understand that Macrium Reflect comes in a free version and has been recommended by several sites. This is my process for setting up.

  • Wipe C partition
  • Install and configure Windows 7 (activate)
  • Install all driver software
  • Install all Windows/driver updates
  • Install disk imaging software
  • Create basic system image
  • Install anti-virus
  • Install most used applications
  • Apply all outstanding anti-virus/application updates
  • Freeze Windows updates (details below)
  • Install and run CCleaner to remove all temporary files
  • Create final system image

At this point you have two images. The basic system image is your "I want to go back to a completely clean system. This one likely won't be used much. The second image is the important one. At some point you may find yourself infected with a trojan/virus/etc. Or your system may just be running slow. I find Windows does that after many months of use. Or you may have installed so much software that your system has gotten too cluttered. As long as you have kept all of your data on another drive (D, for example) it is a simple matter to refresh …

wallet123 commented: Thanks sir, im not american and im 16 years old and i hope you dont mind if i want to ask some further questions.. (the fact that i dont understand some and i havent heard or encountered some of the things that u have stated) what do you mean by "Wipe C p +2
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Please read through the following suggestions before posting in this forum. Questions in this forum are answered by people who generously volunteer their time. Following these guidelines will increase the chances of getting a quick and accurate answer.

  1. Use Search to see if your question has been asked and answered by another user.
  2. Create a meaningful title for your question. "Help" or "Urgent" are likely to be ignored.
  3. Summarize your question in the first sentence of your post. This is what gets displayed in the thread summary page. This makes it easier for everyone to scan the forum.
  4. Please use clear English. Do not use slang or LEET or ALL CAPS. This is not twitter or a chat room. If your question is not clear you may not get the help you seek.
  5. Show us that you have made a serious effort (don't expect us to do the work for you).
  6. Explain what your code is supposed to do as well as what it is doing. If appropriate, include some sample input and what you want as output.
  7. Post all relevent code (commented would be preferred). Do not post extraneous code. If possible, strip your code down to that which illustrates the problem.
  8. If you are having a database problem we may need to see your table structure. If so, post that as well. Include field names and types.
  9. Please include any error messages and the place in the code where the error occurs. There are thousands of ways for …
Begginnerdev commented: At least some one said it. Thanks, Jim. +5
Riteman commented: sure! +1
kvprajapati commented: Great! Please include SSCCE link - http://sscce.org/ +14
Unhnd_Exception commented: I'm tired of seeing this. Glad everyone else likes it. +0
kimlong2012 commented: I agree. +0
The Cleaner commented: Blow it out your ass! +0
G_Waddell commented: Here Here +4
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If you store the player name as part of the structure then you have to do a search to find the record corresponding with a particular name. If you use a dictionary then you can get at any player by indexing with the player name.

    Structure PlayerInfo
        Dim Age As String
        Dim Score As String
        Dim datePlayed As String
    End Structure

    Private Sub btnPlayers_Click(sender As System.Object, e As System.EventArgs) Handles btnPlayers.Click

        Dim players As New Dictionary(Of String, PlayerInfo)
        Dim details() As String = "Jim,53,11209,2012-06-02".Split(",")

        Dim info As New PlayerInfo
        info.Age = Trim(details(1))
        info.Score = Trim(details(2))
        info.datePlayed = Trim(details(3))
        players.Add(Trim(details(0)), info)

    End Sub

To refer to the stats for a particular user you can do

    MsgBox(players("Jim").Age)

You can check if a player exists by

    If players.ContainsKey("Jim") Then
KingGold171 commented: The base of the dictionary storage helped implemted for the use within a structure. +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
Dim str As String = "user8:pass (190.82.87.11:3128)"

'you can split either at the blank or the "("

Dim userpass As String

userpass = str.Split()(0)        'results in "user8:pass"
userpass = str.Split("(")(0)     'results in "user8:pass "
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

There are several ways to do this. My preference (because this is where I have the most experience) is to use ADO (newer approaches use OLEDB). To do this try the following:

Create a blank project
Add a project reference to adodb by
Project -> Add Reference
Select .NET tab
Select adodb

Add a button named btnGetData
Copy in the following code

You will have to change a few things for when you run it on your computer. If you are using SQLEXPRESS then you should be ok with the current SERVER name. You will have to change the values for DATABASE and OUTFILE and most definitely you will need to change the names in the "select UserName..." statement.

Imports ADODB
Imports System.IO
Imports System.Data.SqlClient

Public Class Form1

    Const SERVER = ".\sqlexpress"       'the .\ refers to the local computer    
    Const DATABASE = "mydb"             'this is the name of my test database   
    Const OUTFILE = "D:\temp\out.txt"   'this is file that will be written      

    Private Sub btnGetData_Click(sender As System.Object, e As System.EventArgs) Handles btnGetData.Click

        Dim con As New ADODB.Connection     'this connects you to a server and database 
        Dim rec As New ADODB.Recordset      'this is where you get your data            

        'open a connection to the database and select some records

        con.Open("Driver={SQL Server};Server=" & SERVER & ";Database=" & DATABASE & ";Trusted_Connection=yes;")
        rec.Open("select UserName, DateIn from Test1", con, CursorTypeEnum.adOpenForwardOnly)

        'open an I/O channel to a file

        Dim fs As New FileStream("d:\temp\out.txt", FileMode.OpenOrCreate, FileAccess.Write)
        Dim sw As New StreamWriter(fs)

        'write …
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I've been watching The Firm and I had to laugh when the hacker was trying to decrypt the hard drive and he claimed that "parts of it were coming into focus". Also the comment that a particular hacking tool could get you 90% of the way to determining an encryption key. That's sort of like being able to get your wife 90% pregnant.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If I understand you, you want to select everything between "[" and "]". If that is the case then you can select just that text by

Dim ss As Integer = InStr(RichTextBox1.Text, "[")
Dim se As Integer = InStr(RichTextBox1.Text, "]")

RichTextBox1.SelectionStart = ss
RichTextBox1.SelectionLength = se - ss - 1

MsgBox(RichTextBox1.SelectedText)

But for this to work you must have "[" and "]" in the text. If you don't it will fail.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Unfortunately, there is no easy method to use for this. The Contains and ContainsKey (or even Find) methods do not search the listview for a given string. However, you can roll your own as follows:

Private Function InListView(lvw, text) As Boolean

    For Each item As ListViewItem In lvw.items
        If item.Text = text Then Return True
    Next

    Return False

End Function

If you pass this function a listview control and a string it will return True if that string appears in any cell in the first column, False otherwise. For example

Dim found As Boolean = InListView(MyListView, "Buffalo")
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

There are some useful constants defined in VB. Three of them are vbCr, vbLf and vbCrLf where Cr = carriage return and Lf = line feed. For the following example I created a RichTextBox control then pasted in a few paragraphs. Double clicking on any paragraph will select that paragraph. It does this by starting at the current cursor position (set when you click in the control), scanning backwards for the previous vbLf (or start of text), then scanning forward for the next vbLf (there will always be one because I add one to the end of a local copy of the text.

    Private Sub RichTextBox1_MouseDoubleClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles RichTextBox1.MouseDoubleClick

        'scan backwords from the cursor position to either the start of text or the start
        'of a paragraph (vbLf)

        Dim cp As Integer = RichTextBox1.SelectionStart     'current cursor position
        Dim ss As Integer = cp                              'selection start        
        Dim se As Integer = cp                              'selection end          

        Dim text As String = RichTextBox1.Text & vbLf       'note the added vbLf

        'find the previous and next line feed characters relative to the cursor position

        ss = InStrRev(text, vbLf, cp) + 1
        se = InStr(Mid(text, ss), vbLf) + ss

        'select the paragraph

        RichTextBox1.SelectionStart = ss - 1
        RichTextBox1.SelectionLength = se - ss

    End Sub
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

This code demonstrates how to add controls to a form at run time. The number of rows and columns, the spacing between the controls and the size of the controls are all determined by Consts, but this could easily be changed so that the parameters are user entered. My example adds two handlers to each textbox. I will be posting a refinement to this that uses a TableLayoutPanel to position the controls. Suggestions on how to improve this code are always welcome.

G_Waddell commented: useful +4
Stuugie commented: Nice code snippet for a noob like me. Thanks for taking the time. +1
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

In order to read your question I first have to download the zip file. Then I have to unzip it, only to discover that you have posted the information in a docx file, which my Word 2003 is incapable of reading (unless I go hunting for a plugin that Microsoft has posted somewhere to allow me to read docx files).

It would really be much easier if you would post your question (and related code, if any) in clear text in this thread. If you could do that I would be happy to have a look and reply if I have any advice to offer.

codeorder commented: You fell for the old .docx zipped file trick? LMAOO xD, though brownie point for taking the time to help someone lost, when it comes to asking a question. :) +12
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Docx files are created using newer versions of Microsoft Office Word. By adopting new file formats, Microsoft forces users of older versions of Word to upgrade needlessly thereby generating more obscene profits.

But I'm not bitter.

Begginnerdev commented: Ha! True, but funny! +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Create a listview control
Set the View property to Details
Right click on the control and select Edit Columns
Add (and name) the columns you need (let's make it 3 columns)
Declare a listviewitem variable

    Dim newitem As ListViewItem

For each row you want to add do

    newitem = New ListViewItem
    newitem.Text = "column 1 text"
    newitem.SubItems.Add("column 2 text")
    newitem.SubItems.Add("coumnl 3 text")
    ListView1.Items.Add(newitem)

For more info please see here

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

A much faster way to delete all records is "TRUNCATE TABLE tablename"

Begginnerdev commented: I didn't know this existed. Thanks Rev +5
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

The easiest way to modify Excel from VB is probably by using the Excel Application object. To do this,

1) start a new project
2) add a reference to "Microsoft Excel ##.# Object Library"
3) add "Imports Excel = Microsoft.Office.Interop.Excel" at the top of your code

You create the Excel object by

Dim xls As New Excel.Application

Open an existing workbook by

xls.Workbooks.Open("d:\my documents\points-jim.xls")

Create a reference to a particular sheet (for convenience) by

Dim sheet As Excel.Worksheet
sheet = xls.Workbooks(1).Worksheets(1)

You can access individual cells as

Dim row As Integer = 1
Dim col As Integer = 1

MsgBox(sheet.Cells(row, col).value)

I've attached a sample project which exports the data in a ListView control to an Excel spreadsheet. That should get you started.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

if you Import System.Text.RegularExpressions then you can use the following test

If RegEx.IsMatch(textbox.Text,"\d{4}\.\d{2}") Then
    'the text matches the pattern ####.##
Else
    MsgBox("the text must be in the form ####.##")
End If

'or if you don't want to do the import you can fully qualify as

If System.Text.RegularExpressions.RegEx.IsMatch(textbox.Text,"\d{4}\.\d{2}") Then
    'the text matches the pattern ####.##
Else
    MsgBox("the text must be in the form ####.##")
End If
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If you set the forms KeyPreview property to True you can use the following code

Public Class Form1

    Private Sub Form1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress

        If Me.ActiveControl.GetType = GetType(TextBox) Then

            Me.Text = e.KeyChar

            Select Case e.KeyChar
                Case "0" To "9"
                Case Chr(Keys.Back)
                Case Else
                    e.Handled = True
            End Select

        End If


    End Sub

End Class

This will restrict all textboxes on the form to 0-9 and backspace. If you need to add non-affected textboxes you can always set the Tag property on the restricted ones and test for that.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
Dim tokens() As String = "17:55:88".Split(":")

This will give you an array with indices from 0 to 2 where

tokens(0) = "17"
tokens(1) = "55"
tokens(2) = "88"
Mike Bishop commented: thanks for your help Jim much a +2
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Be yourself. The people who matter won't mind and those who mind don't matter. - Bernard Baruch

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Any sufficiently advanced technology will eventually be used as a cat toy.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

In that case you are misusing the term "exact". Unless you mean you want a result of 1 when the difference is exactly one year. If you are not interested in fractions of a year then do as was suggested and find the difference in days then take the integer portion and throw away the rest. That way you get the numbers

0-364 days = 0 years
365-729 days = 1 year
730-1094 days = 2 years
etc

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

The following code might do it

    Private Function CheckPassword(password As String) As String

        If Len(password) < 8 Or Len(password) > 15 Then Return "not 8-15 chars"
        If Not Regex.IsMatch(password, "[a-z]") Then Return "no lower case letters"
        If Not Regex.IsMatch(password, "[A-Z]") Then Return "no upper case letters"
        If Not Regex.IsMatch(password, "[0-9]") Then Return "no digits"
        If Regex.Matches(password, "[!,@,#,$,%,^,&,*,?,_,~,-,L,(,)]").Count > 1 Then Return "more than one special char"

        Return "OK"

    End Function

    Private Sub txtTestStr_Validating(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles txtTestStr.Validating

        Dim result = CheckPassword(txtTestStr.Text)

        If result = "OK" Then
            e.Cancel = False
        Else
            MsgBox(result)
            e.Cancel = True
        End If
    End Sub

I don't generally like doing things this way because it locks the user into a field until the criteria are satisfied. An alternative would be to add a label next to the password entry field and modify the text in the label to reflect the current password status (could be updated on each keystroke).

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If you are using a recent version of SQL server (2005 or newer) you can use the new ranking functions. Your specific query to generate the above results would be

SELECT TOP 5 RANK() OVER (ORDER BY IAVERAGE) AS Rank,
       USERNAME,ICOUNT,IAVERAGE,DATE_LOGGED
  FROM MyTable   
 WHERE IAVERAGE > 0 AND DATE_LOGGED='05-07-2012'

RANK() will generate a ranking number which will repeat for equal averages (all IAVERAGE numbers that are equal will have the same ranking number). If you wanted to further subdivide the rankings, you could always include a PARTITION clause as follows (let's assume you have a field named CLASSNUM)

SELECT TOP 5 RANK() OVER (PARTITION BY CLASSNUM ORDER BY IAVERAGE) AS Rank,

For this result set, the ranking number would be reset to 1 for each class.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Yesterday I clicked "Mark Forum Read" in the VB.Net forum. Today I am seeing articles for which the most recent postings are 2-3 days old being flagged as NEW.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

More complete - also write an Excel file:

Imports ADODB
Imports Microsoft.Office.Interop

Public Class Form1

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

        Dim con As New ADODB.Connection
        Dim rec As New ADODB.Recordset
        Dim xls As New Excel.Application
        Dim sheet As Excel.Worksheet

        xls.Workbooks.Add()
        sheet = xls.ActiveWorkbook.ActiveSheet

        con.Open("Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=D:\temp\asset.xls;")
        rec.Open("select * from [Sheet1$] where [Name] = 'Rahul'", con, CursorTypeEnum.adOpenStatic)

        Dim row As Integer = 0

        Do Until rec.EOF
            row += 1
            sheet.Cells(row, 1) = rec("Name").Value
            sheet.Cells(row, 2) = rec("Emailid").Value
            sheet.Cells(row, 3) = rec("Asset").Value
            rec.MoveNext()
        Loop

        rec.Close()
        con.Close()

        xls.ActiveWorkbook.SaveAs("D:\temp\test.xls")
        xls.Workbooks.Close()
        xls.Quit()

        releaseObject(sheet)
        releaseObject(xls)

    End Sub

    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

End Class
bigzos commented: works but shows the remaining rows too except thos ewith the specified name +2
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

~s.o.s~ Specifically, single quotes tended to screw up the display. Single line comments (beginning with a single quote) or line ending comments (again with a single quote). Here's an example

    Private Sub mnuLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuLoad.Click

        'prompt for a file name and load the resulting book library file

        dlgOpen.DefaultExt = ".bkl"
        dlgOpen.AddExtension = True
        dlgOpen.Filter = "Book Library Files|*.bkl"
        dlgOpen.FileName = ""

        If dlgOpen.ShowDialog() = Windows.Forms.DialogResult.OK Then
            LoadBookList(dlgOpen.FileName)
        End If

    End Sub
~s.o.s~ commented: Ah, I thought VB = vBulletin ! +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Post your code. When I used the following code it worked fine.

    Private Sub ListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        TextBox1.Text = ListBox1.SelectedIndex
    End Sub
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You can get the command line arguments in the collection My.Application.CommandLineArgs

Because you are passing the filename as an argument to your program, you would process it (open the file) in your form load event handler.

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I suggest you have a look at TrueCrypt. It is open source and free and I have used it for years. You can create an encrypted file of a user-specified size. Once the file has been created you mount it (via TrueCrypt) as a virtual drive then copy files to/from that drive just like you would any other drive. Files are automatically encrypted/decrypted on the fly. If the TrueCrypt file is examined via a hex editor, the data is indistinguishable from noise. You can find it at http://www.truecrypt.org/