PDA

Click to See Complete Forum and Search --> : .Net "String" equivalent


Tom Yasnowski
Sep 25th, 2002, 01:36 PM
How do you do the following in VB.NET:


Dim mystring as string * 25


I thought it may be

Dim mystring as new string("",25)

But I think I may be mistaken..

Thanks
Tom

Cander
Sep 25th, 2002, 01:43 PM
I think

Dim mystring As New String("",0,25)

will work

Tom Yasnowski
Sep 25th, 2002, 01:47 PM
Tried that,
Dim SDEPT As New String("", 0, 25)


Got:

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in HelloWorld.exe

Additional information: Index was out of range. Must be non-negative and less than the size of the collection.


Any more ideas?

:confused:

Cander
Sep 25th, 2002, 01:53 PM
<VBFixedString(25)> Public buffer As String

Tom Yasnowski
Sep 25th, 2002, 02:12 PM
Dander,

Thanks, I should have seen that in the MSDN..

Still not quite "right"

in VB 6.0:
Dim stringa As String
Dim stringb As String * 25

stringa = "TEST"
stringb = stringa

MsgBox " ' " & stringb & " ' "

The message box would show something like:

'TEST '

Showing the whole 25 positions.

Doing the same .Net I am still getting:

'TEST'

Even with the declared length.

Bummer I need to get it as such for some keyed reads..

Tom


I tried it, and when I did a message box on it:

Tom Yasnowski
Sep 25th, 2002, 02:14 PM
Dander

The "TEST" example did not display right..


In VB 6.0 I would see "TEST" with the balance of the 25 positions in the msgbox

Cander
Sep 25th, 2002, 02:20 PM
Well I dont know then..:(

Tom Yasnowski
Sep 25th, 2002, 02:23 PM
Thanks for the help anyway, I still "learned something"

Maybe someone else can find the missing clue?

Tom

Cander
Sep 25th, 2002, 02:27 PM
perhaps tell us what you are trying to do that you need fixed length strings. There maybe another way

Tom Yasnowski
Sep 25th, 2002, 02:27 PM
:o :o :o
Cander,

oops, I was calling you "Dander"! Sorry about that, what the heck was I looking at!!

Tom

Cander
Sep 25th, 2002, 02:29 PM
:p

LOL. Its ok.

Tom Yasnowski
Sep 25th, 2002, 02:37 PM
Well

For one thing I got data in Oracle tables that have trailing
spaces:


fieldx = "somevalue<SPACE><SPACE><Etc>"

so when I do a SQL command I need the key value to reflect that fact.

The other thing I was trying to do is to create a menu selection in a list box with the menu "option number" portion of the string I am adding to the listbox as being the current index value. I want the index value to be part of concatenated field of fixed length 2 padded left to line it up:


dim str_optionnumber as string * 2
dim str_text as string
dim str_combined as string
dim index as integer

index = 1
str_text = "Reports Menu"
str_optionnumber = index

str_combined = str_optionnumber.padleft(2) & "." & space(1) & str_text


listbox1.items.add(str_combined)

result:

1. Reports Menu

add the reset:

2. blah
"
"
10. blah


the menu selections would be in alignment.

If any other ideas please let me know; this IS tedious!

Cander
Sep 25th, 2002, 02:40 PM
hmm..well perhaps look into the stringbuilder class. I think you can set some fixed length there..dont know if it will accomplish hat you need though.

Cander
Sep 25th, 2002, 02:54 PM
arg stringbuilder doesnt work either. I tried it.

:(

HAROLD HOFFMAN
Sep 25th, 2002, 03:26 PM
There are no fixed lentgh strings in .net


Try PadRight.


Dim strW As String
strW = "A"
strW = StrW.PadRight(25," ")
MessageBox.Show(Len(strW))


The Length of strW should be 25.


Harold Hoffman

Cander
Sep 25th, 2002, 03:29 PM
yeah, but the VBFixedString attribute is supposed to emulate it. but it doesnt work.