SCBWV 71 Junior Poster

Okay, but you still have problems with your loop in Command1_Click

    For x = 0 To List1.ListCount - 1
        myRecord.ID = Val(Text1.Text) ' Define ID.
        myRecord.Name = "MyName" & "  " & Text2.Text    ' Create a string.' Write record to file.
        Put #1, x + 1, myRecord       ' Show the record into the listbox
    Next x

You're using the List1.ListCount for the loop but assigning each record to Text1 and Text2

SCBWV 71 Junior Poster

Well, the immediate problem is you are referencing Text2 in the loop for every record you're trying to save:

MyRecord.Name = "MyName" & "  " & Text2.Text 

The other problem I see (or one that will cause you problems later) is you're using a ListBox and combining record properties into one item to simulate columns:

List1.AddItem myRecord.ID & "  " & myRecord.Name

Use a ListView control set to reportview and separate the ID and Name into listview columns:

    Dim itmx As ListItem
    Set itmx = ListView1.ListItems.Add()
    itmx.Text = Text1.Text
    itmx.SubItems(1) = Text2.Text

There's a long post of similar issues here: Click Here

SCBWV 71 Junior Poster

What about SMS text verification? Probably more expense, although I'm not sure how much.

SCBWV 71 Junior Poster

There doesn't seem to be a space after the comma in ",for" for it to break on.

SCBWV 71 Junior Poster

Happy New Year everyone! Wishing you and yours and happy, prosperous, and healthy new year!

SCBWV 71 Junior Poster

You're welcome.

SCBWV 71 Junior Poster

You're quite welcome. You Text3 value is actually the reversing of pairs, not a simple reverse of the string. Try this:

    'This assumes Text1 will always be 18 characters long. Test for it or pad it to 18 characters.
    Dim tmp As String
    Text1.Text = "80ad0120327405c1d8"
    'Last 8 characters
    Text2.Text = Right$(Text1.Text, 8)
    'Simple reverse of the 8 character string
    Text3.Text = StrReverse(Text2.Text)
    'Revering pairs of the 8 characters
    For j = 9 To 1 Step -2
        tmp$ = tmp$ & Mid$(Text2.Text, j, 2)
    Next
    Text4.Text = tmp$
SCBWV 71 Junior Poster

This is how I would do it...

SCBWV 71 Junior Poster

I've changed the tab control to an SSTab than the tab strip. The SSTab is much easier to work with. I added ShellExecute, which handles loading all your links now. It's never a good idea to hard code paths to installed programs, as you can never be sure where a user chose to install, Also, I have neither FireFox nor Chrome, so your code would never work for me.

I haven't a clue what you're trying to achieve with the ListViews in the Links tab. Perhaps if you explain how you intend them to work, I might be able to help?

SCBWV 71 Junior Poster

That's why I suggested overwriting the text with the ListView items. Blank lines would be eliminated automatically.

The only way I know how to eliminate blank lines without the ListView method is to:

  1. Open the text file
  2. Create a temporary text file
  3. Read the text file line by line, outputting it to the temporary text file if the line is not blank
  4. Close the text file
  5. Close the temporary text file
  6. Delete the text file
  7. Rename the temporary file to the old text file name

As you can see, this is a LOT more clunky than:

  1. Open text file
  2. For each itm in LivewView1.ListItems output the item text and subtitems to the text file
  3. Close text file
SCBWV 71 Junior Poster

I never had the deletion create a blank space in the data file. However, you can test for it in the PopulateListview sub as such:

        If LenB(Tmp$) Then
            Result = Split(Tmp$, "|")
            Set itmx = ListView1.ListItems.Add()
            itmx.Text = Result(0)
            itmx.SubItems(1) = Result(1)
            itmx.SubItems(2) = Result(2)
            itmx.SubItems(3) = Result(3)
        End If
SCBWV 71 Junior Poster

