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

You could try the following using regular expressions

Dim Files() As String = System.IO.Directory.GetFiles("D:\Utils")
Dim fltr As New ArrayList
Dim opt As RegexOptions = RegexOptions.IgnoreCase

'Add all filenames starting with CE

For Each file As String In Files
    Dim basename As String = My.Computer.FileSystem.GetFileInfo(file).Name
    If Regex.IsMatch(basename, "^CE.*", opt) Then
        fltr.Add(basename)
    End If
Next

ComboBox1.DataSource = fltr

fltr.Clear()

'Add all filenames starting with BE

For Each file As String In Files
    Dim basename As String = My.Computer.FileSystem.GetFileInfo(file).Name
    If Regex.IsMatch(basename, "^BE.*", opt) Then
        fltr.Add(basename)
    End If
Next

ComboBox2.DataSource = fltr

In regular expressions, the caret (^) anchors the pattern to the start of the string. The ".*" matches any string, so "^CE.*" matches any file that starts with CE.

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

Too bad the cheaters won.

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

Rather than checking the text length you should check if the textbox contains a number. This wouuld not require trimming and would also ignore non-numeric entries such as "abc". The following code should be reasonably self evident.

Dim nums As New ArrayList

For Each txt As TextBox In Me.Controls.OfType(Of TextBox)()
    If IsNumeric(txt.Text) Then
        nums.Add(CInt(txt.Text))
    End If
Next

nums.Sort()

If the form contains other text boxes you could always put the related boxes in a container and do the for loop on that container.

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

Sorry. That should have been

If rdr.Read Then
    Dim imgdata() As Byte = rdr("pic")
    Dim str As New MemoryStream(imgdata)
    Button1.BackgroundImage = New Bitmap(Image.FromStream(str))
    str.Close()
End If
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Try something like

Button1.BackgroundImage = New Bitmap("d:\temp\test.jpg")
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

How about

SELECT (SELECT SUM(sold) FROM veggies) 
     + (SELECT SUM(sold) FROM flowers)
    AS total
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

When you buy a hot dog at a baseball/football game you never know if you are getting a fresh one, or one that was leftover from the last game and just reheated. I know several people who worked the games as vendors and they said that this was common practice.

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

Two ways

UBound(imgdata)

gives you the index of the last byte and

imgdata.Length

gives you the number of bytes. The first value will be one less than the second value.

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

Put a breakpoint at

lvorder.Items(i).Text = (Val(lvorder.Items(i).Text) + 1).ToString

and see if the code stops there. If not then you are never getting a match. In that case put a breakpoint at

If lvorder.Items(i).SubItems(1).Text = btn.Text Then

and step through each iteration of the loop and check the values oof everything including btn.Text to see if things are what you expect. You might want to rewrite the loop as

For i As Integer = 0 To lvorder.Items.Count() - 1

    If  lvorder.Items(i).SubItems(1).Text = btn.Text Then

        dim quantity as integer = Val(lvorder.Items(i).Text + 1)
        dim unitcost as double = Val(lvorder.Items(i).SubItems(2).Text)
        dim total as double = quantity * unitcost

        lvorder.Items(i).Text = quantity.ToString
        lvorder.Items(i).SubItems(3).Text = total.ToString

        ProdMatch = True
        Exit For

    End If

Next

if only for debugging and you can add quantity, unitcost and total to the watch window.

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

It's possible that imgdata contains no data (or invalid data). Put a breakpoint at

PictureBox1.Image = Image.FromStream(str)

and check the length of imgdata

If the database contains valid image data then this should work. I tested it locally before I posted the code.

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

Do you mean this line 25

PictureBox1.Image = Image.FromStream(str)

If the error is in

cmd.ExecuteNonQuery()

then please post the value of the string sql.

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

Never heard of it.

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

