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
Printable View
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
I think
Dim mystring As New String("",0,25)
will work
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:
<VBFixedString(25)> Public buffer As String
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:
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
Well I dont know then..:(
Thanks for the help anyway, I still "learned something"
Maybe someone else can find the missing clue?
Tom
perhaps tell us what you are trying to do that you need fixed length strings. There maybe another way
:o :o :o
Cander,
oops, I was calling you "Dander"! Sorry about that, what the heck was I looking at!!
Tom
:p
LOL. Its ok.
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!
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.
arg stringbuilder doesnt work either. I tried it.
:(
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
yeah, but the VBFixedString attribute is supposed to emulate it. but it doesnt work.