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

So now it doesn't matter that the lines of code are out of sequence?

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

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

If sd is the SortedDictionary in my first response then

Dim newline As Integer = 0

For Each oldline As Integer In sd.Keys
    newline += 10
    ListBox1.Items.Add("N" & newline.ToString("0000") & sd(oldline))
Next

will add the code to ListBox1 with line numbers ranging from N0010 in increments of 10. Warning - if the old line numbers are used as the target of a GOTO then the GOTOs will point to the wrong lines after the resequencing.

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

Let me know how it goes. I had to avoid interlocks on many different automated processes that could not respond to pop-ups. It can get tricky.

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

An excellent document on printing can be found here

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

It converts information from hundreds of Excel documents into a few small text files

Let's assume your Excel files are named ss-0001.xls, ss-0002.xls, etc.

I'm guessing you have two processes at work here. One process runs independently of the GUI app and renders many Excel files into a few text files. This process runs whenever an Excel file is updated.

The second process is run by the user(s) and is used to load and update the Excel files. Let's assume two users modifying files ss-0001.xls and ss-0002.xls. User1 saves ss-0001.xls causing the generation of text files. User2 tries to save ss-0002.xls while the generator is reading it. This could be one source of the interlock.

One suggestion is that when user1 selects an Excel file for editing, that files is copied into a temporary file with a name like

ss-0001-user1.xls

All edits are done on the user specific version of the files. That way the generator can use only the non-user specific files. When the user wants to save the file, the changes get saved to the temp file. Once the file has been written, the save code then enters a loop that repeatedly tries to delete the original file. Once successful it then renames the temp file to the original name.

save temporary spreadsheet

do until original file deleted
    sleep for a short time
loop

rename temp file to original name

The file system watcher would be triggered on the appearance of the …

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

Actually, I think it's more likely they will run on water.

I have a boat that runs on water.

Our electricity here in Manitoba is relatively cheap, mostly hydroelectric and produced by a well managed public utility (thanks again Bob) with excellent staff (right Stuugie?). Unfortunately, electric/hybrid cars are so expensive that most people cannot justify the added cost up front.

And don't get me started on this BS about how when crude oil prices go down "it takes about three months for the cheaper oil to work through the system and result in lower prices at the pump" but an increase in crude is reflected at the pump the next day. According to the oil companies' reasoning and the current price of crude we should be paying around 95 cents a litre but we are actually paying around $1.25.

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

You can always add Encryption/Decrption to just the Password field if you like.

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

Try this

Public Class Form1

    Const INIFILE = "d:\utils\temp\test.ini"

    Structure Account
        Dim AcctName As String
        Dim Version As String
        Dim Login As String
        Dim Username As String
        Dim Password As String
        Dim Character As String
        Dim Server As String
        Dim ReturnLogin As String
        Dim LoginStart As String
        Dim RelogDisco As String
        Dim DisMap As String
        Dim SpecialAcc As String
    End Structure

    Private Accounts() As Account

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

    End Sub

    Private Sub btnRead_Click(sender As System.Object, e As System.EventArgs) Handles btnRead.Click

        Dim accts() As String = INIRead(INIFILE).Split(Chr(0))
        ReDim Accounts(UBound(accts) - 1)

        For i As Integer = 0 To UBound(accts) - 1
            Accounts(i).AcctName = accts(i)
            Accounts(i).Version = INIRead(INIFILE, accts(i), "Version")
            Accounts(i).Login = INIRead(INIFILE, accts(i), "Login")
            Accounts(i).Username = INIRead(INIFILE, accts(i), "Username")
            Accounts(i).Password = INIRead(INIFILE, accts(i), "Password")
            Accounts(i).Character = INIRead(INIFILE, accts(i), "Character")
            Accounts(i).Server = INIRead(INIFILE, accts(i), "Server")
            Accounts(i).ReturnLogin = INIRead(INIFILE, accts(i), "ReturnLogin")
            Accounts(i).LoginStart = INIRead(INIFILE, accts(i), "LoginStart")
            Accounts(i).RelogDisco = INIRead(INIFILE, accts(i), "RelogDisco")
            Accounts(i).DisMap = INIRead(INIFILE, accts(i), "DisMap")
            Accounts(i).SpecialAcc = INIRead(INIFILE, accts(i), "SpecialAcc")
        Next

    End Sub

    Private Sub btnWrite_Click(sender As System.Object, e As System.EventArgs) Handles btnWrite.Click

        For Each acct As Account In Accounts
            INIWrite(INIFILE, acct.AcctName, "Version", acct.Version)
            INIWrite(INIFILE, acct.AcctName, "Login", acct.Login)
            INIWrite(INIFILE, acct.AcctName, "Username", acct.Username)
            INIWrite(INIFILE, acct.AcctName, "Password", acct.Password)
            INIWrite(INIFILE, acct.AcctName, "Character", acct.Character)
            INIWrite(INIFILE, acct.AcctName, "Server", acct.Server)
            INIWrite(INIFILE, acct.AcctName, "ReturnLogin", acct.ReturnLogin)
            INIWrite(INIFILE, acct.AcctName, "LoginStart", acct.LoginStart)
            INIWrite(INIFILE, acct.AcctName, "RelogDisco", acct.RelogDisco)
            INIWrite(INIFILE, acct.AcctName, "DisMap", acct.DisMap)
            INIWrite(INIFILE, acct.AcctName, "SpecialAcc", acct.SpecialAcc)
        Next

    End Sub

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

