|
Hi guys,
i have a vb.net application that watched a folder and whenever a rtf file is dropped i want to read the text an save it to a txt file.
here's my code
Dim word_app As New Microsoft.Office.Interop.Word.Application
Dim word_doc As New Microsoft.Office.Interop.Word.Document
word_doc= word_app.Documents.Open(in_file, False, True, False, , , , , ,Microsoft.Office.Interop.Word.WdOpenFormat.wdOpenFormatRTF)
word_doc.ActiveWindow.Selection.WholeStory()
word_doc.ActiveWindow.Selection.Copy()
str = My.Computer.Clipboard.GetData(GetType(String).ToString)
'word_doc.SaveAs(out_file, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatText)
doc.Close(False)
word_server.Quit()
Dim sr As New IO.StreamWriter(out_file, False)
sr.Write(str)
sr.Close()
this is running on the a windows 2008 rc2 server as a window service.
the error messaage is "Object reference not set to an instance of an object"
if there is another simpler way please advise.
thank you kindly
Anoop
|
|
|
|
|
Hi,
the line which reads
doc.Close(false)
should that be
word_doc.Close(false)
And also, you have an object named word_server, where is that declared?
|
|
|
|
|
hi,
sorry i tried to make it more readable for you guys. i seemed to have mis-renamed the var on this snippet.
thanks
|
|
|
|
|
I suggest you forget about Word and experiment with a RichTextBox. You could set its Rtf property to load the RTF file content; then get its Text property. I haven't done this at any length, however the doc seems to suggest it would return the document content without any markup.
BTW: IMO the RTB does not have to be visible, nor part of any Form for this.
PS: As there are different levels of the RTF specification, it could happen that Word is more capable than an RTB, so complex documents might fail. I just don't know, I wish I did.
|
|
|
|
|
agreed, here is the function you can use..
Sub convertRTFtoText(ByVal in_file_path As String, ByVal out_file_path As String)
Dim rtb As New RichTextBox
rtb.LoadFile(in_file_path) 'this is your rtf file path
IO.File.WriteAllText(out_file_path, rtb.Text) 'this is your txt file path
End Sub
|
|
|
|
|
thanks,
i have used something similar.
Me.RichTextBox1.LoadFile(in_file)
Dim sr As New IO.StreamWriter(out_file, False)
sr.Write(Me.RichTextBox1.Text)
sr.Close()
thanks guys!
|
|
|
|
|
Hi,
I'm a bit of a lurker around here, love reading the articles, but as I'm not a programmer in anything other than the loosest of definitions, am unable to contribute much. I ask your indulgence with the following:
My 'programming' until now has been largely in VB (6 and earlier) and mainly done to fill some gap in the OS, or other specific need. I'm actually proud of many of these little utilities as many of them have continued to make my life easier for many years, despite being constructed in something of a spaghetti fashion - copying of other peoples code (leagally!) plus my own.
I have my own IT consulting business, supporting several hundred users across many small businesses and some of these programs are still in use. It is becoming obvious though, particularly as we move to Windows 7, that many of these old programs really should be reconstructed in a modern language. Additionally, there is a need for some new types of tools for use in our business. With a lot of help from the code samples on this site, I have even created my first such project - about 2000 lines of VB.Net code. The program works well, but I'm certain that it would seems 'confused' to an experienced eye.
I'm keen to get a bit better/more confident/maybe faster at this programming caper and have some basic questions - but I don't want to kick off any religious wars . I'm thinking that the best way to acheive this is to purchase a book and read it, but which book...
- VB.Net/C#.Net - I've mostly done VB 6 in the past, but C# code does make some sort of sense to me.
- Development environment - Visual Studio Express/Pro/Sharp Develop (why did they drop standard?). I need add-ins, services, probably the ability to create Office Add-Ins. I think that means I need to get VS 2010 Pro, or can Express do this stuff, its just templates, any thoughts?
- Winforms/WPF/WCF - I barely understand the differences, I feel I'll mostly use Winforms. How do you decide which is 'best'. Don't believe there will be much need for web based apps.
Lastly, this will probably be covered by simply learning the language/environment better, but .Net often has several ways to achieve what seems to be the same result. How do you know the best way, and determine the best layout for a project - this function in module x, that one in module y.
I know this is long, I'm sorry.
Thanks,
Rod
|
|
|
|
|
RodClark wrote: - VB.Net/C#.Net - I've mostly done VB 6 in the past, but C# code does make some sort of sense to me.
This is largely a matter of preference. But, there are little things that VB.NET does that C# can't (yet) and things that C# does that VB.NET can't do (unsafe code, pointers, ...)
The books are going to be language specific but cover the same topics. But for a newbie, I'd tend to lean toward C#.
RodClark wrote: - Development environment - Visual Studio Express/Pro/Sharp Develop (why did they drop standard?). I need add-ins, services, probably the ability to create Office Add-Ins. I think that means I need to get VS 2010 Pro, or can Express do this stuff, its just templates, any thoughts?
If you're doing Office Addins, plugins, services, ... I'd go with the Pro edition instead of Express. Express has limitations that are not because of an absense of project templates.
RodClark wrote: - Winforms/WPF/WCF - I barely understand the differences, I feel I'll mostly use Winforms. How do you decide which is 'best'. Don't believe there will be much need for web based apps.
Winforms is pretty much what you've been using in the older versions of VB. WPF is an entirely different way of creating Windows applications that isn't as restricted to the "fill in forms" methodology of Windows apps. WPF lets you create much richer UIs for your apps, but the learning curve is pretty steep. Which one is 'best' is determined by your apps requirements and your choice.
The choice is up to you and your project. Most utilities are not going to benefit too much from WPF...
WCF is Windows Communication Foundation and it handles communications between applications and services.
RodClark wrote: Lastly, this will probably be covered by simply learning the language/environment better, but .Net often has several ways to achieve what seems to be the same result. How do you know the best way, and determine the best layout for a project - this function in module x, that one in module y.
You only get this with lots of experience in object oriented design and very good requirements gathering. There is no way for anyone to describe how to determine the 'best' way to solve any one problem. The 'best' method can change with the smallest requirement change in your app. It comes down to the set of problems you're trying to solve and knowing which techniques are going to work better in each situation. Again, lots of experience.
|
|
|
|
|
RodClark wrote: I'm thinking that the best way to acheive this is to purchase a book and read it, but which book...
I found the Head First[^] series a good read, though it's more a learn-by-doing style book. It's not a book you'd read in the train, unless you have a compiler at hand. Another good reference would be the How Do I-video's[^] on MSDN.
RodClark wrote: VB.Net/C#.Net - I've mostly done VB 6 in the past, but C# code does make some sort of sense to me.
How 'bout going for C#, and googling for the matching VB.NET syntax to compare it to? Seeing the same construction through two different glasses helps.
RodClark wrote: I think that means I need to get VS 2010 Pro, or can Express do this stuff, its just templates, any thoughts?
If I recall correctly, you'd need the Pro version to use the VSTO (Visual Studio Tools for Office) extensions. The Pro-version also allows to add in helpful extensions like Resharper, giving helpfull tips in the IDE.
RodClark wrote: Winforms/WPF/WCF - I barely understand the differences, I feel I'll mostly use Winforms. How do you decide which is 'best'.
The YAGNI[^]-princple would be the first filter. What's "best" depends on your circumstances - the man on the northpole will have different demands from a man in the desert. Go with what you're comfortable with, and read up on the new things when you have some spare time to kill. Once you discover some new area that's important to you, indulge.
RodClark wrote: How do you know the best way, and determine the best layout for a project - this function in module x, that one in module y.
I have to admit that I often don't know the best or recommended way.
Most (larger) programs are modular, and even the smaller ones tend to share a library with functions. As time passes, things get updated. The first step toward a cleaner architecturing was learning the OO-concepts, the second was learning design-patterns. What helped most overall, was reading code from articles on sites like this one.
RodClark wrote: I know this is long, I'm sorry.
Have a long answer as revenge
I are Troll
|
|
|
|
|
Thanks for the answers - appreciate them.
Those MS videos do look both interesting and useful, and the Head First book also. That sounds like the way I learn best (by doing) and I don't take the train often - when I do, I have my laptop so I can play. There's also a second edition which covers VS2010 - Here [^].
I'm nervous about going to C#, but then VB.Net is different enough to most of what I've done, that it represents a challenge too. It does seem that either language would do what I need, but most people tend to think that C# is a little more capable. It does look like I should use VS, rather than Sharp Develop. If I do use VS, then I do think that Pro is the minimum level - Just can't believe that MS dropped the standard edition (A$400, instead of A$1200!).
I like YAGNI, not heard that one before - makes sense to me. I do think that WinForms will be most of it - don't think the little utilities I written in the past or likely to create in the future need a fancy UI, just an easy, serviceable one.
Thanks again,
Rod
|
|
|
|
|
RodClark wrote: Thanks for the answers
My pleasure
RodClark wrote: I'm nervous about going to C#, but then VB.Net is different enough to most of what I've done
C# isn't more complicated than VB.NET, they're a close match. It looks a bit more cryptic perhaps, but that passes quickly.
RodClark wrote: but most people tend to think that C# is a little more capable
They match very closely, making automated translations possible. You could learn your C# and use a tool like this one[^] to take a peek at the equivalent VB.NET code.
RodClark wrote: It does look like I should use VS, rather than Sharp Develop.
The Visual Studio IDE remains my favorite IDE, but it's not a monogamous marriage. SharpDevelop is free software, and you could put it on a USB stick[^]. SharpDevelop also contains a built-in function to translate code from one language to another one.
Happy Programming
I are Troll
|
|
|
|
|
Thanks again, I've seen those code converters and even used them to get some example C# code into my VB program.
Now to make the purchase(s)...
|
|
|
|
|
Hi,everyone! I have some difficuties in my project. There are a lot of controls such as textbox and combobox in project, my question is: if I just input some values (not all) into these controls and then close the application; when I open the application next time, I want these controls could shown with values that I inputed last time.
What should I do to achieve it?Please give me some suggestions, thank you!
|
|
|
|
|
You'd have to save the available data somewhere before the app closes (a FormClosing event could help); and restore it when your app runs again (e.g. in a Form.Load event). Somewhere could be one or more files, or a database. I suggest you read a couple of articles here on CodeProject, at best you might come up with some functional search terms that match or come close to your application domain.
|
|
|
|
|
Hi,Luc! Thank you very much! I will search some articles to read
By the way,could you give me some keywords for search Thanks!
|
|
|
|
|
|
i have datagridview, i want to insert multiple rows( 5rows)
between two rows. how will i do that?
i know how to insert row between two rows but a single row.
i used: dttable.Rows.InsertAt(dRow, 0)
C# コードMicrosoft End User
2000-2008
「「「「「「「「「「「「「「「「「「「「「「「「「「「「
The best things in life are free
」」」」」」」」」」」」」」」」」」」」」」」」」」」」
|
|
|
|
|
dttable.Rows is a DataGridViewRowsCollection (the MSDN page on Rows told me so), and abviously its methods are also documented in MSDN. To insert one or more rows, look for a method with a name starting with Insert...
Please make Google your friend and MSDN your bible.
|
|
|
|
|
Do you want to add rows directly into datagridview or you want to update datatable, and so datagrid view?
Anyways, I'm pasting both, it's upto you to choose the best fit for you.
Sub insertRowsInGridView(ByRef dgvRows As DataGridViewRowCollection, ByVal rowsToInsert As DataGridViewRowCollection, ByVal insertAt As Integer)
For i As Integer = rowsToInsert.Count - 1 To 0 Step -1
dgvRows.Insert(insertAt, rowsToInsert(i))
Next
End Sub
Sub insertRowsInDataTable(ByRef dtRows As DataRowCollection, ByVal rowsToInsert As DataRowCollection, ByVal insertAt As Integer)
For i As Integer = rowsToInsert.Count - 1 To 0 Step -1
dtRows.InsertAt(rowsToInsert(i), insertAt)
Next
End Sub
|
|
|
|
|
Hello All, I have added a checkbox column to my datagrid, unfortunately, the checkboxes are not selectable. What am I missing? TIA
<pre lang="vb">Private Sub chkBoxAll_Approve(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkButton.Click
Dim ctr As New DataGridViewRow
Try
For Each ctr In dgvRequests.SelectedRows
If chkBoxColumn.Selected = True Then
Exit For
ElseIf dgvRequests.CurrentRow.Cells("requestType").Value = "OOORequest" Then
Call updateOutOfOffice(LeaveStatus.Approved)
Else
Call updateRequest(LeaveStatus.Approved)
End If
Next
Catch ex As System.Exception
MessageBox.Show(ex.Message)
End Try
End Sub</pre>
|
|
|
|
|
This isn't an answer, but edit your original post and check "Use HTML in this post". That will allow your pre tags to work.
[Update]
In response to your question, it's because of the SelectionMode property. You can only have one selection mode. And the only way to allow the column to be selected is to set the SelectionMode to ColumnHeaderSelect.
Though what you are talking about has absolutely nothing to do with checkboxes within the column.
It sounds like what you really want us to see if the current row has the checkbox selected and if not, you don't do anything with it. So, instead of doing what you are saying, you need to actually check the value of that cell, not whether or not the column is selected.
modified on Wednesday, September 15, 2010 6:24 PM
|
|
|
|
|
I am creating an application in which tcp server can connect to more than one tcp client.
following is the code- where winsockServer is the winsock control in VB6 whose index property is set to 0.
----------------
Private Sub Form_Load()
'winsockServer.Protocol = sckTCPProtocol ' choose the TCP protocol
winsockServer(0).LocalPort = 2020 ' an example port number
winsockServer(0).Listen ' tell Winsock to start listening
intSockCnt = 0
End Sub
Private Sub winsockServer_ConnectionRequest(Index As Integer, ByVal requestID As Long)
If intSockCnt > 2 Then
MsgBox "No. of hosts exceed....."
Else
intSockCnt = intSockCnt + 1
Load winsockServer(intSockCnt)
winsockServer(intSockCnt).Accept requestID
End If
End Sub
on compiling it is giving an error-
Procedure declaration does not match description of event or procedure having the same name
How can I do this ??????
thanks in adv..
|
|
|
|
|
Try this one;
Private Sub axWinsockListen_ConnectionRequest(ByVal requestID As Long) I wouldn't connect to many applications at once; VB6 wasn't built with multithreading support in mind.
I are Troll
|
|
|
|
|
I have 4 option buttons-
options1,options2,options3,options4
I want to add options1 and options2 in one group and options3 and option4 in another group.So that at a time one option button would be selected from each group.
How can I do this?
|
|
|
|
|
place the pairs of buttons within someother container such as a group or a panel.
Dave
Find Me On: Web| Facebook| Twitter| LinkedIn
CPRepWatcher now available as Packaged Chrome Extension, visit my articles for link.
|
|
|
|
|