No difference. SQLDB and OLEDB are merely interfaces. The actual data storage is a function of the underlying database. Consider the database like a huge parking lot and SQLDB and OLEDB the highway you use to get vehicles to/from the parking lot. For small to medium databases (I can't actually define what constitutes small or medium), something like Access is sufficient.

Before I retired, one of our developers built an application in Access. Unfortunately, once the amount of data got to a certain size (don't recall what that was) I would get a 3:00 AM call about once a week from the control centre saying that the application was broken. For some unknown reason, it required a database repair/rebuild about once a week. Also, unfortunately, the control centre staff required 24 hour availability. Fortunately a 3:00 AM call meant two hours double time pay for me. We never had this problem with our SQL databases even though they were magnitudes bigger.

Microsoft sunk a few billion dollars into developing MS SQL and a few hundred million into Access. Which do you think is more robust?

Please don't forget to mark this as solved if you got what you needed.

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

If you are using MS SQL as your database then you should be using SQLDB rather than OLEDB. Both are built on top of ADODB (which you could also use), however, SQLDB is optimized for MS SQL. OLEDB is used for other data sources. In terms of complexity I don't see any difference between SQLDB and OLEDB. If you are using MS SQL, but plan to (possibly) use other data sources then stick with OLEDB and just change the connection string as required.

Santanu.Das commented: Mind-blowing +5
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Here is the OleDB version

Private Sub btnOleDb_Click(sender As System.Object, e As System.EventArgs) Handles btnOleDb.Click

    Dim con As New OleDbConnection("Provider=SQLNCLI10;Server=.\SQLEXPRESS;Database=mydb;Trusted_Connection=Yes;Connect Timeout=15;")
    Dim cmd As New OleDbCommand("SELECT picdata FROM test WHERE picname = '" & imgname & "'", con)

    con.Open()
    Dim rdr As OleDbDataReader = cmd.ExecuteReader

    If rdr.Read Then
        Dim imgdata() As Byte = rdr("picdata")
        Dim str As New MemoryStream(imgdata)
        pbxImage.Image = Image.FromStream(str)
        str.Close()
    End If

    rdr.Close()
    con.Close()

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

I don't know what kind of database you are using. If it is MS SQL then you can use SQLDB as follows to retrieve and display the image

Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Imports System.Drawing.Imaging

Private Sub btnRetrieve_Click(sender As System.Object, e As System.EventArgs) Handles btnRetrieve.Click

    Dim con As New SqlConnection(ConnStr)
    Dim cmd As New SqlCommand("SELECT picdata FROM test WHERE picname = '" & imgname & "'", con)

    con.Open()
    Dim rdr As SqlDataReader = cmd.ExecuteReader

    If rdr.Read Then
        Dim imgdata() As Byte = rdr("picdata")
        Dim str As New MemoryStream(imgdata)
        pbxImage.Image = Image.FromStream(str)
        str.Close()
    End If

    rdr.Close()
    con.Close()

End Sub

For this example I am using a test database created as follows

CREATE TABLE [dbo].[test](
    [picname] [varchar](50) NOT NULL,
    [picdata] [image]       NOT NULL,
CONSTRAINT [PK_test] PRIMARY KEY CLUSTERED 
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I suggest the following method to display a picture in a PictureBox from a file

Dim fs As New System.IO.FileStream(FileList(indx), IO.FileMode.Open, IO.FileAccess.Read)
pbxPicture.Image = System.Drawing.Image.FromStream(fs)

If you load the picture directly (without using a FileStream) you end up locking the file. Using a FileStream releases the file once it has been loaded and the fs goes out of scope.

I'm in the process of rebuilding my system and after I get SQL Express loaded up I'll try to post some code to load the iimage from a database.

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

Just when I was feeling good about my new laptop. OK, Dani, blow us away with the specs.

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

Use @name parameters with SQLDB. For OleDB you have to use ? as s placeholder. Plese see Use Parameterized Queries to Avoid SQL Injection Attacks. When using SQLDB, parameters can be added by name. With OleDB you must add them in the order in which they appear in the query.

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

If you are calculating the tootal price for each dish you need to know

  1. the quantity
  2. the price per unit (the rate)

Your table only has columns for

  1. the quantity
  2. the name of the dish
  3. the total price

You need to add a column indicating the cost (rate) of the dish.

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

I can see one problem with that. If txtQty.Text is not numeric then you will get an error on

num = CInt(txtQty.Text)

Once you have determined that txtQty has a numeric value and you have converted it to num (and the same for txtPrice.Text to an Integer in price) you can do

    Select Case num
        Case Is < 5
            txtPay.Text = num * price & "??"
            Perc = " 0%"
            Debug.Print("0%  ")
        Case Is <= 9
            txtPay.Text = num * price - price * 0.05)) & "??"
            Perc = " 5%"
            Debug.Print("5%")
        Case Is <= 14
            txtPay.Text = num * price - price * 0.1)) & "??"
            Perc = " 10%"
            Debug.Print("10%")
        Case Else
            txtPay.Text = num * price - price * 0.15)) & "??"
            Perc = " 15%"
            Debug.Print("15%  ")
    End Select

I would also assume that you would get the discount on every item, in which case the calculatiion should be

num * (price - price * 0.05)

A cleaner version would be

Select Case num
    Case Is < 5
        discount = 0
    Case Is <= 9
        discount = 5
    Case Is <= 14
        discount = 10
    Case Else
        discount = 15
End Select

txtPay.Text = (100 - discount) * 0.01 * num * price
Perc = discount & "%"

