Newbee on .Net after all there years

AccessShell

Member
Joined
Jun 14, 2016
Messages
21
Programming Experience
10+
I'm trying to convert a VB6 program to .NET. I have 3 major problems right now.

1. I keep adding a reference to MS Word, But it doesn't seem to take hold. I cannot see it in the reference list when I go back to look for it. And the details do not show in the code. Such as synFound = synonymInfo(Word: .... etc.

2. How do add and item to a listbox

3. What happened to the datatype variant. variantType does not seem to be helpful. In my vb6 program I get an unbound list from Word and insert the results into the listbox.

Thanks
 
1. That sounds like a bug in VS that we probably can't help you with specifically. In that case, a repair or a reinstall may be required. Can you describe EXACTLY what you're doing and EXACTLY what you're seeing? Are you adding the reference via the References page of the project properties? Does it appear at that point or not? If it does, does it disappear when you close the and reopen the project?

2. If you're adding items directly, you call the Add method of its Items collection. If the ListBox is bound, i.e. its DataSource is set, then you must add items to the data source in whichever way is appropriate for its type.

3. There is no Variant data type in .NET. If you want a variable that can refer to any type of object then you declare as type Object, which is the root base type in .NET. That said, if you're adding a reference for Word then you shouldn't generally need to use Object because you can use early-binding.
 
Ans to item 1.
I went to Project -> Add Reference -> COM --> scrolled down to Microsoft Word, dbl clicked and hit OK. After your response, I checked the Solution Explorer and under references I found Word. So I think I have correctly referenced MS Word.

Ans to item 2.
I am adding items directly, but I am using code identical to what I used in VB6
synFound = SynonymInfo(Word:=varBuffer, LanguageID:=wdEnglishUS).Found
For i = 1 To UBound(synList)
synList = SynonymInfo(Word:=varBuffer, LanguageID:=wdEnglishUS).SynonymList(Meaning:=1)
lstSynonyms.AddItem synList(i)
Next I
This does not seem to work in .NET

Then I code lblSyns.Caption = NUM_OF_SYNS & CStr(UBound(synList))
where synList is Dim as variant
I tried to write me.lblSyns.Text = NUM_OF_SYNS & Cstr(Ubound(synList))

OK so Over 20 yrs ago, when I learned that VB(5 or 6) can acces MS Access, MS Word, MS Excel, etc it fascinated me. So I wrote a program just to learn how to do this. I entered a word into textbox and my code would tell me if it really was a word. If not it would tell me, else it would give me all the synonyms and antonyms. Several years later I retired and kept procrastinating about VB.NET. I finally decided to load it back onto an old XP computer (no internet access) and try to rewrite it in .NET. My first build gave me over 40 errors. I have managed to fix all but 12. The lines above in red comes from the reference to Word, but they aren't working in .NET

Thanks
 
You're making far too many assumptions about VB.NET working like VB6. VB.NET syntax is based on VB6 syntax with a number of changes but, even if the syntax was identical, a VB.NET ListBox is still a completely different control to a VB6 ListBox so there's no specific reason to believe that the two should work in exactly the same way.

I would suggest that you start by quickly looking through a beginners tutorial to get the hang of the syntax, e.g. when you call a Sub or Function with arguments then you MUST wrap parentheses around those arguments. You then need to take a look at the documentation for the types you're using to see what members they have, e.g. in the case of a ListBox, it has an Items property that exposes a collection and, like all collections, it has an Add method. I don't even know what the Caption of a ListBox does in VB6 but, in VB.NET, the Text of a ListBox is the value displayed for the selected item.
 
Well, I guess when I figure out how to close it I will.

Only a moderator can actually close a thread. When you create a thread, you should be setting the prefix to Question and then, when you're question has been answered, you can edit the thread and change that prefix to Answered. People can then still post but it indicates that you don't need any more help. That said, I'm not sure whether you might need to have 10 posts to make that edit or the like.
 
Back
Top