VB question

Author
Discussion

TheExcession

Original Poster:

11,669 posts

251 months

Tuesday 11th October 2005
quotequote all
please help... I frigging hate VB -

I need an array of static final strings in VB (.NET)

Normally in C/Java I'd do

public final static string[] = new string {
"s1",
"s2",
"s3",
"s4"
};

How do I do the same in VB?

I know google is my friend - but after searching te top 20 pages I still didn't get an answer :(

many thanks
Ex

Don

28,377 posts

285 months

Tuesday 11th October 2005
quotequote all
Why not just

Dim s(10) As String

s(1) = "s1"
s(2) = "s2"

etc?

OK. So you want to protect the strings from accidental overwrites - but hey! Its VB.

Hopefully a VB.NET person will be along with exactly what you want...

Have you tried looking up the syntax in C#?

TheExcession

Original Poster:

11,669 posts

251 months

Tuesday 11th October 2005
quotequote all
Don said:
Why not just

Dim s(10) As String

s(1) = "s1"
s(2) = "s2"

etc?

OK. So you want to protect the strings from accidental overwrites - but hey! Its VB.

Hopefully a VB.NET person will be along with exactly what you want...

Have you tried looking up the syntax in C#?


Thanks Don

Well, Oh , I originally wrote the APP in C# and now I'm having to rewrite the whole bloody lot in VB so that 'other' people can maintain it.... still at least I'm getting paid to do it.

Did I mention that I hate coding VB almost as much as I hate HTML

ThatPhilBrettGuy

11,809 posts

241 months

Tuesday 11th October 2005
quotequote all
Dim ar() As String = {"a", "b", "c"}

canam-tt

862 posts

228 months

Tuesday 11th October 2005
quotequote all
ThatPhilBrettGuy said:
Dim ar() As String = {"a", "b", "c"}


I dont think that will work.

You can always dimensionalise the variable as a variant the set a fixed array

dim vArray as variant

vArray=Array("1","2","3"

ThatPhilBrettGuy

11,809 posts

241 months

Tuesday 11th October 2005
quotequote all
canam-tt said:

ThatPhilBrettGuy said:
Dim ar() As String = {"a", "b", "c"}



I dont think that will work.

You can always dimensionalise the variable as a variant the set a fixed array

dim vArray as variant

vArray=Array("1","2","3"

It works... in Visual Studio 2003 anyway.

Don

28,377 posts

285 months

Wednesday 12th October 2005
quotequote all
TheExcession said:

Well, Oh , I originally wrote the APP in C# and now I'm having to rewrite the whole bloody lot in VB so that 'other' people can maintain it.... still at least I'm getting paid to do it.

Did I mention that I hate coding VB almost as much as I hate HTML


Well - HTML I can deal with - but on the VB front... I'm with you.

There again: release after release they seem more and more determined to turn VB into the semblamce of a "proper" language. With the advent of .NET it should be capable of anything any of the other languages are - and its hard to get excited about clunky syntax as a fault.

Why on earth a client would pay you to re-write a C# app in VB is beyond me, though. I mean - how hard is C# to maintain if you know VB.NET! Libraries are all the same...how difficult is it to put a bleedin semi-colon on the ends of lines! MAD!

Still - enjoy the proceeds, mate. It's what it's all about.

pdV6

16,442 posts

262 months

Wednesday 12th October 2005
quotequote all
Don said:

Why on earth a client would pay you to re-write a C# app in VB is beyond me

That was my first thought!

TheExcession

Original Poster:

11,669 posts

251 months

Wednesday 12th October 2005
quotequote all
pdV6 said:

Don said:

Why on earth a client would pay you to re-write a C# app in VB is beyond me


That was my first thought!


Strange world init?

TheExcession

Original Poster:

11,669 posts

251 months

Wednesday 12th October 2005
quotequote all
ok, I'm still struggling with this -

Namespace I4Spots.spotmaps
Public Class spotstates
Public saSPOTSTATES As String() = {"Any", "G", "GL", "GLM", "GLMC"}
End Class
End Namespace

but saSPOTSTATES is not visible as a static member - as needed to populate a combobox with the array:

ComboBoxStates.Items.AddRange(spotstates.saSPOTSTATES)


What am I doing wrong?

Tried
Static saSPOTSTATES As String() = {"Any", "G", "GL", "GLM", "GLMC"} - tells me static is not a valid member definition?

It won't let me use Const either?

Jesus, how clumsy is this shit?

RIchardD

3,560 posts

246 months

Wednesday 12th October 2005
quotequote all
www.dnzone.com/ShowDetail.asp?NewsId=356

Shows some differences between C# and vb.net

Static seems to mean different things between the two languages

TheExcession

Original Poster:

11,669 posts

251 months

Wednesday 12th October 2005
quotequote all
RIchardD said:
www.dnzone.com/ShowDetail.asp?NewsId=356

Shows some differences between C# and vb.net

Static seems to mean different things between the two languages

Hallelujah, thanks Richard:

Public Class spotstates

Shared saSPOTSTATES As String() = {"Any", "G", "GL", "GLM", "GLMC"}

Public Shared Function getStateStrings() As String()
Return saSPOTSTATES
End Function
End Class

seems to have done it!

J_S_G

6,177 posts

251 months

Saturday 15th October 2005
quotequote all
TheExcession said:
Well, Oh , I originally wrote the APP in C# and now I'm having to rewrite the whole bloody lot in VB so that 'other' people can maintain it.... still at least I'm getting paid to do it.


If it was me, I'd either run a C# -> VB.NET source munger, or (more likely) push the finished assemblies and executables through Reflector (with the file output add-in) and get it to dump out the whole source in VB.NET for you. Albeit with munged local variable names... a few hours of refactoring (and more importantly renaming) with Resharper and you can take the rest of the month off.

Managed to disassemble the whole of the System.Web assembly and get it to compile back up again (running correctly) in under two days once (all because some internal methods should've been public). And that one was an absolute pig - lots of unmanaged nastiness.