In the case where you have parallel sections like [Account 0], [Account 1], etc and each section has the same settings, you could modify the inifile class with a new method to return the parallel items as arrays. It would look something like

    Public Function GetAllValues(sectionStarts As String, setting As String) As String()

        'create an array of all settings with the given setting name in sections
        'that start with the given string

        Dim settings As String = ""

        For Each section As String In m_inifile.Keys
            If section.StartsWith(sectionStarts) Then
                If m_inifile(section).ContainsKey(setting) Then
                    settings = settings & vbLf & m_inifile(section)(setting)
                End If
            End If
        Next

        Return settings.Substring(1).Split(vbLf)

    End Function

Note that with this code you would get the info as in

Dim versions() As String = ini.GetAllValues("[Account","Version)

Which returns an array of all version settings in sections which start with "[Account"

The return statement might look a little odd. It strips off the first vbLf before splitting to avoid returning an ampty element (you have to have one fewer delimiters than you have elements).

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

It was a dark and stormy night. OK. Not so stormy but it did rain and I was awake so I expanded on my earlier post. I'm going to post this code in three sections.

Part one is a rudimentary inifile Class. This class contains methods for reading/writing/maintaining an ini file. It could use some bulletproofing and such (see comments) but should be a good starting place for anyone who wants to tailor it to specific needs. Sections are identified by

[section]
setting=value
setting=value
.
.
.

blank lines and comments are not allowed. This is left as an excercise for the student (I hated that phrase when I was a student).

Imports System.IO

Public Class inifile

    '------------------------------------------------
    '  Name:
    '
    '    inifile.vb
    '
    '  Description:
    '
    '    Simple minded implementation of an inifile reader/writer class. The functionality is all
    '    here except that error checking is minimal, everythinig is case sensitive and there is
    '    no provision to maintain blank lines or comments.
    '
    '  Properties:
    '
    '    status - String - blank or a string indicating the nature of the error
    '
    '  Methods:
    '
    '    Read(filename)
    '
    '        Read the given inifile into memory
    '
    '    Write()
    '
    '        Write the in-memory inifile to the last read inifile on disk
    '
    '    Write(filename)
    '
    '        Write the in0memory inifile to the given file and make it the current file
    '
    '    GetValue(section,setting)
    '
    '        Return the value of the given setting …
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

The Form_Load event is raised when the form is loaded, not when the rendering is completed. That's just the way it is. What are you doing that requires you to wait until the form is rendered?

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

If I might offer a suggestion, a typical ini file has the form

[section]
setting=value
setting=value
[section]
setting=value
.
.
.

This form lends itself to a structure that can be easily represented using two nested dictionaries. If you are not familiar with dictionaries, they are objects consisting of key-value pairs. You can think of a dictionary as a type of array but where the index can be of any type and the value is the associated data. In this case, the outer one can be defined as

Dictionary(Of String, <settings>)

where the key is the section name and "?" will be the settings from the ini file from within that section. Because the settings are also key-value pairs, they can also be stored as a dictionary except this dictionary will consist of a pair of strings. So the complete ini file can be stored in the following

Dim inifile As New Dictionary(Of String, Dictionary(Of String, String))

To add an item to a Dictionary you use the Add method. So to add a new section (let's call it "[FolderList]") you use

inifile.Add("FolderList]", New Dictionary(Of String, String))

Let's say there is a setting under this section such as

LastUsed=D:\Temp

To add this setting to inifile you code

inifile("[FolderList]").Add("LastUsed","D:\Temp")

I've written a simple class to do a couple of the operations. The Write method writes only to the debug window, not to the actual file. Note that it encrypts the "value" portion only. The inifile …

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

To add encryption of the ini file you could try changing the IO code as follows

Public Function INIRead(ByVal INIPath As String, ByVal SectionName As String, _
    ByVal KeyName As String, ByVal DefaultValue As String) As String

    ' primary version of call gets single value given all parameters

    Dim n As Int32
    Dim sData As String

    sData = Space$(1024) ' allocate some room
    n = GetPrivateProfileString(SectionName, KeyName, DefaultValue, sData, sData.Length, INIPath)

    INIRead = IIF(n > 0, Decrypt(sData.Substring(0, n)), "")

End Function

Public Sub INIWrite(ByVal INIPath As String, ByVal SectionName As String, _
    ByVal KeyName As String, ByVal TheValue As String)

    Call WritePrivateProfileString(Encrypt(SectionName), Encrypt(KeyName), Encrypt(TheValue), INIPath)

End Sub

Public Sub INIDelete(ByVal INIPath As String, ByVal SectionName As String, _
    ByVal KeyName As String) ' delete single line from section

    Call WritePrivateProfileString(Encrypt(SectionName), Encrypt(KeyName), Nothing, INIPath)

End Sub

Public Sub INIDelete(ByVal INIPath As String, ByVal SectionName As String)

    Call WritePrivateProfileString(Encrypt(SectionName), Nothing, Nothing, INIPath)

End Sub    

using the Encrypt/Decrypt code you already have. Or you may only want to encrypt the actual values in which case you could see the ini file in a form that would allow you to ensure it is well formatted bur still obfuscate the values. You may have to modify the encrypt/decrypt code to handle the case where a value is "Nothing"

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

I did not realize that it was as requirement of this site to post fully documented code

It is not a requirement to post fully documented code but my feeling is that because we usually do not know the level of expertise of the OP it is better to add a few comments to make it easier to follow the logic of the code. Please note my use of the word "some".

a simple sort was probably not a good idea as it could easily make a bad situation worse

You are correct to have pointed this out. And let me say again, your efforts are appreciated.

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

Would you please add some comments/documentation as to what this code is doing other than "look for inconsistencies" and "invokes a reordering logic"? Your code is appreciated but it would be even better if the mechanics were explained.

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

What events on form2 are firing before the form is displayed?

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

No problem. Glad we were finally able to connect.

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

Try this

Public Class Form1

    Private Sub btnAddNumbers_Click(sender As System.Object, e As System.EventArgs) Handles btnAddNumbers.Click

        If IsNumeric(TextBox1.Text) And IsNumeric(TextBox2.Text) Then
            Dim item As New ListViewItem(TextBox1.Text)
            item.SubItems.Add(TextBox2.Text)
            ListView1.Items.Add(item)
        Else
            MsgBox("please enter two numbers")
        End If

    End Sub


    Private Sub btnCalc_Click(sender As System.Object, e As System.EventArgs) Handles btnCalc.Click

        'add one column for the row number,
        '    one column for each row in listview1
        '    one column for the row total

        For i As Integer = 1 To ListView1.Items.Count + 2
            Dim header As New ColumnHeader
            header.Text = "Column" & i
            ListView2.Columns.Add(header)
        Next

        'add some rows to listview2

        For i As Integer = 1 To 10
            ListView2.Items.Add(i)
        Next

        'Do the calculations. One column will be added to ListView2 for each row in ListView1.
        'That column will be (T1 + T2)/row# where T1 and T2 are from columns 1 and 2 in ListView1.
        'The rightmost column will be the sum of all previous columns excluding the first.

        For row2 As Integer = 1 To ListView2.Items.Count

            Dim total As Double = 0.0

            For Each row1 As ListViewItem In ListView1.Items
                Dim val As Double = (CDbl(row1.SubItems(0).Text) + CDbl(row1.SubItems(1).Text)) / CDbl(row2)
                ListView2.Items(row2 - 1).SubItems.Add(val)
                total += val
            Next

            ListView2.Items(row2 - 1).SubItems.Add(total)

        Next

    End Sub

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

I am trying to understand what you want to accomplish here but I think there is a real disconnect between your explanation and the code so let's just scrap the code for now. Forget TextBoxes, ListViews, etc. and just tell me in English what you are trying to do. Pretend that computers do not exist and you are doing it entirely by hand with pencil and paper. What I gather is that you have two numbers which, for the sake of convenience, we'll call T1 and T2 (any resemblance to TextBox1 and TextBox2 is entirely intentional). You also have a table which contains ten rows (but which may contain more or fewer). I don't know how many columns are in this table. The best way, I think, to make your intentions clear is to show me an example of what your table looks like prior to doing any calculations, then show me what it looks like after the calculations are done. Be very clear on what you want because saying "I want the total of the rows" and "I want the total of each row" are entirely different things. If we can get through the explanation without referring to code or computers then I think we can nail this down. For example, I might say:

I have two numbers, T1 and T2, and a table of a variable number of rows. Column one contains a row number and column two contains a dollar amount. I want to calculate column three …

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

Instead of using the FileOk event, get the file name, etc by using ShowDialog. This prevents further processing until the file dialog is closed.

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

        If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then

            Dim dbfFileFolder As String = System.IO.Path.GetDirectoryName(OpenFileDialog1.FileName)
            Dim dbfFileName As String = System.IO.Path.GetFileName(OpenFileDialog1.FileName)
            Dim dbfFileNameShort As String = System.IO.Path.GetFileNameWithoutExtension(OpenFileDialog1.FileName)

            If dbfFileName = "GNDITEM.DBF" Then
                frmFileCheck.Show() 'this is my Form2
            End If

        End If

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

You should check if the entry fields are numeric. Also, you can simplify the if-elseif block as follows

If Not IsNumeric(TextBox1.Text) Then
    MsgBox("please enter a numeric value in textbox1")
    Exit Sub
End If

If Not IsNumeric(TextBox2.Text) Then
    MsgBox("please enter a numeric value in textbox2")
    Exit Sub
End If

.
.
.

If t <= 270.0 Then
    MsgBox("Flight in these conditions is impossible. Please enter the value of Temperature Greater than 270K")
ElseIf mach <= 0.3 Then
    .
    .
    .
ElseIf mach <= 1.0 Then
    .
    .
    .
ElseIf mach <= 5.0 Then
    .
    .
    .
Else
    .
    .
    .
End If

Note that in the first "If" I compare t to 270.0 rather than TextBox1.Text. The way you are doing it compares a numeric value to a string value which will not give you the results you want.

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

I'll check out the LGPL version of QT in September when I get back from the cottage. A 1.7 gig download is a tad large for summer bandwidth. Thanks for the suggestion.

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

You could try setting the Opacity property of the main form to something like 0.5 just before you you display the modal form, then set it back to 1.0 on return.

Me.Opacity = 0.5
form1.ShowDialog()
Me.Opacity = 1.0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

My original point was that I think Python is an excellent language that, if I had been aware of it twelve years ago, I would have used instead of vbScript. It would have saved me countless hours of development. I think it is an excellent language for beginners as well as seasoned professionals. My second point was that unless you are willing to pay for something like QT, developing a GUI based app in Python can be daunting. At least that was the case for me.

You seem to feel that VB apps are to be frowned upon. I fail to see why a well written application in any language should be looked down upon. I believe Sturgeon's Law still holds. Ninety percent of everything is crap. That applies equally to VB, C, C++, even Python. Blame the programmer, not the platform.

In any case, we are probably getting off topic.

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

The only GUI development I have done using Python was with either wxPython or Tkinter. I may be mistaken but I believe you have to by QT, whereas Visual Studio Express is free. The first actual GUI app I developed was a Load Advisory Program for our control centre (in C under OS/2). No tools, and all GUI elements had to be coded by hand. It was brutal. In my opinion, the tools you use to develop programs are at least as important as the underlying language. Few would be developing VB.net apps with GUIs without using an environment that removes the grunt work of placing visual elements, or an interactive debugger that supports breakpoints and step-by-step source level debugging.

Nice to see you back. I hope the move went well.

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

I started scripting around the year 2000. I had been a professional programmer for around 25 years. None of my code required a user interface and the ability to inspect/modify code at three in the morning was critical so vbScript filled the bill. It was free and required no special IDE. Had I known about Python at the time I might have used it instead of vbScript. Using Python as implemented today I could have cut my programming time in half and my consumption of antacids by even more.

However, that was because my apps required no GUI. Developing apps in Python requiring a GUI is painful in the extreme. Using wxPython, everything must be done by hand and little of it is intuitive. Developing a GUI in VB.net on the other hand is almost trivial in comparison.

Based on my experience, Python is an outstanding first language and it maintains its appeal even to veteran programmers. But if your goal is to develop any kind of serious GUI, be prepared to invest a lot of time in learning details which you should not have to be concerned about.

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

It's always a good idea to state specifically what you are trying to do. What you have done is say that you are trying to do some math, then shown us uncommented code. Having said that, I would use double rather than decimal.

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

Anyone ever notice in Castle that Beckett wears high heels, but when there is a chase scene her shoes mysteriously change to no-heels?

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

How many items do you have in your datagrid and what do you define as "slow"? How long is it taking to complete the loop? Do you get consistent times on successive runs? Do you have anything else running that could be sucking back CPU cycles?

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

Semantics.

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

I tried your code (after adding the control to the form) and it worked just fine. Newline and paste worked as expected. What version of VB are you using?

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

The OP asked about msconfig settings so I based my answer on that. msconfig is not merely a diagnostic tool. It can be used to enable/disable programs to start automatically. It can also be used to disable the default "idiot light" display at startup. I like to see drivers identified as they are loaded. Msconfig lets me set that option. There are other tools that do thiss better (autoruns from SysInternals, for example), but again, the OP asked about msconfig.

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

Can you clarify

However wrapping occurs (ie) when I finish the like till the end

The code you show to create the RichTextBox is incomplete so it is hard to give an informed answer. There should be no way to access the created control(s) through the GUI because you haven't added the new control to the form. I assume this code exists elsewhere. If so then you should include it in your posting.

You should also declare c as the correct control type as in

Dim c As New RichTextBox
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

In that case use

file_name.LastIndexOf("\bin")) & "\" & EIDCardNr.Text & "."
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Assuming you have the card number stored in a variable named EIDCardNo, just replace your line

file_name.LastIndexOf("\bin")) & "\test."