See if this works. You had a problem in the Delete Data sub. Your DataFile was pointing to Notes.Txt instead of Tickets.txt. Also, you Dim'd a variable called remove, which is a keyword for ListViews, so I changed it. There was an issue with the Sites combobox not getting populated after you delete an item because you clear in the Clear fields sub. By changing it to a dropdown combo, you can clear the text of the ComboBox without clearing the list it contains, which I've done.

SCBWV 71 Junior Poster

Well, so far, I can see an error when deleting an item. There's an invalid index error in the PopulateListView3 Sub because you're trying to assign SubItems 4 and 5 when ListView3 doesn't have that many columns. There's no direct way I can recall of deleting a specific data line from a text file without reading each line and comparing it to the desired item. It would take two text files - reading the source lines and outputting them to another text file if the line isn't the one to be deleted. Deleting the source and renaming the new text file. That can get messy in a hurry. I have never received an error you mentioned about reading past the end of the file or the "ENTER" as you called it. Can you tell me what steps to take to reproduce the error so I can help you?

The easiest way is to rebuild the text file based on the ListView each time the ListView changes. The text file would be overwritten, thus eliminating the item that was deleted.

Your project has now grown to having multiple text files used as a database table with 8 or 9 "fields." It's going to start getting complicated. At some point, you should consider using a database program to manage your data files. You can use the standard controls you have or consider using the ADO control with data bound controls such as the list. Would make your program much easier to …

SCBWV 71 Junior Poster

I can't test it because there's no longer a subroutine called Clear_Fields in Form1. The Delete button seems to work for me in Form2.

SCBWV 71 Junior Poster

The project has gotten a lot more complex. Starting to shape up nicely. I fixed the search. The out of bounds error happens when you use the count property in your for/next loop and delete an item inside the loop. You'll see how it's fixed. Your Sites and Status error occurred because DataFile is a public variable and your routine changed the value, so you were opening the wrong file. Fixed. I'm not sure what is not working for Form2. Can you explain further?

Two suggestions:

  1. Sort your procedures alphabetically. It helps find subroutines.
  2. You are using control arrays but not taking advantage of the purpose. Thus, you have a quite a few command button routines. You should consider consolidating these and using Select Case Index, where appropriate. Can save that for next time.
SCBWV 71 Junior Poster

What errors did you get?

SCBWV 71 Junior Poster

Not to mention line 54 is a mess.

Thao_14 commented: yeah I don't know how to make it shorter +0
SCBWV 71 Junior Poster

