[SOLVED] Real Studio code to write checked items from list box to a new .txt file help

Steve

Rebuilding slowly but getting there ..
Staff member
This is very easy to say but for me to find any example of code to work with is impossible, as I have searched for some time now. run test.exe and you will see what I am trying to do, if it is possible.

I found the fix for the shout box help I shouted about -
Today at 8:49 AM - Glenn: Dat = String.ReplaceAll(Data, "Package '", "")

I was actually able to do it and it works perfect for the simple space in the name situation, THANKS @Glenn

Thanks, Steve
 
Sorry I don't have RealStudio anymore so I done my best in Xojo, you have the main part, so here's the rest:

You wont need this as your list is populated:
Code:
Dim I as Integer
'Listbox1.ColumnTypeAt(0) = Listbox.TypeCheckBox
Listbox1.ColumnTypeAt(0) = DesktopListBox.CellTypes.CheckBox
For I = 0 To 100
  ListBox1.AddRow()
  Listbox1.CellTextAt(I,0) = Str(I)+" Test"
Next

Here is the code from the Button Pressed event I use to extract the Checked data only, then you can write it directly to a file or whatever:
Code:
Dim I As Integer
Dim KeptText As String
For I = 0 To 100
  If Listbox1.CellCheckBoxValueAt(I,0) = True Then KeptText =KeptText + Listbox1.CellTextAt(I,0) + Chr(10)
Next I
MsgBox KeptText

As I am using xojo your CellCheckBoxValueAt may be different, but it will work the same, you give a cell position (Row, Column) and it will tell you the value of True or False.
 
Thanks for trying to help, unfortunately it did not work, even in XOJO, NilObjectObjection error ever where, even in the original code that worked in Real Studio does not work in XOJO
View attachment 2535
 
Sorry I never realised you hadn't figured out how to get the list count so you don't get that error, I just assumed you knew it :D

For I = 0 To Listbox1.RowCount-1

You can only scan through the items available, so my 100 was way out of your range. Nil means no object is available at the integer your checking. it usually means you've gone outside the last item available.

Changing the one line will stop that error. I have been cleaning the shed today and mowed/whiper snipped the edges etc. so haven't been able to help.

If you wanted you can put a check to make sure any items pre exist:

If Listbox1.RowCount >=1 Then
For ...

End If

This will make sure it never nil's out on you again.

Happy to help you learn to program and like you said, finding good current examples is hard, the included ones are ok, but I generally google:

Xojo ListBox and it'll find the help for it or some others code. I also often type ListBox1. and see what comes up and then go read about each option.

I take it you'll need a hand getting the Shell commands working next :) so you can run things with the checked items :)

If you share the goal of your project I can do a basic template that works and you can add features to it or adjust/bug test it. I just need to know what your plan is for the project as I can say from experience, each step will fight you, very rarely will something just work first try :)
 
I feel like I am missing a count of the check boxes to the row number to pull the info from that line, does this make since.

I have code to give me the Listbox1.ListCount , so this is correct which is 46 , depending on the image loaded the number will be different, but I can not get how many check boxes is checked in a msgbox, I feel that is the issue, no count for how many checked boxes and which number in the listbox.

How did you do ssWPI to add all the apps , etc, to mini installer? Check boxes , what am I missing?

this is as close as I got to getting a good return see image, Message box popped up 5 times ( note checked boxs is 5 ) with full list in message box which is a step forward.

View attachment 2537
 
Last edited:
Ok, I got a count of the boxes that is checked so here is the code I have now in Bevelbutton1.Action

Code:
  // yep nothing here as my code just simple did not work LOL
  // new .txt file can be named test.txt , I can code all the other in with no problems
  // just not the listbox items checked written to new .txt file
 
  // MsgBox "no code to work with"
 
  Dim Count As Integer
  Dim I as Integer
  For I = 0 To Listbox1.ListCount -1
    If Listbox1.CellCheck(I,0) = True Then
      Count=Count+1
   
      //////// Listbox1.TypeCheckbox=2   /// gives a string of True  /// Listbox1.TypeCheckbox=1 gives a string of False
      //////// MsgBox str(Listbox1.TypeCheckbox=2)
      //////// Str(Listbox1.ListCount) /// gives the number of items in the list box which is 46 using the packagesedt.txt file
      //////// MsgBox "Str(Listbox1.ListCount)
      // MsgBox ListBox1.Text + "       "+ Str(Count)
   
    Else
      //  just here for testing
    End If
  Next I
 
  MsgBox Str(Count) ///// this gives the total check boxes that is checked so this works
  //MsgBox Str(Listbox1.ListCount)
 