with

file_name.LastIndexOf("\bin")) & "\" & EIDCardNo & "."
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Glad to be of help. Please remember to mark this thread as solved if it works out for you.

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

Most of my database experience has been in real-time processing where getting the data into the database was the most important step. Displaying the data was secondary because of processes downstream that required access to current data. In my case I was dealing with more than 8000 records at a time. My preference would be to insert the records into the database first, then populate the datagridview via a query to fetch the most recent records from the database.

I should add that my database inserts were done, for speed reasons, using the SQL bulk insert capability - something which is not available (as far as I know) in Access. Incidentally, when you ran your timing tests, did you use SuspendLayout and ResumeLayout? Doing a suspend before adding the records, then resume following would speed up the process by stopping the control from updating until all the records have been added.

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

Testing attach of two image files. Well bite me. Now if works. Here's the two files.

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

I would very much like to attach the two sample pictures but for some reason I cannot. Trust me. The first picture has columns headers and the second one does not.

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

If you just want to index by number and you know how many items there are in the list then you can just use an array as in

Dim allelements As HtmlElementCollection = MbFacebookBrowser.Document.GetElementsByTagName("span")
Dim labels(3) As String
Dim item As Integer = 0

For Each DD As HtmlElement In allelements
    If DD.OuterHtml.Contains("resource") Then
        TlsResourceComboBox.Items.Add(DD.GetAttribute("InnerText"))
        labels(item) = DD.GetAttribute("InnerText"))
        item += 1
    End If