After you create your .EXE there are 3 ways you can use to create an installation file / package.

  1. The Package and Deployment Wizard that is part of VB6. It should be on your Start menu.
  2. Visual Studio Installer (my preferred method, though a bit more complicated). I don't recall where VSI came from - the MSDN Library or downloaded.
  3. A commercial package such as SamLogic (https://www.samlogic.net/visual-installer/visual-installer.htm) or Wise Installer.

All 3 will read your project and ensure that all dependencies are copied and installed properly. Options 2 and 3 offer much more flexibility, though a steeper learning curve.

SCBWV 71 Junior Poster

Here's version 5 with a ListView. All functions work - search, delete, add, etc. It seems to me to be a lot less code than your previous versions. I included code to automatically resize the columns based on the contents. I also included code to sort the rows based on a column. Click the column header to sort ascending, click again to sor descending. This about the best I can do with my understanding of what you're trying to accomplish. Best wishes.

SCBWV 71 Junior Poster

I couldn't open the Excel file. Perhaps it's not compatible with my version. Trying to implement columns in a ListBox is much more complicated and requires a lot more code than using a ListView, if at all possible. Columns in a ListView can be programmatically set to the width of the contents with the Windows SendMessage function and the LVM_SETCOLUMNWIDTH parameter. A ListView would eliminate a large portion of your code, particularly that dealing with the memory arrays. A ListView also allows the user to set the column width as they desire, and can also be programmed to allow sorting rows based on a selected column.

Alternatively, you could use a DataGrid and an Access database to handle your record functions.

SCBWV 71 Junior Poster

I couldn't open the Excel file. Apparently, it's not compatible with my version. There's no easy way to do what you want with a ListBox. It's much easier, and a lot less code, with a ListView. You can also programmatically adjust a ListView columns to fit the longest data in each column. I don't see the logic in using a ListBox, but I could be missing something.

SCBWV 71 Junior Poster

You can simulate columns in a ListBox by including a tab in the text string

ListBox1.AddItem "Column 1" & vbTab & "Column 2"

Again, with variable length strings, it may not align perfectly, so you may have to add additional tabs based on the length of the strings.

SCBWV 71 Junior Poster

When you install your app on another system, the .ocx will be installed along with your app.

SCBWV 71 Junior Poster

I'm not sure what you're trying to achieve by using a ListBox over a ListView. Columns in a ListBox is overly complicated to implement in code and has the disadvantage of columns not aligning when text is longer than the space allotted for the column. Additionally, columns in a ListBox does not allow the user to adjust the column width to their desired size. The ListBox does have a column property, but that only changes the scrolling behavior from vertical to horizontal. An example is provided in the Help (F1) for the Column property.

Perhaps I can provide a better answer if I knew why you want to use a ListBox instead of a ListView.

SCBWV 71 Junior Poster

Option Explicit forces you to declare all variables before they are used with Dim, Private, Public, ReDim, or Static statements. All your variables were declared except:

Dim Tmp As String
Dim Result() As String

in PopulateListview. Using Option Explicit is a good habit as it can help avoid incorrectly typing the name of an existing variable, which would be apparent when it raises an error.

SCBWV 71 Junior Poster

My thoughts and changes.

SCBWV 71 Junior Poster

Try this. I made significant changes. If you have any questions about the code, let me know.

SCBWV 71 Junior Poster

Sorry. I didn't notice the dates were Day/Month/Year and not Month/Day/Year.

Fixed.

SCBWV 71 Junior Poster

Fixed. I added several comments to the code to help explain. Also added a subroutine for the Combo1_Click event.

Best wishes.

SCBWV 71 Junior Poster

I'd be glad to, but I don't use .rar files so I have no way of opening your attachment.

SCBWV 71 Junior Poster

Attached.

SCBWV 71 Junior Poster

Use a ListView control and set it's View to lvwReport. Then in the Properties, add the number of columns - in this example 4. Add column headers if desired.

    ListView1.ListItems.Clear
    fNum = FreeFile
    Open "users.txt" For Input As #fNum
    Do Until EOF(fNum)
        Input #fNum, Tmp$
        Result = Split(Tmp$, "|")
        Set itmx = ListView1.ListItems.Add()
        itmx.Text = Result(0)
        itmx.SubItems(1) = Result(1)
        itmx.SubItems(2) = Result(2)
        itmx.SubItems(3) = Result(3)
    Loop

This will result in the screenshot attached.

Best wishes.

Example.jpg

SCBWV 71 Junior Poster

What does the contents of the users.txt file look like? Send a few lines and I'll send you the loop. Also, why are you saving the lines in the nmInfo array?

SCBWV 71 Junior Poster

Use a ListView, then add SubItems

For example:

        Set itmx = ListView1.ListItems.Add()
        itmx.Text = FirstColumnText$
        itmx.SubItems(1) = SecondColumnText$
        itmx.SubItems(2) = ThirdColumnText$

etc.

Be sure to change the View to 3 - lvwReport

SCBWV 71 Junior Poster

Congratulations! Sounds like a great month even if quite busy. Where did you honeymoon?

SCBWV 71 Junior Poster

I think it's wonderful, at nearly 80, that you decided to continue programming. I admire your ambition. I have written countless programs that no one will ever use except me, and I thoroughly enjoyed writing them. Go you!

SCBWV 71 Junior Poster

Has anyone experienced the function Windows SystemParametersInfo reporting a different display resolution after returning from sleep mode? My display is 3840X2160, which the SystemParametersInfo reports accurately. However, upon returning from sleep mode, SystemParametersInfo gives a resolution of 2560x1392, which doesn't match any configuration in the Windows Registry under Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\GraphicsDrivers. The actual screen resolution has not changed - the desktop is 3840X2160, but the function reports 2560x1392.

Waiting a while thinking everything hasn't woken up yet doesn't seem to help. Problematic when your program needs to find the right edge of the screen.

SCBWV 71 Junior Poster

Agreed! Moving to a current language has many benefits. I'm sure for some it's not possible. Having said that, I'd be a little bit leary of one from MS (other than C++ C#) as they seem to abandon languages often.

SCBWV 71 Junior Poster

Understood. I was just posting for the many people that have no choice but to maintain VB6 code for love or money. As I understand it, there is still LOTS of critical business code in VB6 for one reason or another. Thus the continued work from MS to ensure VB6/VBA still runs, while not supporting the language or its development.

SCBWV 71 Junior Poster

In case you're wondering, VB6 programs run on Windows 11. Programs with a manifest have the appropriate Windows 11 appearance. The IDE works as well, although it seems to aggravate the known Windows 11 Taskbar flickering issue, but it settles down quickly.

The only issue I have found so far is that command button mnemonics do not appear after pressing the Alt key is you use a manifest. This can be solved by 1) not using a manifest file, or 2) changing the Windows setting to always show mnemonics.

