Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have the following code in VB6. How can I re-write this in Visual Studios 2012?

As it is written below, I get the following error message:

"Arrays declared as structure members cannot be declared with an initial size. "
I've seen possible alternatives to how this should be written but I cant get anything to work.

VB
Structure selectStruct
Dim name As String 'name of menu
Dim options(0 To 300) As String 'the options in the select/combo
Dim selected As Integer 'the number of the option which is selected
Dim size As Integer 'number of options in menu
Dim node As IHTMLDOMNode ' the node in the DOM
End Structure

thanks
Posted
Updated 14-May-13 11:37am
v2
Comments
Richard C Bishop 14-May-13 17:20pm    
VS2012 is not a language, do you mean VB.Net?
Amy Adams 14-May-13 17:39pm    
Yes. Thanks.
Maciej Los 14-May-13 17:41pm    
What to "re-write"? You need to write it from the beginning to the end. There is no simply method to "re-write".
There is not enough information to answer to your question at all.

Please, read my comment. You did not provide enough information to post exact answer.

VB6 vs. VB.NET[^] - there are similar languages both not the same.
Array class (VB.NET)[^]

I would suggest you to use custom class. Please, follow this link: Using Classes and Structures in Visual Basic .NET[^]. I'll share an example, but i don't know how do you use above array...
 
Share this answer
 
v2
Comments
Amy Adams 14-May-13 18:01pm    
Thank you. I will check out the link you provided.
Maciej Los 14-May-13 18:08pm    
You're welcome ;)
Sergey Alexandrovich Kryukov 14-May-13 18:52pm    
First link does not show anything useful, it must be you mistake, others are good, a 5.
—SA
Maciej Los 15-May-13 1:55am    
Link corrected.
Tahnk you, Sergey ;)
 
Share this answer
 
Comments
Maciej Los 14-May-13 18:04pm    
Above question is one of them: "How to re-write?" and i expect from you, Sergey, more comprehensive answer. Your answer points OP to the solution, but i think that problem is much, much deeper... Sorry, but it's my opinion, my Guru. See my answer.

At that time... +4!
Sergey Alexandrovich Kryukov 14-May-13 18:16pm    
I agree, it was a quick answer. I think Solution 2 is the correct more detailed solution. Do you think there is something deeper? If so, could you explain?
Thank you, Maciej.
Maciej Los 14-May-13 18:40pm    
Have you read my answer?
"Something deeper" is in that that OP wants to "re-write" code from VB6 to VB.NET. As you know, there is no simply way to achieve that because of the differences between both programming languages. Of course, we can help Her to find solution in this case, but it does not solve problem at all.
I hope my explanation is clear enough now.
Sergey Alexandrovich Kryukov 14-May-13 18:54pm    
I saw it now. I don't see anything "much deeper" though, but it depends on individual perception of "depth"; to me, this is just one more VB.NET weirdness... Up-voted anyway.
—SA
Maciej Los 15-May-13 1:52am    
Maybe i'm wrong. We will see...
Thank you, Sergey ;)
Does this work:
VB
Structure selectStruct
  Dim options() As String
  Sub New(ByVal size As Integer)
    ReDim options(size - 1)
  End Sub
End Structure


Note that I used "size - 1" because I'm guessing the original code should say "options(0 To 299)".
 
Share this answer
 
My VB is rusty, but I think you want:
VB
Dim options(300) As String

instead of the line you have declaring it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900