Next

LblHel.Text = labels(0)
LblIro.Text = labels(1)
LblOxy.Text = labels(2)
LblWat.Text = labels(3)

'this will crash if there are more than four "resource" elements
'you could also do

Dim allelements As HtmlElementCollection = MbFacebookBrowser.Document.GetElementsByTagName("span")
Dim item As Integer = 0

For Each DD As HtmlElement In allelements

    If DD.OuterHtml.Contains("resource") Then

        TlsResourceComboBox.Items.Add(DD.GetAttribute("InnerText"))

        Select Case item
            Case 0: LblHel.Text = DD.GetAttribute("InnerText"))
            Case 1: LblIro.Text = DD.GetAttribute("InnerText"))
            Case 2: LblOxy.Text = DD.GetAttribute("InnerText"))
            Case 3: LblWat.Text = DD.GetAttribute("InnerText"))
        End Select

        item += 1

    End If

Next

'that would ignore any additional resource elements
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You can use a Dictionary to store things. A Dictionary consists of name/value pairs where the name is used as the index (key). The value part can be of any type, even objects and custom classes. When you create a dictionary object you declare the type of the key and value as follows

Dim mydict As New Dictionary(Of <type>, <type>)

For example you could declare a dictionary to hole employee names keyed by employee number as follows:

Dim empdict As New Dictionary(Of Integer, String)

and you would add entries as

empdict.Add(1024, "Jetson, George")

You can access the values as

Msgbox(empdict(1024))

Check out the documentation for all the features.

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

body &= vbCrLf should work. If your email format is HTML then try body &= "<br>"

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