Please note, I started with Windows 10 and upgraded to Windows 11. I assume an original Windows 11 install would work the same.

Best wishes to all.

SCBWV 71 Junior Poster

Good example using the Sieve of Eratosthenes algorithm - http://www.codeguru.com/columns/vb/article.php/c6575

SCBWV 71 Junior Poster

Are you using VBA in Access or Visual Basic 6?

SCBWV 71 Junior Poster

Try Format$(Number, "##-####"). If you want leading zeros, use Format$(Number, "00-####") or Format$(Number, "00-0000")

To be consistent, you can make the "00-0000" a public constant.

SCBWV 71 Junior Poster
SCBWV 71 Junior Poster

Form is a key word in VB. Try changing it to something else like frm.

SCBWV 71 Junior Poster

Your code would probably be more efficient and more readable with a Select Case block instead of the IF, ElseIf.

Select Case dbltotalaverage
    Case 90 To 100
        txtgrade.Text = "A"
    Case 80 To 89
        txtgrade.Text = "B"
   Case 70 To 79
        txtgrade.Text = "C"
   Case 60 To 69
        txtgrade.Text = "D"
   Case Else
        txtgrade.Text = "F"
End Select
SCBWV 71 Junior Poster

Like you, I developed a very specialized piece of software into a decent side venture. Lots of seemingly small decisions to be made. There's some good reading here doc... http://www.developer-resource.com/index1.html

While I haven't always followed their advice, it did help in the thinking process. Don't rush your decisions. Some, such as pricing and support are tough to reverse.

If you sell your code, you don't get to sell it to other hospitals. The developer that buys your code will want exclusive right, I'm sure. If the hospital bought your "code," I'm sure they would like to sell it to other hospitals to recoup their investment.

You sell a license to use your program. Even here there's decisions to be made. Are you selling a site license or the right to use it on one machine? Does the site license restrict it to one facility or every facility in the management's group?

There may be partnership opportunities to consider as well, such as you retaining the rights to the code and the hospital uses its resources and connections to market the program to other facilities. Here again, decisions - how long does the relationship last? Current version? Every subsequent version? X number of years?

My advice... go slow or you could leave a lot of money on the table.

SCBWV 71 Junior Poster

DateDiff can be used to calculate the difference between times - http://msdn.microsoft.com/en-us/library/aa262712(VS.60).aspx

SCBWV 71 Junior Poster

You need to update your VB6. Microsoft patched the MSVBVM60.DLL to fix the problem. Try here - http://msdn.microsoft.com/en-us/vbrun/aa662927.aspx

SCBWV 71 Junior Poster

Error 453 means the DLL function specified was not found within the DLL. Try making the Sub Public.