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

Sure. Take the console app:

Module Module1

    Sub Main()

        Dim password As String = "mypass"
        Console.WriteLine("password=" & password)

        password = Chr(115)
        password &= Chr(101)
        password &= Chr(99)
        password &= Chr(114)
        password &= Chr(101)
        password &= Chr(116)
        Console.WriteLine("password=" & password)

    End Sub

End Module

When you run it you will get the output

password=mypass
password=secret

If you extract the string values from the exe file (I use strings.exe, a tool from the excellent SysInternals Suite available free here) you can see the string "mypass" but not the constructed string "secret".

Please note that if you build "secret" in one line of code like

password = Chr(115) & Chr(101) & Chr(99) & Chr(114) & Chr(101) & Chr(116)

The compiler will optimize this to

password = "secret"

and, therefore, the string will be available for detection. The above method does not prevent someone extracting the string by examining the machine code with a disassembler or a debugger but it does add a level of obfuscation to prevent casual sleuthing.

ryklon commented: Your explanation is good. +1
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You might want to check out the FileSystemWatcher control. I think it is better to let the system notify you of changes than to continuously poll the system. Wrox Press Visual Basic 2008 Programmer's Reference says:

The FileSystemWatcher class keeps an eye on part of the file system and raises events to let your program know if something changes. For example, you could make a FileSystemWatcher monitor a work directory. When a new file with a .job extension arrives, the watcher could raise an event and your application could process the file.

The FileSystemWatcher class’s constructor takes parameters that tell it which directory to watch and that give it a filter for selecting files to watch. For example, the filter might be “ *.txt ” to watch for changes to text files. The default filter is “ *.* ” , which catches changes to all files that have an extension.

Set the filter to the empty string “ ” to catch changes to all files including those without extensions.

The NotifyFilter property "Determines the types of changes that the watcher reports. This is a combination of values defined by the NotifyFilters enumeration and can include the values Attributes, CreationTime, DirectoryName, FileName, LastAccess, LastWrite, Security, and Size.

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

Would it be a big deal to add an option to the Search to restrict results to the current forum only? When I am on the VB.net forum, for example, and I do a search, I am interested in results in the VB.Net forum only.

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

To Dan:

The OP merely asked how computer shops install or reinstall Windows (of various flavours). It seems to me that by offering more than just the latest and greatest version of an OS (Windows/Linux/whatever) they WILL attract customers. In my former life (pre-retirement) I was frequently called upon to support applications that would not run on the "latest and greatest". Believe it or not, in 2008 I was still providing support on a custom app that would not run on anything newer than Windows 98. I, myself, have a piece of hardware (Plextor TV tuner) that will run only under Windows XP. As such, I plan to keep my old IBM ThinkPad (XP Pro) running for as long as I possibly can.

That doesn't prevent me from moving along with the tide into the era of Windows 7. That also does not mean that users who choose, for whatever reason, to remain with Windows XP should be left high and dry. Any computer shop that followed your reasoning would, in my opinion, LOSE customers. The way to attract customers, especially in this economy is to provide BETTER service than your competitors.

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

textbox.Text = (timer1.Elapsed + timer2.Elapsed).ToString

thedonedeal commented: This one works. +2
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

It specifies the actual filename of the SQL database. I have never used this parameter. I specify the server name and database name and let SQL server figure out where the file is stored.

I was a SQL db Administrator (among many other rthings) before I retired, and there were a couple of times when I had to move our database files from one disk to another. Any applications that used the attachdb parameter to connect would have failed. None of them did. I can't think of any reason you would want to use it either.

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

You could use an Access database or an Excel spreadsheet. There are connection strings available for both of these. Even CSV files as I recall.

bilal_fazlani commented: experienced..! +2
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If you don't want to do it in one step by joining the tables (which can be daunting) you just need to create a delete query for each table and enclose those deletes in a transaction block. The transaction block ensures that if any of the deletes fail then none of the deletes are committed.

Dim trans As SqlClient.SqlTransaction = myConnection.BeginTransaction()

Try	'delete from all tables

    'run delete query on first table
    'run delete query on second table
    'etc
    
    trans.Commit()

Catch	'got an error - roll back the transaction    
    
    trans.Rollback()
    
Finally	'close the connection

    myConnection.Close()
    
