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

There have been several postings on this forum relating to accessing Excel spreadsheets from within VB. For example, I recently posted the following code which returns an array containg the names of all worksheets in a given workbook.

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
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

The following code contains a function which will split the header into four fields. In the example, the results are:

0010115112011
00015
00065
00020

Using that you can convert the counts to Integer using CInt, then once you get the totals after the merge you can rebuild the combined header.

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

    Dim header As String = "0010115112011                              000150006500020"
    Dim fields() As String = SplitHeader(header)

End Sub

Private Function SplitHeader(header As String) As String()

    Dim temp() As String = header.Split()
    Dim fields(3) As String
    Dim field2 As Integer = UBound(temp)

    fields(0) = temp(0)
    fields(1) = temp(field2).Substring(0, 5)
    fields(2) = temp(field2).Substring(5, 5)
    fields(3) = temp(field2).Substring(10)

    Return fields

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

Look on the page for

Has this thread been answered?
If this thread has been successfully resolved, please Mark this Thread as Solved so that it can be added to our Knowledge Base and help others. Also, posters who replied appreciate knowing that they were helpful.

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

Whben you are sure you have what you need then please mark this thread as solved. Glad I could be of assistance.

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

In your example, the three separate headers are

0010115112011                              00015[B]00065[/B]00020
0010115112011                              00011[B]00054[/B]00020
0010115112011                              00002[B]00010[/B]00020

So wouldn't the combined header just be the sums? In this case

0010115112011                              00028[B]00129[/B]00020
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Nope. It just gets stuck at "Processing download request".

The text messes up when directly posting here.

If that's the best you can do when describing an error we're not going to get anything fixed here. Are you aware that you can click on USE ADVANCED EDITOR where you can attach (for example) zip files to your posts?

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

Please post the Input Files info here. When I try to follow your link my anti-virus software says

Opening this website may put your security at risk

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

My boss once refused to buy a piece of software that would make my life much easier (PrimalScript) so I just bought it out of my own pocket ($99). The next month he authorized $1300 for software to help one of my users. Go figure. I ended up billing for it another way so it worked out. I just couldn't convince him that if I could save an hour a day by spending $99 that he would get an extra hour of work out of me.

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

Acronis True Image is $50. If your IT department hasn't got the budget for that then it's time to start looking for another place to work.

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

I just thought that a flag on a toggle would prevent multiple notifications. Just a suggestion.

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

Here's a suggestion to handle threads that should be flagged as solved but haven't been.

Implement a control on the thread with the text "Notify OP to Mark as Solved".

Anyone (or perhaps anyone with a given minimum rep) can click on this control. This would cause an email to be sent to the OP requesting that he/she return to that thread and mark it as solved (perhaps there could even be a link in the email similar to the unsubscribe link that would accomplish this). To prevent multiple emails, the first click would also set a flag so that the control is disabled and replaced with the text "The OP has been notified to mark this thread as solved".

A special web page, available to moderators, could be created which cummarizes all threads for which the OP has been notified but for which no action by the OP has yet been taken.

The icons on the thread summary pages (new posts, popular thread, you have posted, etc) could be modified (perhaps displayed in red instead of purple) to indicate that a thread has been flagged for cleanup but not marked as solved.

This would put policing in the hands of the DaniWeb community and save the moderators (by virtue of the special web page) from having to scour the threads for cleanup. It would also ensure that OPs are notified that action is required.

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

There should be an entry in the displayed list for "echess". What is the value?

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

Acronis makes a great backup/restore utility that offers pretty good compression. Image files can be mounted to examine/extract files.

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

You can go to Project -> Properties -> Settings

Or you can set a breakpoint just after

connectionInfo = ConfigurationManager.AppSettings("echess")

or you can add the following line after that

MsgBox(connectionInfo)

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

As far as I know you can't override that behaviour from within the application. Access to system folders is restricted to protect your system. If it could be overridden from with the application with some code then the system would not be aable to protect itself from malicious code. There are ways to run an application with elevated priviledges. One way is to select "Run As Administrator" from the shortcut context menu but you have to do that every time you run it AND you get a confirmation prompt every time. The other way avoids the prompt but requires creating an entry in the Task Scheduler.

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

I didn't say newbie=untrustable. I said to use caution. If the OP has a compiler and knows how to use it then fine. That's safe. I offered what I considered reasonable advice - if you don't trust the source then use caution. If I tell my son to practise safe sex by using a condom I am not necessarily implying that his date is a disease ridden slut. I am just saying to use caution. If I implied that you were never to be trusted then I apologize. That was not my intention.

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

There are also several free text editors that support regular expressions in search/replace. You can download TextPad and use that (at least for a while) without paying. To do your function you would load the text file then use the following in the replace dialog

Find what: \n
Replace with: (type a single space here)
[x] Regular expression

Then click "Replace All"

You can download Textpad from here

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

timetraveller92 is (from the looks of it) a newbie poster. While his code will do what you want, I suggest you use caution before downloading and executing an executable from a site unless you trust that it is virus/trojan/etc free.

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

I don't know why that wouldn't work. vbScript comes as a part of Windows systems. What happens if you type

cscript

at a command line? If that works then try the following

cscript //h:cscript //s

And try running concat again.

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

Copy the following code into a file name concat.vbs. To convert your text into a single line do something like

concat myfile.txt > temp.txt

temp.txt will have one line containing all of the lines in myfile.txt concatenated and separated by a space. If you want to use a different separator just change the first line.

separator = " "

set fso = CreateObject("Scripting.FileSystemObject")
set arg = Wscript.Arguments

if arg.Count <> 1 then
	wscript.stdout.WriteLine "concat filename"
	wscript.Quit
end if

filename = arg(0)

