|
Greetings.
First of all I am not looking for the entire code, I need your help to direct me or give some suggestions.
From VB.NET, will I be able to write a string to a word document which is already open (I can see the word doc in taskbar)? I was able to get the file name of the word doc that's in taskbar but failed to activate it or write on it.
So, from VB.NET, I need to activate or get the word doc which is up and running with a file name of "Musa.doc" and write some text to the word doc...
Any suggestion will be very helpful.
Thanks in advance.
Musa.Biralo
|
|
|
|
|
Unless there's a way in the Office tools to interact with an open doc, I fear your issue will be that the file is in use.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
I need some assistance in sorting a structure array...
I am reading words from a text file and need to store them in a array:
Structure Translate
Dim English As String
Dim French As String
Dim German As String
End Structure
Dim TWord(16) As Translate
I then read the text file.. which basically goes from English, to French, to German.
So the first line in the text file is the English word YES, the second line is OUI (French) which means YES and the third is JA (German) which means YES in English as well. So what I have to do it put these ina structured array.
fs = New FileStream("TranslateC.txt", FileMode.Open, FileAccess.Read)
sr = New StreamReader(fs)
count = 0
Do While sr.Peek() >= 0
TWord(count).English = sr.ReadLine()
TWord(count).French = sr.ReadLine()
TWord(count).German = sr.ReadLine()
count = count + 1
Loop
sr.Close()
Now that I have that.. they want me to sort the english words?!? This is where I get completely lost. I found code earlier that helped me and it sorted the english words from A to Z but none of the others. So the translated words did not match up.
*** Could anyone point me to the correct location of a good tutorial on this? ***
I did the project first hand (That works!) but used jagged arrays instead:
Peronsally I like this way better but according to the project it is not HOW they wanted it done:
Imports System.IO
Public Class Form1
Dim TranslateWords(15)() As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim fs As FileStream
Dim sr As StreamReader
Dim count As Integer
fs = New FileStream("TranslateC.txt", FileMode.Open, FileAccess.Read)
sr = New StreamReader(fs)
count = 0
Do While sr.Peek() >= 0
Dim read = sr.ReadLine()
If read <> Nothing Then
Dim words As String() = read.Split(",")
TranslateWords(count) = New String() {words(0), words(1), words(2)}
End If
count = count + 1
Loop
sr.Close()
End Sub
Private Sub SortArray()
End Sub
Private Sub btnTranslate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTranslate.Click
Dim sentence As String = txtEnglish.Text
Dim splitSentence As String() = sentence.Split(New Char() {" "c})
Dim count As Integer
txtTranslated.Text = ""
If radioFrench.Checked Then
For Each word As String In splitSentence
Dim translated As Boolean
translated = False
For count = 0 To 15
If TranslateWords(count)(0).ToLower() = word.ToLower() Then
txtTranslated.Text += TranslateWords(count)(1) + " "
translated = True
End If
Next
If translated = False Then
txtTranslated.Text += word + " "
End If
Next
ElseIf radioGerman.Checked Then
For Each word As String In splitSentence
Dim translated As Boolean
translated = False
For count = 0 To 15
If TranslateWords(count)(0).ToLower() = word.ToLower() Then
txtTranslated.Text += TranslateWords(count)(2) + " "
translated = True
End If
Next
If translated = False Then
txtTranslated.Text += word + " "
End If
Next
Else
MsgBox("You must select French or German before trying to translate", MsgBoxStyle.Information)
End If
End Sub
End Class
|
|
|
|
|
Hi,
I don't know what happened here, you started explaining a nice structure (Translate) holding three strings, one for each language; later on I don't see that structure used anywhere, instead a lot of code I did not understand at first glance, anyway too much to get the required things done.
Collection classes have Sort methods: Array has a static Sort, most Lists and Dictionaries have an instance Sort() method; they all take an optional IComparer<Translate>, and that is what you need: a Compare method that understands your structure, takes the right language string, and compares two of them.
For three languages, that would mean three comparers, each of them holding some 5 lines of code (which I am not venturing to write down here as my Basic isn't very fluent, and some has to be left for you too).
BTW: I don't like your structure''s name, a structure holds data, so it is (almost) an object, don't call it a verb then. Maybe MultilingualTerm would fit.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I see what you are saying. The top of my question was basically what I was trying to do. Towards the bottom of my post is what I have written that actually works, but wasn't using a Array Structure and sorting it like the project requested. I'll have ot look up more on the IComparer.
|
|
|
|
|
I think you should look to use the overload of Array.Sort that takes an IComparer(Of T)
The comparer would look something like this (WARNING: code typed directly into the reply)
Friend Class TranslationSorter
Implements IComparer(Of Translate)
Public Function Compare(ByVal x as Translate, ByVal y as Translate) as Integer
'you will need null checks here to decide how to sort in nulls
'this will use the default sort order for strings
Return x.English.CompareTo(y.English)
End Function
End Class
Array.Sort(yourArray, New TranslationSorter)
With this approach, you could add a language property to the TranslationSorter class to make it do other languages.
On an unrelated note, StreamReader has an EndOfStream property instead of needing to do .Peek() >= 0
|
|
|
|
|
I actually found what my professor was wanting. I wasn't aware that she posted the code. She used a bubble sort for the structure array:
Private Sub bubbleSort(ByRef arrayName() As Words)
Dim temp As Words
Dim numItems As Integer = arrayName.GetUpperBound(0) ' number of items in array
For passNum = 1 To numItems - 1 ' Number of passes is 1 less than number of items in array
For i As Integer = 1 To (numItems - passNum) ' Each pass needs 1 less comparison
If (arrayName(i - 1).English > arrayName(i).English) Then
temp = arrayName(i - 1)
arrayName(i - 1) = arrayName(i)
arrayName(i) = temp
End If
Next
Next
End Sub
|
|
|
|
|
FYI, you do not need to pass the array ByRef to the function. Passing the array ByVal will still allow you to sort the array and have the effects noticed in the original function. Passing an array ByRef would only be useful if you were going to replace the entire array with another array. For example, if you were somehow trimming the array in a function, you would need to pass ByRef.
I'm assuming that the bubble sort was part of the assignment, but otherwise would still recommend using Array.Sort
|
|
|
|
|
Interesting... well the bubble sort is not part of the assignment. She just gave us that. It just says to "Sort" it. To be honest.. I'll have to read more on the IComparer because I don't fully understand it.
|
|
|
|
|
Hi,
a class implementing IComparer basically says Ï have a method Compare() that knows what the relative order would be of two objects of a given type; it will return zero when order is irrelevant (i.e. both objects are equal), a negative value if object1 should preceed object2, and a non-zero positive one if object1 should follow objects2."
So basically an integer Compare() method could just return the difference of both numbers; and a simple string compare method is obviously available in the string class.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hi
I'm writing a program that has a ListBox control. If the user drags a file and drops it on the listbox, the filename should be added to the list. I'm using the following code:
Private Sub ListBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub ListBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragDrop
Stop 'This is called
Dim s$ = e.Data.GetData(DataFormats.FileDrop, True) 'Why does this exit the sub?
Stop 'This not
'...
End Sub
As you can see, I put 2 stop statements in the DragDrop event. The first of them is called and stops debugging, but then e.data.getdata somehow exits the sub, and so nothing happens.
Is it even possible that a procedure exits the sub it is called from (without exiting the thread)???
I'm very confused ; I would be grateful to anyone who could give me an explanation for this.
|
|
|
|
|
What on earth is a stop statement - never used one never even heard of one.
Why not just use a breakpoint and inspect the content of e.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I'm glad you made that reply. I was going to say exactly the same, but as I do not do much VB it might have passed me by and I didn't want to appear dumb.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Yeah, just got into the office and about to fire up VB/MSDN to find out what. I used VB since the early 90's (I now use C#) and have never used a stop statement.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi,
The FileDrop data format is a StringCollection so there should be a runtime error when you try to assign into the string s$.
The question is why do you not see the exception?
Do you have ON ERROR GOTO 0 anywhere in your code?
Alan.
|
|
|
|
|
Hi,
If there was any On Error or Try statement in my code I would understand, but there isn't!
Yes, with a string array it works . Tnx
|
|
|
|
|
Hello,
Iam working on vb.net2008 and using Access as backend.
1) I want my database should save on default location unlike this:
Dim connectionstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Contacts3\mycontacts.mdb;Persist Security Info=False"
Since i'm deploying my project on another computer itz showing me an error of database connection.Then again i've to make one folder of Contacts3 in C drive and then itz connecting the database.please let me know how can i deploy my database as default.
Thanks
Mirza
modified on Sunday, July 5, 2009 6:17 AM
|
|
|
|
|
Add a custom folder in your setup project and place your MDB file in it. Set the target loaction of the folder as you need.
|
|
|
|
|
Thanks danish for your reply.Danish i want my database should be in my project folder and dont want to place my access db manually to the specified path.I want something like this:
Dim connectionstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\mycontacts.mdb;Persist Security Info=False"
Here i'm not putting the location i.e, C:\Contacts3.This'll store my records wherver mycontacts.mdb file present.I think i'm missing somthing before this ?????\mycontacts.mdb and in project->windowsproperties->setting->value i should put & or + before \mycontacts.mdb
Thanks
|
|
|
|
|
Path.GetFullPath will give you that I guess. Is that the path you are looking for?
|
|
|
|
|
best apply your path in dynamically.
Yours,
KaNNaN
-----------------------------------------------------------------
"Success is When Ur Signature Becomes An Autograph"
Mail To : foreverkans@gmail.com
|
|
|
|
|
Yes Mr. Kannan exactly i want my path dynamically but dont know where i am goin wrong..
plz suggest me.
Dim connectionstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Contacts3\mycontacts.mdb;Persist Security Info=False"
Thanks
|
|
|
|
|
Dear Danish,
Actually i just need to know what should i write before \mycontacts.mdb instead of C:\(database drive path) because if i mentioned the path then i've to put the same folder(in order to get the same path)in other system where i'll deploy my project(client).
i think i should write & before my database like &\mycontacts.mdb but still i'm not sure.
Once again Thanks
|
|
|
|
|
Hi all...
I want to know that how can I add different effects like - sepia,mono,negative etc. in an Image through programming. I am using VS with vb.net.
Also tell me what is the procedure to create a cartoon image from an existing image.
Thanks.
Gagan
|
|
|
|
|
Is ImageMagick something for you? (just google it) It has huge options to do things with images programmaticly...
Rozis
|
|
|
|