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

if its possible to make an editor like Notepad++

Certainly it is. But why do you want to reinvent the wheel when there are editors out there that will do this already?

Please help with what you can even if you can give me bits and peices to make the script myself.

We are not going to write it for you. That's not what this forum is for. However, if you make an attempt to write it yourself we can help you out with the problem areas. It might help to know your level of expertise.

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

If you don't want to return an exit code then you can just let it run off the end of the Main sub. If you want to set an exit code I think the process is

System.Environment.ExItCode = 7
System.Environment.Exit

Replace 7 with your exit code of choice.

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

You use SELECT DISTINCT when retrieving one field only and the syntax is

SELECT DISTINCT(fieldname) FROM tablename
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You can also name a node. For example, let's give the node a name equal to the value. Then you can refer to nodes by name as in

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

        'add a root node, then add two child nodes

        trvTree.Nodes.Add(MakeNode("1"))
        trvTree.Nodes("1").Nodes.Add(MakeNode("2"))
        trvTree.Nodes("1").Nodes.Add(MakeNode("3"))

        'add a child node under node "2" and one under node "3"

        trvTree.Nodes("1").Nodes("2").Nodes.Add(MakeNode("2.1"))
        trvTree.Nodes("1").Nodes("3").Nodes.Add(MakeNode("3.1"))

        trvTree.ExpandAll()

    End Sub

    Private Function MakeNode(value As String) As TreeNode
        Dim node As New TreeNode(value)
        node.Name = value
        Return node
    End Function
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

What do you mean by (2,3)? Do you mean two child nodes at the same level as in

node 1
|
-- node 2
|
-- node 3

Can you please show us the code you are using? To ad nodes to any node in the tree you just reference that node's Nodes collection. Try this with an empty tree

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

        'add a root node, then add two child nodes

        trvTree.Nodes.Add(New TreeNode("1"))
        trvTree.Nodes(0).Nodes.Add(New TreeNode("2"))
        trvTree.Nodes(0).Nodes.Add(New TreeNode("3"))

        'add a child node under node "2" and one under node "3"

        trvTree.Nodes(0).Nodes(0).Nodes.Add(New TreeNode("2.1"))
        trvTree.Nodes(0).Nodes(1).Nodes.Add(New TreeNode("3.1"))

        trvTree.ExpandAll()

    End Sub
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
DataGridView1.Columns(1).Visible = False

Just substitute the appropriate zero-relative column number.

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

' isn't a wildcard character. If you take the string "D'Souza" and change it to "D''Souza" then it will go into the table as "D'Souza".

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

In order to prevent errors on ' all you have to do is replace each ' with two '. Instead of using

name

use

name.Replace("'","''")

If you do that SQL won't complain.

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

What was the output from the Debug.WriteLine I suggested?

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

I'm not familiar with portable VB but the line

If Text1.Text = Label1.BackColor = Values(0) Then

in standard VB should be written

If a = b And b = c Then

and in my edition (VB 2010), you can't compare a string (Text1.Text) to a Color. That would explain the Type mismatch.

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

When you get the message "variable not defined", the message identifies the variable that it is flagging. It also gives you the specific line that generated the error. I'm not going to play 20 questions. If you want help then please provide complete information. Having said that, I suspect your first error was on line 16 because you reference the array, Values, which is defined in Command1_Click but goes out of scope when you exit the sub. If you want to use Values in multiple subs/functions then you have to move it to have module scope, like "score".

I have another problem with your code. You have subs like Command1_Click and Form_Load but none of them have standard parameter lists or "Handles" qualifiers. What version of VB are you using?

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

What variable is it complaining about? Please post the exact text of the error message. Also, please use the "Code" tool to insert code that is properly formatted.

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

You can try SELECT DISTINCT rather than just SELECT.

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

You got it.

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

I did set the background of the textbox to transparent. Didn't help. As far as the SetStyle call is concerned, it is applied to the control (textbox), not the form. All it really appears to do is enable setting the BG color of the textbox to Color.Transparent without generating an error. Other than that, there doesn't appear to be any effect.

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

Because the code in the Finally is always executed you might wonder what's the point. The point is that the code in the Finally block is logically associated with the code in the Try and Catch blocks. If you saw

Try
    'some statements
Catch ex As Exception
    'some more statements
End Try

'some other statements

You might (at some point) either be tempted to insert more code after the End Try, or move the code after the End Try somewhere else. However, if you saw

