How to (actually) load RichTextBox from VB.NET in VS2022 - vb.net

Have spent hours on hours exploring "solutions" that surely worked for someone, sometime, somewhere.
Alas NONE seem to work when I try to do so creating a Windows Desktop App using VB.NET in VS2022. Has something changed? Am I just plain dense.
Tried the obvious... RichTextBox1.Text = File.ReadAllText("C:\Temp\Results.txt"), followed by several alternatives, e.g. moving the file to the \bin file of the code etc. ALL futile.
Will TRY to add screen shots of significant issues, e.g. does the file exist... I say try because haven't yet learned how to deal with the "add Text File where stateda picture: feature, beyond adding only one.
Text file content in Notepad
Simple Code that fails

This is C# code if you Google C# to VB.Net you will find a code converter
Now that you have the naming issue solved and the Path correct This code will load txt data to a listBox just change the name for your RichTextBox
You might like to consider SQLite if you want to store data much better!
private void btnMakeDB_Click(object sender, EventArgs e)
{
listBox.Items.Clear();
using (StreamReader sr = new StreamReader(path))
{
string line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
listBox.Items.Add(line);
textBox.Text = line;
}
}
}

Related

Displaying NLog in date descending order

I am using NLog with a VB.Net project:
Private m_logger As NLog.Logger = LogManager.GetCurrentClassLogger()
Issues are populated in the log like this:
Catch ex As Exception
Console.WriteLine("Error: {0}", ex.Message.ToString())
m_logger.Error(ex, "ExtractCalendarInformation")
End Try
Now, this VB too is a console app that is used my another application which is written with Visual C++. If the parent app has detected that there are problems it displays the log file:
void CMeetingScheduleAssistantApp::ShowLogFile(CString strLogFile)
{
if (PathFileExists(strLogFile))
{
CLogDlg dlgLog;
CTextFileRead fileLog(strLogFile);
CString strText = _T("");
fileLog.ReadLine(strText);
while (!fileLog.Eof())
{
strText.Trim();
if (strText.IsEmpty())
continue;
dlgLog.AddLogEntry(strText, true);
fileLog.ReadLine(strText);
}
dlgLog.SetErrorMode(true);
dlgLog.DoModal();
}
}
The problem is that the log file is in date ascebdung order and sometimes users send me screen shots and don't scroll.
Is there anyway to display this error log from Nlog in fdate desending order? And I don't think it is OK to just read the file in reverse.
I include both VB and C++ tags since I might have to make changes in either tool.
I saw this question Write records in descending order in NLog. The thing is my C# tool uses SimpleLogger and that creates log folders in a folder and the log is named by date, and all items in that log are date descending. But I can't use SimpleLogger with VB.Net I don't think.
One option could be to load the file into a vector<CString>, and then just use rbegin() for reverse iteration and inserting file-contents into the dlgLog.
Another option is to investigate how update scrollbar in CTextFileRead after having loaded the file, so scroll-button is moved down to the bottom.
Update
I actually was using CEdit control to display the log contents. So in the end I used the following code to automatically scroll to the bottom:
m_editLogData.LineScroll(m_editLogData.GetLineCount());

Converting .doc to .pdf in java (for free)

I created a java app that create some documents in output. The documents are created with apache POI api and are made of text abn tables.
My boss now decided they also want them in pdf format for storing them. They of course have 0$ budget. I tryed using iText 4.2 (which comes under lgpl license) but i lost all tables (I'm having only naked text)
This is my script:
try{
XWPFDocument doc = new XWPFDocument(POIXMLDocument.openPackage(s + ".doc"));
XWPFWordExtractor wx = new XWPFWordExtractor(doc);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(s + ".pdf"));
document.open();
writer.setPageEmpty(true);
document.newPage();
writer.setPageEmpty(true);
String text = wx.getText();
text=text.replaceAll("\\cM?\r?\n", "");
document.add(new Paragraph(text));
}
catch(Exception e){
System.out.println("Exception during test");
e.printStackTrace();
}
Any help? Even a change of direction would be great. I was wandering if I could simply write a macro that open the doc, type save as, and save it as pdf with same name. Launching it eventually inside java app.
Thank you
You might want to take a look at this, pretty similar question.
I wrote an answer there which is not tested yet since i got no time to do so. But it might sill solve your problem or atleast give you some hints for further researches.

ObjectARX SDK for c#