Code:
Dim ItemsChecked As String
 Dim Count As Integer
  Dim I as Integer
  For I = 0 To Listbox1.ListCount -1
   If Listbox1.CellCheck(I,0) = True Then
     Count=Count+1
     ItemsChecked = ItemsChecked + Listbox1.CellText(I,0) + Chr(10)
  
     //////// Listbox1.TypeCheckbox=2   /// gives a string of True  /// Listbox1.TypeCheckbox=1 gives a string of False
     //////// MsgBox str(Listbox1.TypeCheckbox=2)
     //////// Str(Listbox1.ListCount) /// gives the number of items in the list box which is 46 using the packagesedt.txt file
     //////// MsgBox "Str(Listbox1.ListCount)
     // MsgBox ListBox1.Text + "       "+ Str(Count)
  
   Else
     //  just here for testing
   End If
  Next I

If you use MsgBox ItemsChecked it'll print only the checked items, Chr(10) is end of line (next line).


I simply added this line:
ItemsChecked = ItemsChecked + Listbox1.CellText(I,0) + Chr(10)

If you want it to go to another DB then use

ListBox2.AddRow (Listbox1.CellText(I,0))

So there is a lot you can do with the info you have.

If you grab my latest LLStore it has some new methods I am proud of, such as SaveDataToFile (Data, FilePathAndName), this will make the file and put the data in it, with some error checking in place, I do still need to add some read only checks, but that can happen later.
 
WELL since it is XOJO code you are posting I moved to try the test.rbp in XOJO and I get a error of NilObjectException in a comiled XOJO .exe which this code has worked perfectly since Last7 builder erra LOL yes been a good while, so I added MsgBox "Pass 1" pass2 etc to catch where does it break it breaks on after pass 2 , I never see pass 3, that is when it NOE error

View attachment 2546

Code:
dim St As String
dim F as FolderItem
Dim Ls, Rs As String
Dim textInput As TextInputStream

MsgBox "Pass 1"

//// new code to read a .txt file and add to listbox with check box/s /////
try
  f = GetFolderItem(AppPath+"\packagesedt.txt", FolderItem.PathTypeShell)
catch NilObjectException

end try

MsgBox "Pass 2"

' read the txt and write it to the listbox
textInput = TextInputStream.Open(f)

MsgBox "Pass 3"

While Not textInput.EOF
  MsgBox "Pass 4"
  St=textInput.ReadLine
  Ls = Uppercase (Left(St,InStr(0,St,"=")))
  Rs = Right(St,Len(St)-Len(Ls))
  Select Case Ls
  Case "PackageName="
  
    //msgBox (Rs) // works move on with more code
    Listbox1.AddRow (Rs)
  
  End Select
Wend
textInput.Close
 
Last edited:
Also in XOJO this line has issues as for XOJO says there is no member for
Listbox1.CellText

.CellText is not in the list of what is usable, man this is rough oof
 
BINGO found it! this right here did it in RS , I can not believe it was that short of a line of code that made it work

MsgBox listBox1.cell(I,0)+EndOfLine


Code:
Dim I as Integer
  For I = 0 To Listbox1.ListCount -1
    If Listbox1.CellCheck(I,0) = True Then
      Count=Count+1
      MsgBox listBox1.cell(I,0)+EndOfLine ///// gives the checked item message box text from the row textfield
      //////// MsgBox Str(Count)+Str(Listbox1.SelCount)
      //////// Listbox1.TypeCheckbox=2   /// gives a string of True  /// Listbox1.TypeCheckbox=1 gives a string of False
      //////// MsgBox str(Listbox1.TypeCheckbox=2)
      //////// Str(Listbox1.ListCount) /// gives the number of items in the list box which is 46 using the packagesedt.txt file
       // MsgBox Str(Listbox1.ListCount)
      // MsgBox ListBox1.Text + "       "+ Str(Count)
    
      // Else
      //  just here for testing
    End If
  Next I
 
No, eol is CRLF, chr(10) is just LF. But chr(13) is meant to be CR, in windows it self LF but not in Linux, so I switched to chr(10) for everything except multiline text areas, these require Chr(13) or they are one continuous stream of text.

These are the kinds of bugs I've been working around for years. Over half my programming is spent fixing other people's bugs and limitations built into their languages. Not that I can do a better job. But I can spot bugs everywhere. It makes the illusions PCs give harder to believe. I am actually amazed there aren't more total system crashed. But there have been some very smart people who got the core level stuff so impressively built and optimised that it does work.
 
Back
Top