Try
    'some statements
Catch ex As Exception
    'some more statements
Finally
    'some other statements
End Try

you would know immediately that "some other statements" is associated with "some statements" and "some more statements". Typically, the Finally block contains cleanup code. For example, if, in the Try block, you opened one or more files, you'd want to close those files whether or not an exception occurs. Rather than duplicate this code in the Try and Catch blocks, you place it in the Finally block.

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

There is a way to enable Transparent color in a control but it has to be done in the Constructor (New). You don't have access to the constructor for the built in controls but you can subclass any control and add

Me.SetStyle(ControlStyles.SupportsTransparentBackColor,True)

to the constructor for that control. However, I gave this a try and still ended up with a non-transparent control. Either I did it incorrectly (thank you Microsoft for not providing an example) or the info I read was incorrect (thank you again Microsoft). If anyone has a further suggestion I'd be interested to know where (or if) I went wrong.

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

Public Class Form1

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

        Dim text As String = System.IO.File.ReadAllText("d:\temp\test.html")

        Dim pattern1 As String = "<h4><b>File Name:</b>(.*)</h4>"
        Dim m As Match = Regex.Match(text, pattern1)

        If m.Success Then
            MsgBox(m.Groups(1).Value)
        End If

    End Sub

End Class

The regular expression, pattern1 will match the required line. Note that part of the pattern consists of "(.*)". This is defined as a sub-pattern. The Match object, m, will contain two groups. The value of group one is the entire matched string. The value of group 2 will be the value of the sub-pattern, or the string you want to extract.

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

In the following code, the Debug.WriteLine gets executed with visible results but the "Click" message is never displayed. I find that just a little odd.

    Private Sub Form1_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        MsgBox("FormClosed")
    End Sub

    Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        MsgBox("FormClosing")
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Me.Close()
        Debug.WriteLine("click")
        MsgBox("Click")
    End Sub
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

When you execute Me.Close() it raises the FormClosing event. In the FormClosing handler you can choose to cancel the close by executing

e.Cancel = True

If you do not then the next event to get raised is FormClosed. The code following Me.Close() never gets executed. You can check this by adding the following:

Private Sub Form1_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
    MsgBox("FormClosed")
End Sub

Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    MsgBox("FormClosing")
End Sub

Then somewhere else you can add

Me.Close()
MsgBox("after Me.Close()")

You'll never see the "after" message unless you set e.Cancel = True in FormClosing

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

And does it still get duplicate items? If so, I suggest you add a

Debug.WriteLine(MyDataTable.Rows(Rno)("Script_Name"))

inside the loop just above the Add to see if the problem is with your DataTable.

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

I recommend using the supplied enums like DateInterval.Day. You can run into confusion when using the older string ("D", etc) designation. For example, does "M" mean minutes or months?

Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
DateAdd(DateInterval.Day,-1,Now())

The first parameter is the interval and you can specify other values for month, year, etc.

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

cboScrip.Items.Clear() is the correct call to clear all items. I suggest you put the Clear just above the code that populates the combobox.

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

One thing you can do is to display a message to the user stating that some email systems with aggressive spam filters may block the receipt of your email. You could warn them to either whitelist your address or check the spam box.

Alternately, you could send two messages. One would be the receipt and the other could be a generic (no suspicious keywords or phrases) saying that a receipt has been sent and if it is not received in a specified time frame that it was likely blocked by a spam filter. That email should contain an address to reply to if the receipt was not received.

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

Assuming that your program doesn't start until after all other startup programs have run then you can have a class variable such as

    Private tasks As New Dictionary(Of Integer, String)

And you can populate it with the current list of process IDs and names by

    For Each proc As System.Diagnostics.Process In System.Diagnostics.Process.GetProcesses
        tasks.Add(proc.Id, proc.ProcessName)
    Next

You need to use the process ID as the key because it is guaranteed to be unique. In your timer handler you can do

    For Each proc As System.Diagnostics.Process In System.Diagnostics.Process.GetProcesses
        If Not tasks.ContainsKey(proc.Id) Then
            MsgBox("closing on task " & proc.ProcessName)
            Me.Close()
        End If
    Next

But in production you would remove the MsgBox.

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

Is it also possible to stop it when I start up another programm ?

A particular program? Is it one that you have the source code for? You could always create a cmd file to start that particular program then create a shortcut to the cmd file and always start it from that. The cmd file could have a line to kill your program and another to start the requested program.

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