For last two days I have looking for sample code with steps which may help me to understand the Autocad API. so I can use the code in C#.
[CommandMethod("LISTGEn")]
public static void ListEntities()
{
Document acDoc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Open the Block table record for read
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,OpenMode.ForRead) as BlockTable;
// Open the Block table record Model space for read
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],OpenMode.ForRead) as BlockTableRecord;
int nCnt = 0;
acDoc.Editor.WriteMessage("\nModel space objects: ");
// Step through each object in Model space and
// display the type of object found
foreach (ObjectId acObjId in acBlkTblRec)
{
acDoc.Editor.WriteMessage("\n" + acObjId.ObjectClass.DxfName);
nCnt = nCnt + 1;
}
acDoc.Editor.WriteMessage(nCnt.ToString());
// If no objects are found then display a message
if (nCnt == 0)
{
acDoc.Editor.WriteMessage("\n No objects found");
}
// Dispose of the transaction
}
}
I can run the above code, but it's not functioning properly. It's difficult for me to understand how to get it work with Autocad. I have OjectARX SDK referenced,
I am working with VS2010 and Autocad 2012. Thank You for your help.
Ok, I got it only thing that is being required
1.) is to create a class library
2.) Then need to enter the above code in the class.
3.) Build your project by pressing F5.
4.) A DLL will be created in the bin/debug/ folder of your project
5.) Open Autocad.
6.) Write netload command.
7.) Select the DLL created and then write command "LISTGEN" and than kaboom it will show all the objects in your project.
To avoid having to manually netload your dll, you can use a temporary fix for debugging and write a lisp file to do it for you
(Command "netload" "path/to/your/.dll")\n
Or you can use \\
Take a look at my github. The link is on my profile. Look over the reference library, it's highly simplified for object model manipulation.
If you have any questions feel free to email me.

an error 3013 thrown when writing a file Adobe AIR

I'm trying to write/create a JSON file from a AIR app, I'm trying not so show a 'Save as' dialogue box.
Here's the code I'm using:
var fileDetails:Object = CreativeMakerJSX.getFileDetails();
var fileName:String = String(fileDetails.data.filename);
var path:String = String(fileDetails.data.path);
var f:File = File.userDirectory.resolvePath( path );
var stream:FileStream = new FileStream();
stream.open(f, FileMode.WRITE );
stream.writeUTFBytes( jsonToExport );
stream.close();
The problem I'm having is that I get a 'Error 3013. File or directory in use'. The directory/path is gathered from a Creative Suite Extension I'm building, this path is the same as the FLA being developed in CS that the Extension is being used with.
So I'm not sure if the problem is that there are already files in the directory I'm writing the JSON file to?
Do I need to add a timer in order to close the stream after a slight delay, giving some time to writing the file?
Can you set up some trace() commands? I would need to know what the values of the String variables are, and the f.url.
Can you read from the file that you are trying to write to, or does nothing work?
Where is CreativeMakerJSX.getFileDetails() coming from? Is it giving you data about a file that is in use?
And from Googling around, this seems like it may be a bug. Try setting up a listener for when you are finished, if you have had the file open previously.
I re-wrote how the file was written, no longer running into this issue.

I can't get netbeans to find a txt file I have in the same directory... java.io.FileNotFoundException

I can't make it path specific because once I get this program to work (this is the last thing I have to do) I'm uploading to my university's ilearn website and it has to run on my professors computer with no modifications. I've tried a few different amalgamations of code similar to the following...
File file = new File("DataFile.txt");
Scanner document = new Scanner(new File("DataFile.txt"));
Or...
java.io.File file = new java.io.File("DataFile.txt");
Scanner document = new Scanner(file);
But nothing seems to work. I've got the necessary stuff imported. I've tried moving DataFile around in a few different folders (the src folder, and other random folders in the project's NetBeansProjects folder) I tried creating a folder in the project and putting the file in that folder and trying to use some kind of
documents/DataFile.txt
bit I found online (I named the folder documents).
I've tried renaming the file, saving it in different ways. I'm all out of ideas.
The file is just a list of numbers that are used in generating random data for this program we got assigned for building a gas station simulator. The program runs great when I just use user input from the console. But I can not get netbeans to find that file for the life of me! Help!?!?!?
Try adding the file to build path ..
public void readTextFile (){
try{
Scanner scFile =new Scanner(new File("filename.txt");
while(scFile.hasNext()){
String line =scFile.nextLine();
Scanner details=new Scanner(line).useDelimiter("symbol");
than you can work from there to store integer values use e.g in an array
litterArr(size)=details.nextInt();
Note: size is a variable counting the size/number of info the array has.
}
scFile.close();
{
catch
(FILENOTFOUNDEXCEPION e){
..... *code*
}
Keep file in the same folder as the program,but if it is saved in another folder you need to supply the path indicating the location of the file as part of the file name e.g memAthletics.Lines.LoadFromFile('C:\MyFiles\Athletics.txt');
hope this helps clear the problem up :)