if not fso.FileExists(filename) then
	wscript.stdout.WriteLine "file: " & filename & " not found"
	wscript.Quit
end if

text = fso.OpenTextFile(filename).ReadAll
text = Replace(text,vbCrLf,separator)

wscript.stdout.WriteLine text
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

You have

connectionInfo = ConfigurationManager.AppSettings("echess")

but I still don't know what the value of connectionInfo is. I need to know the actual contents of ConfigurationManager.AppSettings("echess") to see if it is a valid connection string.

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

On line 123 you declare Grades as Integer but you never assign it a value. I'm guessing that when you get to

If Grades >= 0 AndAlso type = GradesFiles.Grades Then

that the first part of the If fails because Grades has no value. That would mean the function always returns False. The ShouldDisplay function should really be commented to describe its purpose (input, output, etc). Put a breakpoint at the If and check the value of Grades at that point.

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

What is the value of connectionInfo?

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

The easiest way to read in a text file is to do it all at once as in

Dim alltext As String = My.Computer.FileSystem.ReadAllText(filename)
alltext = alltext.Replace(vbLf, "")
Dim lines() As String = alltext.Split(vbCr)

Or you can do it all at once by

Dim lines() As String = My.Computer.FileSystem.ReadAllText(filename).Replace(vbLf, "").Split(vbCr)
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

I'm curious as to how points are awarded when the OP marks a thread as solved. My control panel states "Forum threads marked solved after Reverend Jim replied to them". What happens in the case when I spend several hours helping a poster with a problem then someone else pops in with a post such as "That's a good point". If the thread is then marked as solved, who gets the "credit"? Is it the person who posted the solution or the lurker who made the last (but not helpful) post?

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

You can also use the syntax

Dim sqlQuery As String = "SELECT * FROM MyTable WHERE DateColumn BETWEEN @param1 AND  @param2"
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Unless you are running the software in a VM in order to avoid having the software show up on an inventory (like on an office computer) in which case you shouldn't.

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

Not to mention that the actual VM executive takes CPU cycles as well.

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

You can't get something for nothing. If your virtual machine is honking back cpu cycles doing video conversion then there are fewer cycles left for other processes. If you limit the resources available to the virtual machine either by putting a ceiling on available memory or by lowering the priority you will make more resources available to other tasks but by doing so you will increase the time required to do the conversion. Also, the more tasks you have doing I/O the less efficient that I/O will be as you will have multiple processes doing seeks/reads/writes to different areas of the disk (assuming all I/O is to the same physical drive).

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

The syntax has changed. You can set it by

PictureBox1.MaximumSize = New System.Drawing.Size(200, 200)
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

If you want to retain the current font but just change the size you can use

listBox1.Font = New System.Drawing.Font(listBox1.Font.Name, fontsize)

And specify your desired value for fontsize.

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

And how is

"The number to be converted is input by the user in a textbox"

different from

the number that will be converted(let's say 7)will be in a text box

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

Please take the time to ask a coherent question. If you can't be bothered to explaini it properly then don't expect a coherent answer. For example

i wanted the inpu to be
- number to be converted(text box)

I presume this means "The number to be converted is input by the user in a textbox". Put a little more effort into the question.

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

I should also point out that if you use a Class you will have to create each element of leagues with "New" as in

Public Class League
    Public id As String
    Public name As String
    Public players(20) As String
End Class
.
.
.
Dim leagues(20) As League

For i As Integer = 0 To UBound(leagues)
    leagues(i) = New League
Next
Reverend Jim 5,225 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

Try

Structure league
    Dim id As String
    Dim name As String
    Dim players() As String
End Structure

Dim leagues(100) As league
for i as integer = 0 to 100
    redim leagues(i).players(20)
next

I don't know why there should be a restriction on declaring the length of the players array when the struct is defined but apparently there is. An alternative would be to use a class instead of a struct as

Public Class League

    Public id As String
    Public name As String
    Public players(20) As String

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

No prob. I find a simple example that illustrates one feature is clearer than a complex one that tries to show all features. Are you listening Microsoft????

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

In what way is it not working?

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

What version of vmware are you using?

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

This usually happens when you have failed to specify a boot device.

Did you tell vmware (via the settings) to use the physical CD/DVD device on your computer? The alternative is to make an iso file from your XP CD/DVD and make sure it is mounted. Both options are set in the same place. On my version ov vmware (6) you get to the appropriate section by

VM -> Settings

Go to the hardware tab and click on CD-ROM. In the right hand panel you can select (under connection) "Use physical drive" (in which case you select the drive letter of you physical drive), or "Use ISO Image" in which case you specify the iso file you just created.

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

Then if your recordset is returned in the variable "rec" you can do

do until rec.EOF
   dim item as new ListViewItem(rec(0).Value)
   item.SubItems.Add(rec(1).Value)
   item.SubItems.Add(rec(2).Value)
   .
   .
   .
   lvwListView.Items.Add(item)
   rec.MoveNext()
loop

rec.Close()

Or you can use the field names instead if a field index, that is, rec("FIRST_NAME").Value. And forgive me if my SQL syntax is a little rusty.

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

If you are only interested in specific buttons on a page, a convenient way to distinguish them from other buttons is via the button.Tag property. Then inside the "is this a button" test you can check if button.Tag = "some value".

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

Are you having a problem with the SQL part, the ListView part, or both? My SQL is rusty so I'll leave that to the experts as I have no SQL implementation to play with, however, the ListView part is something I can help you with. What specifically are you having a problem with? Is it configuring the listview columns, adding the listview items, etc?

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

DOH! I do believe you are right. In my haste to help I overlooked that little fact. Ah well, as you so correctly stated, change ListBox to ListView and everything should work.

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.