Problems:

  1. No comments
  2. No description of any kind as to what you want to do
  3. Incomplete error message
  4. No posting of the value of sampque
daniel955 commented: Yup +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Before I give my opinion on that, let's look at how downloads occur.

Your computer requests a file from a remote computer

The remote computer sends the file via TCP/IP. This protocol has resend logic built in such that packets that are not received or are corrupted are resent. The protocol also ensures that the sent packets are reconstructed in the correct order.

The speed at which the file is transferred depends on several things such as

  • the speed of your internet connection
  • the reliability (noise, etc) of your internet connection
  • the current load on the sending computer
  • the current load on your computer

If your connection is maxxed out (perhaps you are running a bittorrent) then your download speed is limited by that.

If the sending computer is maxxed out (either serving other users or doing some other task) then your download speed is limited by that.

If your connection is very noisy and packets are continuously being resent then your download speed is limited by that.

In the case of bittorrent transfers, faster download speeds are achieved by dividing the requested file (or files) into pieces. These pieces can be downloaded from multiple servers (thereby avoiding the server-under-load problem). This requires some coordination so that all of the other bittorrent clients can send different pieces at the same time. Note that if your computer was the only one running bittorrent software you would get absolutely no use out of it. It would be like being the only …

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

Could be an overheating problem. Games are much more CPU intensive and cause your system to run hotter.

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

I can see one problem. The strings in your example all end in ".". Therefore, the key, "apple.", exists in the dictionary, but the key, "apple", does not. I should also point out that the keys are case sensitive. Thus, settings("apple") and settings("APPLE") refer to two different values. To see if a particular key exists you can use the ContainsKey method as in

If settings.ContainsKey("apple") Then
    'do something
Else
    'do somethinig else
End If

One way to prevent problems with case sensitivity is to force all keys to lower (or upper) case before adding them to the dictionary. The, when you check if a key exists, do the same in the test as in

If settings.ContainsKey(LCase(TextBox1.Text)) Then
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You don't have to search a dictionary. If you want the string corresponding to "apple" just do

Dim result As String = settings("apple")

result will end up with the value "a fruit" and

Dim nextresult As String = settings(settings("apple"))

will set nextresult to "an example of a fruit would be an apple"

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

In that case the dictionary code above should do the trick. You'll only have to process the text file once to get the [] and () key-value pairs into the dictionary. Sorry for the earlier typo.

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

I just noticed a horrible typo in my regex sample. The Split should have read

line = line.Split("]")(1)

My originial post (which I have since corrected) split on "[".

If the values between "[" and "]" are unique within the file then you can use a dictionary as

    Dim settings As New Dictionary(Of String, String)

    Dim parenth As String = "\(.*\)"                'matches "(any text)"
    Dim pattern As String = "^\[.*\].*\(.*\).*"     'matches "[any text] any text (any text)"

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

        If Regex.IsMatch(line, pattern) Then

            'split on closing square bracket

            Dim flds() As String = line.Split("]")

            'get text between "[" and "]"

            Dim key As String = flds(0).Substring(1)

            'get text between "(" and ")"

            Dim val As String = Regex.Match(flds(1), parenth).Value
            val = val.Substring(1, Len(val) - 2)

            settings.Add(key, val)

        End If

    Next

    For Each key As String In settings.Keys
        TextBox1.AppendText(key & " = " & settings(key) & vbCrLf)
    Next

And this time I tested the code for typos. Of course, you would declare the dictionary at the class level otherwise it would exist only within the given sub or function. To get the value of any of the entries yopu would index the dictionary like and array but use the string from [mystring] as the index as in

Dim item As String = settings("some string")
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

In that case I misunderstand what it is you are trying to do. Perhaps if you posted a sample input file and told me explicitly what strings you are trying to extract.

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

I avoided the use of regular expressions in my original answer because they can be a bit off-putting to people unfamiliar with the concept.

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

When I used to work for a living I would get requests from my users to write programs or to modify existing ones. My usual first response was to write up, in my own terms, what it was I thought they were asking for. I would ask them to either confirm or clarify based on my description. I found this was less time consuming in the long run than asking a lot of questions. So let me try that here. This what I think you want to do:

You have a file containing lines of text. Some (maybe just one, perhaps many) lines consist of a string enclosed in square brackets followed by a string in parentheses. You want to process all lines in the file. For each line starting with

[some arbitrary text]