You want to remove duplication of code. It makes the code easier to follow and reduces the chances of errors due to typos.

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

Assuming this is some sort of login form, what you would usually do it compare the entered username and password to a stored username and password (such as in a database). Since I don't know what you are comparing it to I'll just use literals as

If txtUsername.Text = "Bilbo" And txtPassword.Text = "Baggins" Then
    MsgBox("Access granted")
    LoggedIn = True
Else
    Msgbox("Incorrect login")
    LoggedIn = False
End If

The problem with using an onscreen keyboard is that as soon as you click on a key whatever textbox you were in loses focus so you have to keep track of what control you were just in. You can do that by declaring a class level variable like

Private currText As TextBox = Nothing

Then in the Enter event for each textbox you set the value like

Private Sub txtUsername_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtUsername.Enter
    currText = sender
End Sub

In the Click event for your keyboard keys you can do

If Not currText Is Nothing Then
    currText.Text &= "A"
End If

You could even generalize the keyboard to use the same event handler for all of the keys. That would be the preferrred way since all of the keys have the same code except for that actual key entered (which can be determined from the displayed value on the key).

By the way, you should be using & to concatenate strings instead of using +. It would also be …

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

You have to give us actual code.

If TextBox1.[dont know what to type here] = True Then 

does not qualify. May I also suggest you name your controls more clearly. For example, txtUsername and txtPassword instead of TextBox1 and TextBox2.

And your explanation is still very confusing.

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

1.267?

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

If you use a panel instead of a listbox and set AutoScroll to True then it will work.

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

Adding more controls than can be shown will not activte the scroll bars. You have to add text to do that.

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

Declare an integer at the class level as in

Private ButtonClickCount As Integer = 0

Then in the button click event handler do

ButtonClickCount += 1
Me.Text = "Current count = " & ButtonClickCount

This will display the count in the title bar. Replace the last line to copy the value to a ListView.

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

I'm doing it right now.

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

Then use them to prove to me that gravity is a lie

Well obviously since nobody knows how gravity works then it's only a "theory" like the theory of evolution and we all know that that is a lie. Therefore gravity doesn't exist.

smoking has no health risks what so ever.

I know a guy who smoked and he lived to 96 so therefore smoking has no healthy risks.

Hey, if a mother can say that a vaccne caused her child's autism (even though the vaccine was given at the same time that autism usually manifests) then I can claim the above.

And I'm only using the same sort of logic you seee on such reputable shows like Fox (Faux) News.

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

Helping by Skype would not benefit anyone else on the forum.

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

For OleDB you use ? for the parameters as follows:

sql = "UPDATE tbdishlist SET " & _
          "qty = qty + ?,    " & _
          "price = price + ? " & _
      "WHERE nod = ?"

acscmd.Parameters.AddWithValue("@qty", qty)
acscmd.Parameters.AddWithValue("@price", price)
acscmd.Parameters.AddWithValue("@name", name)          
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

In an Explorer window

Organize >- Folder and Search Options

Click on the View tab.

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

It's a hidden folder. You have to enable "Show Hidden Folders, Files and Drives" in folder view.

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

Save the date and time when the app was first run, then just pop up a nag and exit if it is mote than one year old. The first-run date could be saved in a Settings variable or the registry (possibly encrypted to prevent abuse).

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

Why do so many people expect to be rewarded...

I don't know about other places, but here in Winnipeg there was talk a few years ago about something which I believe is at the root of the problem. Some teachers felt that it was proper to give either a lower grade, or even no grade, for assignments which were not handed in on time. This is a position with which I strongly agree. In the real world you don't credit for work that you don't do. I seem to recall that the teachers were told that they were to allow work to be handed in late with no penalty. Furthermore, it is now almost unheard of for a child to repeat a grade. Everyone gets moved through the system regardless of proven ability or proficiency.

I think that there is a strong sense of entitlement being fostered in our children and I think that this hurts them in the long run.

Turn on any newscast and you see CEOs of the same companies that caused the financial crash being rewarded instead of punished. You see people with no discernible talent, people who contribute nothing to society other than providing fodder for tabloids (think Kim Kardashian, Paris Hilton and any Real Housewives or Jersey Shore cast member) raking in millions.

And you ask why people expect to be rewarded for doing nothing?

Nearly 50% of the US population now receives government handouts in one form or another.

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

If there was an online storage option that would store my files encrypted (including file names) where the encryption key was stored only on my computer then I would likely use it. I realize that I can use truecrypt to create a container which I could then use on DropBox, but that requires re-uploading an entire container for even minor changes. A while back I looked at SpiiderOak which was promising just that in the near future. Perhaps it's time for another look.

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