End Try
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You can get the list of files with

Dim filelist() As String = System.IO.Directory.GetFiles("c:\windows\system32")

Use a class variable to keep track of which file name to display next. The timer tick handler can advance the index (and wrap to zero if you want to repeat).

NetJunkie commented: Thanks! +5
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You can form the insert query by

query = "insert into TABLENAME _
   (CustomerID,Title,FirstName,LastName,DOB,Address,Town,Postcode,County,TelNumber) _
    values('" & txtCustomerID.Text & "','" _
              & txtTitle.Text      & "','" _
              & txtFirstName.Text  & "','" _
              & txtLastName.Text   & "','" _
              & txtDOB.Text        & "','" _
              & txtAddress.Text    & "','" _
              & txtTown.Text       & "','" _
              & txtPostcode.Text   & "','" _
              & txtCounty.Text     & "','" _
              & txtTelNumber.Text  & "')"

Note that VB will reformat the code to remove extra spaces. I left it as above so it would be easier to see how the query is built. How you apply the query to the database depends on how you connected. If you do it with ADO then it would look like

Imports ADODB
.
.
.
conn = New Connection
conn.Open("Driver={SQL Server};Server=.\sqlexpress;Database=mydb;Trusted_Connection=yes;")
query = (use the code from above)
conn.Execute(query)
conn.Close()
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You can try

select name from Table2 where name not in (select * from Table1)
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Change it to

Query = "update Prod_DB_Laminate_Raw set [Stock Level] = '" & TextBox1.Text & "' where Laminate = '" & ComboBox1.Text & "'"

Wnen you run into a problem like this it is best to display the actual query string as submitted to SQL. In most cases the error will be obvious. An extra line of

msgbox(Query)

Can open your eyes.

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

The Windows Imaging Automation component might do it for you. http://www.microsoft.com/download/en/details.aspx?id=18287

The Windows Image Acquisition Automation Library v2.0 provides basic image acquisition and manipulation functionality to Visual Basic and Scripting applications.

Begginnerdev commented: Thanks for the input! +4
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Here is an example of using ADO to import records from Excel. In my example, the data on Sheet1 looks like

lname   fname   age   gender
Smith   John    32    M
Doe     Jane    41    F
Imports ADODB

Public Class Form1

    Private Sub btnFetch_Click(sender As System.Object, e As System.EventArgs) Handles btnFetch.Click

        Dim conn As New Connection
        Dim rset As New Recordset
        Dim buff As String

        conn.ConnectionString = "Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=d:\temp\test.xls;"
        conn.Open()

        rset.Open("select * from [Sheet1$]", conn, CursorTypeEnum.adOpenForwardOnly)

        Do Until rset.EOF
            buff = rset("lname").Value & " " & rset("fname").Value & " " & rset("age").Value & " " & rset("gender").Value
            txtExcel.AppendText(buff & vbCrLf)
            rset.MoveNext()
        Loop

        rset.Close()
        conn.Close()

    End Sub

End Class

In this case, the first row is expected to contain the column headers (field names). If there are no column headers than the parameter ";HDR=No" must be included in the connection string.

Note that it is not necessary for any AccessDB components to be used (or even present on the user's computer).

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

to waqasaslammmeo

Can you please explain to me how

Importing Data from excel to Mysql using VB.net

can be interpreted as "I want to import Excel to an AccessDB?". I'm not trying to be difficult or argumentative but if I can misunderstand such a simple request than I obviously have no command of the English language whatsoever.

I'd also like to remind you of the forum rules/guidelines. To wit

Do not write in all uppercase or use "leet", "txt" or "chatroom" speak

Typing "u", "ur", etc makes it more difficult for non-English (as a first language) forum members to follow conversations.

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

Note - the following code assumes that len(b) <= len(a)

Dim a As String = "abcdefghijklmnopqrstuvwxyz"
Dim b As String = "rahman"
Dim c As String = ""
Dim ch As Char

For i As Integer = 0 To Len(a) - 1

    'If there are still chars left in b then pick a char from a (if a=b)
    'or from b (if a <> b). If there are no more chars in b then just take
    'the next char from a

    If i < Len(b) Then
	ch = IIf(a(i) = b(i), a(i), b(i))
    Else
	ch = a(i)
    End If

    'If the selected char is not already in c then add it to c

    If InStr(c, ch) = 0 Then
	c += ch
    End If

Next

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

The usual procedure is to finalize the database design (table and column names, etc) then code to that design. If the database design is incomplete then you'll just have to modify your code as changes occur. The only other option (at leas as I can tell) is to abstract the column and table names. By that I mean store the column and table names in a config file and read those names in at run time. As an example, the config file might contain lines like

CustomerInfoTable = cust_info
ProductInfoTable = prod_info
CustomerNumber = cust_no

read those values into variables at load time then create your queries dynamically as in

query = "select " & CustomerNumber & " from " & CustomerInfoTable " where..."

At least that way you would only have to change the config file as the database changes (except for major restructuring)

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

Take out the comma in ",FROM Breakfast".

discovery-power commented: much appreciated, thanks +3
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I can't help you with the error but I do have a recommendation. When you share a folder on the server, do not add individual people into the access list. Instead, create an AD group with the required access rights, then add people to that group. You want to minimize the number of mods to the ACLs on the server. I had to undo a massive admin nightmare on several of our work servers where another individual was adding people rather than maintaining access through AD groups. It wasn't pretty.

skilly commented: yep, that is best practice, i had forgotten +4
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

In the button click handler you can identify the button either by name or by label text (the label text is probably more informative depending on how you name your controls)

Dim button As Button = DirectCast(sender, Button)
MsgBox(button.Text & " " & button.Name)
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

In the button click handler you can identify the button either by name or by label text (the label text is probably more informative depending on how you name your controls)

Dim button As Button = DirectCast(sender, Button)
MsgBox(button.Text & " " & button.Name)
sanket044 commented: hey thanx dud... +0
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

You can do this with application settings. I don't know what version of Visual Studio you have so I'll describe the procedure for VS 2010.

Start with your project open

Go to the project properties settings

Select the "Settings" tab down the left side of the panel

Add an item, let's name it "LastButtonText", make it of type "String" and scope "User". Don't enter a value.

Go to your Form Load event handler and add the line (I'll assume your button control is named btnMyButton - change it to the correct name)

If My.Settings.LastButtonText <> "" Then
    btnMyButton.Text = My.Settings.LastButtonText
End If

That will load the button text on startup. Now you have to save the last displayed text at app exit. For that you have to add the following code to the FormClosing handler.

My.Settings.LastButtonText = btnMyButton.Text

That should do it.

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

Try

Sub fillListView()
 
    With sqlcmd
        .CommandText = strsql
        .Connection = sqlconn
    End With
 
    With sqlda
        .SelectCommand = sqlcmd
        .Fill(dTbl)
    End With

    subjListView.Items.Clear()

    For i = 0 To dTbl.Rows.Count - 1
        With subjListView
            .Items.Add(dTbl.Rows(i)("name"))
            With .Items(.Items.Count - 1).SubItems
                .Add(dTbl.Rows(i)("age"))
            End With
        End With
    Next

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

Assuming you want to do this to all text controls on the form, add the following to subs

Private Sub Text_Enter(sender As System.Object, e As System.EventArgs)
    DirectCast(sender, TextBox).BackColor = Color.Yellow
End Sub

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

Then add the following for the form load event handler

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

    For Each ctrl As Control In Me.Controls

        If TypeOf (ctrl) Is TextBox Then
            AddHandler ctrl.Enter, AddressOf Text_Enter
            AddHandler ctrl.Leave, AddressOf Text_Leave
        End If

    Next

End Sub

The first two subs will supply the handler code for the enter and leave events. The form load code will add those handlers to all textboxes.

I have a new kitten (as of 4 days ago) who is making these postings somewhat difficult, although on the bright side, she is creating some very cryptic passwords as she chases the cursor while dancing on my keyboard.

M.Waqas Aslam commented: good solution bro , thank u soooo very much +1
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

The easiest way to insert a record into a table is by ADO as follows

Dim con As New ADODB.Connection
con.Open("Driver={SQL Server};Server=JIM-PC\SQLEXPRESS;Database=mydb;Trusted_Connection=yes;")

Dim query As String = "insert into Table1 (RegistrationNo,Field1,Field2) values(12,'John','Doe')"

con.Execute(query)
con.Close()

In this case I am inserting into a SQL Express 2008 table "Table1" in the database "mydb". That table has three fields named "RegistrationNo", "Field1" and "Field2".

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

You have a typo in the for loop. You mistyped "proc" as "porc".

As far as I know, you can't lock the screen by killing explorer.exe. It can always be started again from task manager (which can be activated from the keyboard). However, you CAN lock the workstation by executing the following command

rundll32 user32.dll,LockWorkStation

The password to unlock it will be the password used at logon.

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

Let's replace the variables with tokens. For example, let's replace ServerAdressTextBox.Text with the string SERVER, etc, and see how your connection strings look at that point. Your three examples boil down to

"Data Source=SERVER;Initial Catalog=DATABASEIntegrated Security=SSPI" & ";"

"Data Source=SERVER\MSSQL;Initial Catalog=DATABASE;User Id=USERNAME;Password=PASSWORD;"

"Data Source=SERVER;Initial Catalog=DATABASETrusted Connection=True;"

When you look at the resulting strings you can see that you are missing the delimiter ";" following the DATABASE name in examples 1 and 3. Correct that first and see where it gets you.

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

"Cancel" is universally regarded as "throw out what I did". Have a look at codeorder's code above. He's doing substance so I might as well do style. I suggest you relabel your button to something like "OK" or "COMMIT" instead of "Cancel" or you are going to confuse a lot of users.

OK - I'm happy with my changes. Please save them and continue
CANCEL - throw away my changes and continue

codeorder commented: "confuse a lot of users", it's what i love about replying to certain threads, Not.:) +12
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

A couple of more comments:

When you define a function such as CalculateItems, try to give it a meaningful rather than a generic name. CalculateItems imparts almost zero information. The comment you included with it, "calculates gross sales" gives a little information but could be clearer as in "calculates gross sales as the product of items sold and something else". I don't know what that somethinig else is because you used a literal, 10.

Which brings me to my next point. Literals in almost all cases are bad. If I see a literal like 3.1415926535 in a calculation, especially one involving circles or spheres, I'm pretty sure I can figure out what it is. The literal, 10, on the other hand is essentially meaningless. You'd be better off with

Const DESCRIPTIVE_NAME = 10

You'll find this more useful later when you need the same literal in several places.

If I'm being picky it's because I assume this is for an assignment. I've been through that from both sides, as a student (a very long time ago), a marker (not quite as long but still a long time) and as a maintenance programmer where I have come close to tears and/or rage at some of the messes I've had to clean up. Better to beat it out of you now ;-)

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

Try this. I created a form with five labels and one listbox.

Public Class Form1

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

        AddHandler Label1.Click, AddressOf Label_Click
        AddHandler Label2.Click, AddressOf Label_Click
        AddHandler Label3.Click, AddressOf Label_Click
        AddHandler Label4.Click, AddressOf Label_Click
        AddHandler Label5.Click, AddressOf Label_Click

    End Sub

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

        Dim label As Label = sender
        ListBox1.Items.Add(label.Text)

    End Sub

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

You don't use SaveAs (or even Save) on a WorkSheet. You use it on a WorkBook. For example, the following code copies items from a listview into a new Excel WorkBook/WorkSheet then saves it to a file specified by the SaveFileDialog.

'browse for a file to save the data into

SaveFileDialog1.Title = "Save Excel File"
SaveFileDialog1.Filter = "Excel files (*.xls)|*.xls|Excel Files (*.xlsx)|*.xslx"
SaveFileDialog1.ShowDialog()

If SaveFileDialog1.FileName = "" Then
    Exit Sub
End If

'create an Excel WorkBook

Dim xls As New Excel.Application
Dim sheet As Excel.Worksheet

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

'save the listview items to the Excel WorkSheet

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

For Each item As ListViewItem In lvwToExport.Items
    For i As Integer = 0 To item.SubItems.Count - 1
	sheet.Cells(row, col) = item.SubItems(i).Text
	col += 1
    Next
    row += 1
    col = 1
Next

'save the WorkBook to a file and exit Excel

xls.ActiveWorkbook.SaveAs(SaveFileDialog1.FileName)
xls.Workbooks.Close()
xls.Quit()
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I just get "Incorrect linking code."

Don't make me jump through hoops. Just post the data here.

codeorder commented: ">>Don't make me jump through hoops...". :) +12
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Sorry about that. A clearer bit of code would be

Imports System.Windows.Forms

Public Class Form1

    Private filterkeys As Boolean = False
    Private mycursors() As Cursor = {Cursors.AppStarting, Cursors.Arrow, Cursors.Cross}
    Private cursorindex As Integer = -1

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

    Private Sub Form1_KeyUp(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
        If filterkeys And e.KeyCode = Keys.Up Then
            cursorindex = (cursorindex + 1) Mod (UBound(mycursors) + 1)
            Cursor = mycursors(cursorindex)
        End If
    End Sub

End Class

Don't confuse Form1_KeyUp with Keys.Up. "KeyUp" in the function name refers to the event "when a key is released (the UP event)" with "Keys.Up" which refers to the key code for the UP key.

PS - I've been programming for years but there are many many people here who are more adept than I am in VB and object oriented programming so when I suggest a solution keep in mind that it is "a" solution, not necessarily the best or only solution ;-)

codeorder commented: good stuff: "Don't confuse Form1_KeyUp with Keys.Up..." :) +12
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If you go to

Project -> (my app) Properties

There is a checkbox labeled "Make single instance application"

Select it if you want to allow only one instance at a time to run, deselect it if you want to be able to run multiple instances.

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

You will need to enable KeyPreview in the form. You can trap the up arrow press in the forms KeyUp event. You have to enable KeyPreview at design time. There is no way to set it at run time so you will have to have a global variable (call it something like filterKeys) and set it to True in the button click event. Then in your KeyUp handler you can do

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

I presume you mean an Excel Workbook/Worksheet. As far as I know you have to open it first but you can do that easily with the following function

Private Function GetWorkSheetNames(ByVal ExcelFile As String) As String()

    Dim names As String = ""
    Dim xls As New Excel.Application
    xls.Workbooks.Open(ExcelFile)

    For Each sheet As Excel.Worksheet In xls.ActiveWorkbook.Worksheets
        names = names & vbCr & sheet.Name
    Next

    xls.Quit()

    Return names.Substring(1).Split(vbCr)

End Function
cguan_77 commented: Thanks. +8
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Write it out in English (pseudo-code) first and it may be clearer. For example, start with

If candidate is 5 or higher in mobility and 5 or higher in hearing and 5 or higher in sight or candidate is 7 or higher in mobility and 7 or higher in hearing and sight and 4 or higher in hearing and sight, etc

and put "(" and ")" around sections to avoid ambiguity. By that I mean you don't want to confuse

a or (b and c)

with

(a or b) and c

which could give different results. Once you have the English then you can try to convert it to code. Once you have determined if a candidate is fit for ordinary duties (save it in a boolean variable named "ordinary"), then you can test for special duties. But like adam k said, you have to show some effort.

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

You could create two new tables named Invoice and InvoiceLine. Each invoice would have a unique primary key named Invoice_ID. The fields in this table would contain information relevant to the entire invoice (Customer_ID, date, status, etc). InvoiceLine would have a primary key consisting of Invoice_ID and Line_ID. This table would contain all the info for each invoice item (product id, quantity, unit cost, etc).

bilal_fazlani commented: solved my problem +1
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If you have a text field named txtMytext and it contains "abcdefghijklmnop" then the following code

txtMytext.Focus()
txtMytext.SelectionStart = 3
txtMytext.SelectionLength = 6

will set focus to the control with "defghi" selected.

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

This is not a newbie project. I've been programming for 35+ years I wouldn't begin to touch it.

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

I've been happy with TeamViewer. It can also be set up to allow remote access on unattended machines (to be used with caution).

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

That's exactly how it is done. The items are added as follows:

item = New ListViewItem          'create new listview item

item.Text = col1text             'add column 1
item.SubItems.Add(col2text)      'add column 2
item.SubItems.Add(col2text)      'add column 3

listView.Items.Add(item)         'add item to listview
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

If you have already covered arrays then I suggest you use an array to hold the random numbers. You start with no random numbers in the array. Your outer loop will terminate when you have generated the 6 required unique numbers. Inside the loop you can generate a random number and add it to the array only if it isn't already present in the array.

Does that make it a little clearer?

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

But if you run the explorer-like app using the method in my link then it will run the access rights sufficient to access all folders. The alternative is to pin the app to your taskbar then CTRL-Shift click. This will pop up the UAC dialog which will give you the same rights as the task scheduler/schtasks workaround.

I don't see the problem.

I have an application (Songbird media player) that for whatever reason needs to save a setting in a restricted folder. I've mentioned this to the developers but the "bug" remains. Every time I run Songbird it pops up the UAC. Really annoying. I created a task scheduler entry named "songbird" and I specified that it should run with highest rights. I created a shortcut with

schtasks /run /tn "songbird"

as the target. Now when I run the shortcut, Songbird starts without the UAC nonsense. Of course it is very important that you trust the program that you are giving these access rights to. Songbird is open source and I have checked out the source code. You are rolling your own app so unless your app does something really bad (due to a bug) then I don't see a problem.

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

I believe the actual algorithm is Newton's method. You start with a guess as to the answer then iterate through a formula to get the next approximation. Repeat as needed. It converges very quickly to the answer.

Example - find the square root of 10. Let's guess that it is 2 (it's not a good guess but it doesn't matter). To find the next approximation we divide the original number by our guess, add it to our guess then divide the result by 2.

(2 + 10/2) / 2 = 3.5
3.5 squared is 12.25

(3.5 + 10/3.5) / 2 = 3.178571429
3.178571429 squared is 10.10331633

(3.178571429 + 10/3.178571429) / 2 = 3.162319422
3.162319422 squared is 10.00026413

etc. Each iteration gets us closer to the actual square root. All of it requires floating point arithmetic.

v3ga commented: Nice info I had to make a program for sqrt without math.h.........thx +2
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Right. That's soooooo much better.

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

Make sure you have ListView1 in Details mode and that it has one (or more) columns in its collection.

Public Class Form1

    Class MyCustomSorter

        Implements IComparer

        Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare

            Dim item1 As ListViewItem = CType(x, ListViewItem)
            Dim item2 As ListViewItem = CType(y, ListViewItem)

            Dim num1 As Integer = Int(item1.SubItems(0).Text.Substring(9))
            Dim num2 As Integer = Int(item2.SubItems(0).Text.Substring(9))

            If num1 > num2 Then Return 1
            If num1 < num2 Then Return -1
            Return 0

        End Function

    End Class

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

        Dim s As String
        Dim strings() As String = {"78550Item10", "78550Item6", "78550Item4", "78550Item5", "78550Item3", "78550Item9", "78550Item2", "78550Item1", "78550Item8", "78550Item7"}

        For Each s In strings
            ListView1.Items.Add(s)
        Next

        ListView1.ListViewItemSorter = New MyCustomSorter
        ListView1.Sorting = SortOrder.Ascending

    End Sub

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

If you have the listview in details view you can define a custom sort. Let's say your listview is called lvwList

lvwList.ListViewItemSorter = New MyCustomSorter

But first you have to write the MyCustomSorter class. This is code that will compare two of your items and determine whether one is <, =, or > to the other

Class MyCustomSorter

Implements IComparer

Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare

    Dim item1, item2 As ListViewItem
    Dim text1, text2 As String

    item1 = CType(x, ListViewItem)
    item2 = CType(y, ListViewItem)

    text1 = item1.SubItems(0).Text.SubString(9)
    text2 = item2.SubItems(0).Text.SubString(9)

    If text1 > text2 Then Return 1
    If text1 < text2 Then Return -1
    Return 0

End Function

It's up to you to determine how to compare the items. I just did a substring as an example. You may have to get fancier to extract the strings. Also, for my example to work you would have to convert text1 and text2 to numeric and compare those.

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

First of all when you take the square of 4 you get 16. I presume you meant square root. I would imagine that the algorithm used to find the square root results in 2 plus a very very small fraction which is not shown because it is so much smaller than 2. When you subtract 2 from that you are just left with the fractional part which is, at least on my computer, around -8 times 10 to the -39th power which is damn close to zero.

One of the first demonstrations I had on how computers do math was back in 1971 when it was shown that 1/3 + 1/3 + 1/3 was actually slightly less than one according to the computer.

flagstar commented: nice... even I have to read several times to understand completely... +7