You want to extract the text between the "(" and ")" on the same line. I'm going to suggest a method that is different from the previous suggestions but will be more robust. It involves the use of regular expressions. If you are unfamiliar with regular expressions, in the simplest sense, they are a way of describing a pattern. It may sound complicated at first but for what you want to do it is fairly simple. In your case, the pattern in English would be

A left square bracket followed by an arbitrary number of characters followed by a right square bracket followed by an arbitrary number of characters followed by a left parenthesis followed by …

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

And if each line is different then

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

    Dim lb As Integer = InStr(line, "[")
    Dim rb As Integer = InStr(line, "]")

    'make sure line has "[" followed by "]"

    If lb > 0 And rb > 0 And rb > lb Then
        MsgBox(Trim(line.Substring(rb)))
    End If

Next

And you can use your method of choice to get at the text following the "]"

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

I just used "line" as a generic string variable.

For Each line As String in myLines
    MsgBox(Trim(line.Split("]")(1)))
Next

Would display the requested text from each matching line.

line.Split("]")

splits the line into two strings using "]" as the delimiter

line.Split("]")(1)

takes the second element of the resulting array and

Trim(line.Split("]")(1))

removes leading and trailing blanks.

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

You can read the entire file into a string array as

Dim allLines() As String = System.IO.File.ReadAllLines(MYFILE)

and you can extract the "interesting" lines as

Dim myLines() As String = Filter(allLines,"[String I'm searching for]")

The array, myLines, will contain only the lines from allLines containing the given string. Filter takes two additional (optional) parameters. Parameter 3, if given, is a boolean value. If True then all lines containing the string are returned. If False then all lines NOT containing the string are returned. Parameter 4 can be either CompareMethod.Text (case insensitive) or CompareMethod.Binary (case sensitive).

Once you have a matching line you can get the part you want either by

line.Substring(InStr(line,"(")-1)

or

Trim(line.Split("]")(1))

The first version will fail if there is no text following the matched string. The second version will correctly return a zero-length string.

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

Sample input and output please.

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

Simple types such as Integer, Boolean, etc (i.e. types that do not require instantiation with "New") are value types. Anything that is used to access an object is a reference type. In your example, Graphics refers to an object (as indicated by the fact that you can access methods/properties via dot notation).

Short answer - YES.

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

You don't need quote characters around numeric fields.

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

Audacity is free and open source, and it is available on multiple platorms. You do not need a video converter for mp3 files. You can load the file into Audacity and export each section as a separate mp3 file. I suggest you make a copy of your original file and play with the copy. It's easy to make an irreversible mistake when getting used to an unfamiliar application.

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

The following gets a value from the registry. Normally it is set to 3. If you set it to 4 then USB access will be denied. However, setting the value requires admin access.

My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\USBSTOR\","Start",0)

To set a new value use

My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\USBSTOR\","Start",4,Microsoft.Win32.RegistryValueKind.DWord)
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
Dim lines() As String = System.IO.File.ReadAllLines(myfile)

For Each line As String In Filter(lines,IdBox.Text)
    Dim fields() As String = line.Split(vbTab)
    MsgBox(fields(1) & " " & fields(2))
Next

Filter returns all lines containing the given text.

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

Just replace the delimiter character with vbTab as in

Dim fields() As String = sline.Split(vbTab)
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Use the Leave event in the first textbox as in

Private Sub TextBox1_Leave(sender As Object, e As System.EventArgs) Handles TextBox1.Leave
    TextBox2.Text = TextBox1.Text
    TextBox3.Text = TextBox1.Text
End Sub

This code will be executed as soon as the user leaves the TextBox1 control.

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

Declare a variable with Class scope and save a reference to the textbox in that variable. The proper way to create the control is as follows:

mytextbox = New TextBox()
mytextbox.Location = New Point(130,y)
Me.Controls.Add(mytextbox)

Then to get the entered text just use

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

You only need Application.DoEvents() if you are in a lengthy loop. You aren't doing any loops here so don't use it.

oSheet = oBook.Worksheets(1)

You don't need this inside the With at line 19. It's already been set outside on line 17.

If you are setting the values of single cells then use the Cells(row,col) property instead of Range. Row and col are integers and are one-relative.

Don't use myProcess.Kill to terminate Excel. This will kill all running copies and will severely piss off users who happen to have Excel already open (especially if they have unsaved data). Once your Excel processing is done, close the workbook and then quit the Excel application.

Try these suggestions and see if you still have a problem.