I've noticed that a lot of your recent questions could be answered by even a cursory reading of just about any intro to vb.net programming book or one of the many similar (free) tutorial web sites. Might I suggest you get one and read it?

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

If you want to do the same without using AutoIt you can still do it with vbScript by

do

    titles = GetTitles()
    if Contains(titles,"TextPad") Then
        wscript.Echo now, "TextPad is active"
    end if

    wscript.Sleep 1000

loop

Function GetTitles ()

    Dim cmd:  cmd = "tasklist /v /fi ""WINDOWTITLE ne N/A"" /fo list"
    Dim tasks: tasks  = Split(CreateObject("WScript.Shell").Exec(cmd).StdOut.ReadAll(), vbCrLf)

    GetTitles = Filter(tasks, "Window Title:")

End Function

Function Contains (titles, string)

    Dim title

    Contains = False

    for each title in titles
        title = Trim(Split(title, ":")(1))
        if instr(title, string) > 0 Then
            Contains = True
            Exit Function
        end if
    next

End Function

although executing TASKLIST is much less efficient than using AutoIt and it involves a lot more coding.

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

For that sort of stuff I use AutoIt. It's free and very scriptable. For example

set aut = CreateObject("AutoItX3.Control")

aut.AutoItSetOption "WinTitleMatchMode",2

while True

    if aut.WinExists("TextPad") Then
    wscript.echo "textpad is open"
    end if

    wscript.Sleep 1000

wend

After you install AutoIt, copy the above and save it into WatchTextPad.vbs. The do the following, once from the command line

cscript //h:cscript //nologo //s

That makes cscript.exe the default engine. That way, writes (wscript.echo) go to the console window. Otherwise, vbs scripts get run by wscript.exe and writes get sent to a messagebox popup.

aut.AutoItSetOption "WinTitleMatchMode",2

says that when you are checking window titles, check for the given string anywhere in the title (there is a very good help file detailing all this). The rest of the script should be obvious.

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

What are the command line arguments for running it? Also, it seems like an awful lot of code just to monitor a process.

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

I want to try running this locally but I am getting

Type 'FreeMemory' us not defined
Type 'EncryptDecrypt' is not defined
Type 'BuildString' is not defined

What version of vb.net are you using?

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

For starters, the program won't compile because of

If p.Id = CDbl(cid) Then

The variable cid is not defined.

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

See here for examples using SQLDb and OleDB.

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

You have to use a delegate to modify controls. It's not complicated and there is a tutorial on how to use BackGround threads which includes a discussion of delegates. Once you have read the tutorial feel free to post any follow up questions here.

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

Here's something you might want to try as a last resort. Download and create a GPartEd LiveCD. Boot from that. In GPartED, make note of the current flags on the recovery and Windows partitions in case you have to manually reset them later. Clear the boot/active flags from the Windows OS partition. Set the boot/active flags on the recovery partition. Try booting and see if that takes you right into recovery.

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

'after one times execute for loop i want to exit here. this meaning is if not exit For loop it will be continue looping so after one times execute i want For loop exit and continue go back to a.txt file and read continue processing. i hope this make sense.

Actually, it doesn't.

Given the pseudo code I provided you should be able to create the corresponding vb code. When you generate the two random numbers (call them r1, r2) you will have to test if r1 > r2 and swap them if true.

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

By the way, have you tried actually booting from the recovery disks you mentioned in your other thread?

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

If the recovery disks are no longer readable, or the user did not make a set of recovery disks (the nags are there for a reason) you should still be able to download a set from Dell based on the Service Tag or Express Code on the back of the laptop. Upgrading the OS should not in any way affect the recovery partition on the hard drive. The recovery program can be started before the OS actually boots. If this was not the case then it would be useless in the event of a catastrophic OS failure. Over Christmas I replaced my son's hard drive with an SSD by cloning the recovery partition to the new disk, then running the Recovery process from that. The new drive had no OS on it until after I did the recovery. I suppose, if you really had to, you could boot to a GParted livecd and nuke the OS partition before trying the recovery.

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

Let me see if I understand what you want.

for each line in a.txt
    pick two random numbers (lo,hi) in the range 0 to b.txt.count - 1
    output line
    for i = lo to hi
        output i
    next
    output newline
next

If that is what you want then it should be easy to translate the above into actual code. What I don't understand is

'after one times execute for loop i want to exit here

What is the point of using a loop if you always exit after one iteration?

And for future posts, please indent your code. It makes it easier to read and increases the odds of getting a response.

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

You might as well replace

goodLine = line
My.Computer.FileSystem.WriteAllText(RestranName2, goodLine & VbCrlf, True)

with

My.Computer.FileSystem.WriteAllText(RestranName2, Line & VbCrlf, True)

It's pointless to declare another temporary variable.